Solved

parse xml document with multiple namespaces

Posted on 2009-05-06
4
2,030 Views
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);
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
Comment
Question by:ogdennews
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 21

Expert Comment

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

0
 

Author Comment

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

This also returns null
0
 
LVL 21

Accepted Solution

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

Author Comment

by:ogdennews
ID: 24325745
Damn, that fixed it.

I've been looking at that for 2 days.
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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 …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

730 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