Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

parse xml document with multiple namespaces

Posted on 2009-05-06
4
Medium Priority
?
2,049 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 2000 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

604 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