Problem when trying Update nodes of the following SOAP XML C # file

0

This is the XML SOAP to be modified, the nodes that you want to modify are "Code", "TrNumber" are inside the Element "SECInformation"

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cis="http://www.i2.com/cis">
    <soapenv:Header/>
    <soapenv:Body>
        <cis:processLoad>
            <!--Optional:-->
            <cis:ApiHeader>
                <!--Optional:-->
                <cis:OperationName>processLoadup</cis:OperationName>
            </cis:ApiHeader>
            <!--Zero or more repetitions:-->
            <cis:LoadUpdate>
                <!--Optional:-->
                <cis:Carrier>1605</cis:Carrier>
                <!--Optional:-->
                <cis:LoadID>Slw12</cis:LoadID>
                <cis:SECInformation>
                    <!--Optional:-->
                    <cis:Code>TRNT</cis:Code>
                    <cis:TrNumber>DZF660</cis:TrNumber>
                </cis:SECInformation>
            </cis:LoadUpdate>
        </cis:processLoad>
    </soapenv:Body>
</soapenv:Envelope>

Thus I charge the File xml, in C #:

XmlDocument doc = new XmlDocument();
doc.Load("TrNumber.xml");

var nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");

XmlNode General;
XmlNode root = doc.DocumentElement;
General = root.SelectSingleNode("/soapenv:Envelope/soapenv:Header/soapenv:Body/processLoad/ApiHeader/LoadUpdate", nsmgr);
General["Carrier"].InnerXml = "1234";

XmlNode secInfo;
XmlNode sec = doc.DocumentElement;
secInfo = sec.SelectSingleNode("/soapenv:Envelope/soapenv:Header/soapenv:Body/processLoad/ApiHeader/LoadUpdate/SECInformation");
secInfo["Code"].InnerText = "DE12";
secInfo["TrNumber"].InnerText = "FLG1";

doc.Save("TrNumber.xml");

When I do the "sec.SelectSingleNode" I set the route to the element where I want to access its node to be able to update the current values but when going to "secInfo [" Code "]. InnerText" returns an Object null reference because it is not accessing the element that I want in this case is "cis: LoadUpdate" of the xml and thus be able to update the values of its nodes.

I hope you explained to me

    
asked by Davideveloper 16.10.2018 в 23:05
source

0 answers