parse xml document with multiple namespaces

Posted on 2009-05-06
Medium Priority
Last Modified: 2013-12-17
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);
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

Question by:ogdennews
  • 2
  • 2
LVL 21

Expert Comment

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


Author Comment

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

This also returns null
LVL 21

Accepted Solution

MogalManic earned 2000 total points
ID: 24325476
You misspelled the namespace.  It should be
  nsmgr.AddNamespace("apcm", "http://ap.org/schemas/03/2005/apcm");

Author Comment

ID: 24325745
Damn, that fixed it.

I've been looking at that for 2 days.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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

Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
An ASP.NET Web Form User Control is not newly introduced in ASP.NET. In fact, it was an old technology yet still playing a role to generate web content, especially when we want to use it to have a better and easy way to control part of the web conte…
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

623 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