Just getting started with XQuery using BaseX.
The XML structure that I did not create and have no control over, looks like this:
2002test.xml:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:runSearchResponse xmlns:ns2="http://externalapi.business.footprints.numarasoftware.com/">
<return>
<_items>
<_containerDefinitionId>1234</_containerDefinitionId>
<_containerDefinitionName>Service Desk</_containerDefinitionName>
<_itemDefinitionId>2244</_itemDefinitionId>
<_itemDefinitionName>Service Request</_itemDefinitionName>
<_itemId>9989</_itemId>
<_itemFields>
<itemFields>
<fieldName>Icon Name</fieldName>
<fieldValue>
<value>default_ticket.png</value>
</fieldValue>
</itemFields>
<itemFields>
<fieldName>emailCustomerUpdate</fieldName>
<fieldValue>
<value>false</value>
</fieldValue>
</itemFields>
<itemFields>
<fieldName>bestContactNumber_Customer</fieldName>
<fieldValue>
<value/>
</fieldValue>
</itemFields>
</_itemFields>
</_items>
</return>
</ns2:runSearchResponse>
</soap:Body>
</soap:Envelope>
Doing a simple:
for $x in doc("2002test.xml")
return $x
returns my entire document as expected.
Any attempt to drill into it is not working for me however.
I've tried:
for $x in doc("2002test.xml")/soap:Envelope/soap:Body/ns2:runSearchResponse/return
return $x/_items/itemFields/fieldName
But the long path throws a "No namespace declared for 'soap:Envelope'."
So I tried declaring the path like this:
declare variable $m := "/soap:Envelope/soap:Body/ns2:runSearchResponse/return";
for $x in doc("2002test.xml")//$m
return $x
Which got me:
/soap:Envelope/soap:Body/ns2:runSearchResponse/return
/soap:Envelope/soap:Body/ns2:runSearchResponse/return
/soap:Envelope/soap:Body/ns2:runSearchResponse/return
...
I tried:
for $x in doc("2002test.xml")/*[local-name()='soap:Envelope'][local-name()='soap:Body'][local-name()='ns2:runSearchResponse'][local-name()='return']
return $x
Which did nothing.
Very simply I'd like to be able to do something like this:
for $x in doc("2002test.xml")
where $x/return/_items/_itemFields/itemFields/fieldValue/value="default_ticket.png"
return $x/return/_items/_itemFields/itemFields/fieldName/text()
resulting in:
Icon Name
Any advice?
question from:
https://stackoverflow.com/questions/65602422/querying-xml-data-with-a-long-multi-special-character-path-name 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…