Link to home
Start Free TrialLog in
Avatar of Bran-Damage
Bran-DamageFlag for United States of America

asked on

XML parsing error 'x://shipto/name' has an invalid qualified name.

I am trying to parse an XML and I am stuck.  The XML has a namespace which is making this more difficult.  

I have attached the code, it is blowing up on the line:

            objShipTo.strSTContact = root.SelectSingleNode("x://shipto/name", nsmgr).InnerText.ToString();

I have attached the XML as well.

Thanks for your help.

private bool FillShipTo(XmlDocument xmlDoc)
    {
        try
        {
            objShipTo = new InterfaceShipTo();

            XmlElement root = xmlDoc.DocumentElement;
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
            nsmgr.AddNamespace("x", root.NamespaceURI); // x is our temp alias

            objShipTo.strSTContact = root.SelectSingleNode("x://shipto/name", nsmgr).InnerText.ToString();

            return true;
        }
        catch (Exception ex)
        {
            return false;
        }
    }

Open in new window

Response.xml
Avatar of Friman001
Friman001
Flag of United States of America image

"x://shipto/name" should be "x:/shipto/name".  If that gives you an, you can try it the other way, "x://shipto//name", but normally you specify a website the first way I wrote, but drives in C# may be different and you have to use // to actually display a /.
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I guess I was way off then!
Avatar of Bran-Damage

ASKER

Thanks for the help, i tried the x: in front of each node, and I got this error

'x://shipto/x:name' has an invalid qualified name.

That's not the XPath I specified...
oh... haha, wupps.  Got the x: messed up, trying it now.
Perfect, thanks.
NP. Glad to help  = )