我有xml有效负载。
<ClientList>
<Client>
............................
....n number of elements....
............................
<EmployerList>
<Employer>
............................
....n number of elements....
............................
<LocationList>
<Location></Location>
<Location></Location>
<Location></Location>
<Employer>
............................
....n number of elements....
............................
<LocationList>
<Location></Location>
<Location></Location>
<Location></Location>
<Client>
............................
....n number of elements....
............................
<EmployerList>
<Employer>
............................
....n number of elements....
............................
<LocationList>
<Location></Location>
<Location></Location>
<Location></Location>
<Employer>
............................
....n number of elements....
............................
<LocationList>
<Location></Location>
<Location></Location>
<Location></Location>
位置有locationId元素。基于我手头的输入locationId,我只需要过滤位置。如何在不迭代/重新映射数千个其他元素的情况下完全删除不匹配的位置元素(提及为&#34; n个元素和#34;)
答案 0 :(得分:0)
如果xml不是很清楚,可能的解决方案是:
1.你可以使用xpath过滤器。例如:。
参考文献:https://blogs.mulesoft.com/dev/anypoint-platform-dev/using-xpath-expressions-on-an-xml-document-with-namespaces/
你也可以使用jaxb。将xml转换为Java Bean并根据所需位置进行过滤,并使用过滤器详细信息创建新的xml文件(仅在需要时)。