Solved

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

Posted on 2011-09-10
8
1,023 Views
Last Modified: 2012-05-12
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
0
Comment
Question by:Bran-Damage
  • 3
  • 3
  • 2
8 Comments
 
LVL 4

Expert Comment

by:Friman001
ID: 36516629
"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 /.
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 36516641
Unless Mono is screwed up, it actually needs to be "//x:shipto/x:name".
0
 
LVL 4

Expert Comment

by:Friman001
ID: 36516680
I guess I was way off then!
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

Author Comment

by:Bran-Damage
ID: 36516820
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.

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36516875
That's not the XPath I specified...
0
 

Author Comment

by:Bran-Damage
ID: 36516885
oh... haha, wupps.  Got the x: messed up, trying it now.
0
 

Author Closing Comment

by:Bran-Damage
ID: 36516892
Perfect, thanks.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36516893
NP. Glad to help  = )
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question