Querying an XML node which has only localname and xmlns declared to it.

Hi,
I have a requirement to query an xml which of the below format

<root xmlns:xsi=<> xmlns:xsd=<> xmlns:

value1
value2

the requirement is to fetch the value of key1. The way I followed is, I got the rootLocalName of xml and prepared an XPath to query the node like this
/%rootLocalName%/parent1/key1

but, the query gave me null results.
Can some one help me on this?

BestRegards,
SasikalaVinay

Hi Sasikala,

do you have the DocType representation available in your IS (i.e. created from a XSD)?

Then you can just right click on the field in the pipelina and select “copy”.
This can be pasted into the query field.

Regards,
Holger

Hi Holger,

Firstly thanks for your reply!

I didn’t have DocType for this. The original requirement was with prefix and now, user come up with additional requirement that the service should serve the xmls without rootPrefix.

I have seen many posts saying that it is difficult to query a node with defaultNamespace. But, I have to get it done without disturbing the input xml root tag.

Please suggest me way to do it.

Regards,
SasikalaVinay

[color=blue]Hi Sasikala,

You mean to say that Root Tag of the XML received can change during run time?

Whether this path parent1/key1 is unchanged?[/color]

-Ambrish-

Hi Sasikala,

can you provide a screenshot of your flow implementation?

You should try to get the XSD for this XML message from the partner as this will ease development a lot.

Regards,
Holger

Hi Holger,

sorry, I can’t provide screenshot of the XML.

Hi Ambrish,

No, my requirement is to write an xPath to query an XML Node which has default namespace.

The rootLocalName (root tag) and the child tags will remain same for a given input.

BestRegards,
SasikalaVinay.

Hi Sasikala,

then your xpath should be “/root/parent1/key1”.

Regards,
Holger

Hi Holger,

That Xpath is not working, it is fetching me null values. I have tried this option as well :frowning:

Regards,
SasikalaVinay

Hi Sasikala,

I did some research meanwhile.

Hopefully your XML is welformed (only one node with name root after the <?xml>-Tag).

Here are some options to try:

  • /*/parent1/key1
  • parent1/key1

Did you try to specify the namespace in the nsDecls-Parameter?

BTW:
Which QueryLanguage are you using?
WQL or XQL?
Usually the XQL should be preferred over WQL.

If this does not help, please provide a screenshot of pub.xml:queryXMLNode step.

Regards,
Holger

XQL is preferred way and yes please upload the screenshot clearly the settings you are inputting to queryXMLNode service.

Attach the test XML also if possible.

HTH,
RMG

Hi all,

Thanks for your suggestion and reply.

I have got the query executed using the below format to fetch the values from XML.

//:parent1/:key1

It works for both scenarios, with and without prefix.

BestRegards,
SasikalaVinay.

Glad to hear you were able to resolve it with the syntax above :smiley:

Cheers!
RMG

Hi Sasikala,

I agree with RMG.

Luckily you have figured out the correct query.

As there was never a sample xml structure with namespaceprefix present inside the tags we might have been looking in the wrong direction sometimes.

As there different types of presentations of xml messages regarding the presence or absence of namespace prefixes this can be confusing when not knowing all occuring variants.

  1. All elements have prefixes
  2. No element does have a prefix
  3. Only the root element does have a prefix
    This depends on how xsd are composed/cascaded with namespaces defined and if they define elementFormQualified as true or false.

In my project I have observed all 3 types of messages for different interfaces causing more or less trouble when importing them into the IS as well as constructing test and reference data for testing them on either 7.1 or 9.5.

Regards,
Holger

Thank you Holger and RMG :slight_smile: