1

I am trying to return the value of certain attributes in an XML file and for some reason I cannot do it.

I load the XML document and select the node from the path:

XmlDocument doc = new XmlDocument();
doc.Load(@"XMLDocument.xml");
XmlNode dataAttribute = doc.SelectSingleNode(@"/ProcessCustomerPartyMaster/ApplicationArea/Sender/UserArea/Property/NameValue[@name='websiteurl']");

The XML document:

<?xml version="1.0" encoding="utf-16"?>
<ProcessCustomerPartyMaster xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" languageCode="en-US" systemEnvironmentCode="" versionID="0" releaseID="2"
    xmlns="http://schema.infor.com/InforOAGIS/2">
    <ApplicationArea>
        <Sender>
            <UserArea>
                <Property>
                    <NameValue type="StringType" name="cr12d_legacy" />
                </Property>
                <Property>
                    <NameValue type="StringType" name="SALN05" />
                </Property>                
                <Property>
                    <NameValue type="StringType" name="websiteurl">https://www.davis.com</NameValue>
                </Property>
            </UserArea>
        </Sender>
    </ApplicationArea>
</ProcessCustomerPartyMaster>

As an example, what would I need to do to pull the value from the NameValue where name='websiteurl'?

Edit I have already tried bypassing the namespaces by using

        XmlNode dataAttribute = doc.SelectSingleNode(@"/*[local-name()='NameValue']");
  • I see people constantly try to circumvent namespaces. Stop doing that; namespaces are part of your schema and trying to circumvent them makes your XML processing slow and incorrect. Both XmlDocument and XDocument can use namespaces. – Dour High Arch Jan 23 '22 at 20:16
  • I wouldnt mind using the namespace, it was flagged as a duplicate and this was one of the solutions. I think we should get as exact to a path as we possibly can. I am just not entirely sure how to include it and use the path to get to where i need to go. – Samuel Dague Jan 24 '22 at 21:04

0 Answers0