• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2059
  • Last Modified:

parse xml document with multiple namespaces

I am a rookie at XML and need help. Using C#, Visual studio 2008.
A sample xml document is attached.
I am attempting to parse an XML document with multiple name spaces.
In the attached code snippet I attempt to use : SelectSingleNode() to get the value of  'sequenceNumber' from the 'apcm:Property' node.

wnode = feedDoc.SelectSingleNode("//apcm:Property[@Name='sequenceNumber']", nsmgr);

This returns null.

The next call to 'SelectSingleNode' to get the 'ap:updated' value is successful.
There are several other nodes with the  'apcm:' prefix and I can't seem to parse any of them.
Can anyone help!
feedDoc.Save("C:\\AP_WebFeed\\myAPItemList.xml"); // save original 
 
XmlNamespaceManager nsmgr = new XmlNamespaceManager(feedDoc.NameTable);
nsmgr.AddNamespace("ap","http://www.w3.org/2005/Atom");
nsmgr.AddNamespace("apcm","http://ap.org/scemas/03/2005/apcm");
nsmgr.AddNamespace("apnm","http://ap.org/scemas/03/2005/apnm");
 
XmlNode wnode = null;
 
wnode = feedDoc.SelectSingleNode("//apcm:Property[@Name='sequenceNumber']", nsmgr); // returns null
 
if (wnode != null)
    Globals.m_SequenceNumber = wnode.Attributes["Id"].Value;
 
wnode = feedDoc.SelectSingleNode("//ap:updated", nsmgr); // success
 
if (wnode != null)
    Globals.m_Updated = wnode.InnerText;

Open in new window

ap-xml-sample.txt
0
ogdennews
Asked:
ogdennews
  • 2
  • 2
1 Solution
 
MogalManicCommented:
try wnode = feedDoc.SelectSingleNode("//apcm:Property[@apcm:Name='sequenceNumber']", nsmgr);

0
 
ogdennewsAuthor Commented:
I ttied:
wnode = feedDoc.SelectSingleNode("//apcm:Property[@apcm:Name='sequenceNumber']", nsmgr);

This also returns null
0
 
MogalManicCommented:
You misspelled the namespace.  It should be
  nsmgr.AddNamespace("apcm", "http://ap.org/schemas/03/2005/apcm");
0
 
ogdennewsAuthor Commented:
Damn, that fixed it.

I've been looking at that for 2 days.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now