0

I have an XML and I wanna get a specific nested element using XPath but it does not work. Maybe that is why tags include xmlns attributes. Any suggestions?

<DataPDU xmlns="urn:cma:stp:xsd:stp.1.0">
<Body>
    <AppHdr xmlns="urn:iso:std:iso:20022:tech:xsd:head.001.001.01">
        <test1>
            <test2>
                <test3>
                    <test4>text</test4>
                </test3>
            </test2>
        </test1>
        <test5>
            <test6>
                <test7>
                    <test8>dummy text</test8>
                </test7>
            </test6>
        </test5>
        <test9>test</test9>
        <test10>p1212121</test10>
        <test11>147</test11>
        <test12>lorem</test12>
    </AppHdr>
    <Document xmlns="urn:iso:std:iso:20022:tech:xsd:pacs.008.001.08">
        <test13>
                <test14>
                        <test15>asap</test15>
                </test14>
        </test13>
    </Document>
</Body>

  • As well as the "canonical" answer for which this is marked as a duplicate, search for "XSLT default namespace" for many other answers to this question, – Michael Kay May 21 '20 at 07:44

1 Answers1

-1

Yes you'll have to define the namespace. Have a look at this -

How to get XML element with namespace

Or you can pass the xml as string and use regex to remove those attributes -

Regex.Replace(xmlString, @"(\sxmlns="".+"")", "")

Depending on your use case, you can use either.

Bandook
  • 658
  • 6
  • 21