Parsing XML Element - c#

i am trying to parse an xml element (DItem >> Title)
below is my code but somehow i am not getting hold of it.... any help?
XDocument xdoc1 = XDocument.Load(url);
XNamespace ns = "http://sitename/items.xsd";
string topic = xdoc1.Descendants(ns + "DItem")
.Select(x => (string)x.Attribute("Title"))
.FirstOrDefault();
<?xml version='1.0'?>
<root xmlns="http://www.w3.org/2005/Atom">
<title type="text">title</title>
<entry>
<id>da7d3189-fd89-4d3f-901c-30eab7a3baa5</id>
<title type="text">Swimming Pools</title>
<summary type="text"></summary>
<updated>2011-08-19T19:02:21Z</updated>
<link rel="alternate" href="link" />
<link href="link" />
<content type="application/xml">
<Items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.namespace.xsd">
<CatalogSource Acronym="ABC" OrganizationName="organization name" />
<Item Id="28466" CatalogUrl="url">
<DItem xmlns:content="http://namespace.xsd" TargetUrl="http://index.html" Title="my title">
<content:Source Acronym="ABC" OrganizationName="ABC" />
</DItem>
</Item>
</Items>
</content>
</entry>
</root>

Using the namespace "http://www.namespace.xsd" should (and does) work:
XNamespace ns = "http://www.namespace.xsd";
string topic = xdoc1.Descendants(ns + "DItem")
.Select(x => (string)x.Attribute("Title"))
.FirstOrDefault();
Since DItem is not qualified with a namespace itself, it will use the default namespace specified asxmlns="http://www.namespace.xsd" on its parent element.

Related

How to write xpath for xml with two namespaces?

I am trying to get the values of the title and link with the attribute equals to alternate. But with the namespaces, I find it a bit challenging to get the values.
I have added my namespaces as follows but my result is comming back with Enumeration yeilds no result:
nameSpaceManager_ = new XmlNamespaceManager(new NameTable());
nameSpaceManager_.AddNamespace("viz", "http://www.vizrt.com/atom");
nameSpaceManager_.AddNamespace("atom", "http://www.w3.org/2005/Atom");
I am using XDocument with a mixture of linq and xpath to query my data.
I use the XPath as follows:
var showName = showNode.XPathEvaluate("/atom:entry/atom:title/text()", nameSpaceManager_);
UPDATE
XML:
<?xml version="1.0" encoding="UTF-8"?>
<feed xml:base="http://127.0.0.1:8580/directory/shows/" xmlns="http://www.w3.org/2005/Atom">
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:viz="http://www.vizrt.com/atom">
<title>My Show</title>
<author>
<name>Media Sequencer</name>
</author>
<id>tag:user,2017-02-03:0:/directory/shows/My%20Show.show</id>
<updated>2017-02-03T11:41:05Z</updated>
<summary>Show My Show</summary>
<category scheme="http://www.vizrt.com/types" term="directory" />
<category scheme="http://www.vizrt.com/types" term="show" />
<category scheme="http://www.vizrt.com/types" term="trio_4_layer_collection" label="Trio 4 Layer Collection" />
<link type="application/atom+xml;type=feed" rel="alternate" href="http://127.0.0.1:8580/show/%7B4575C71F-FC79-4813-A92F-D6297D5C517C%7D/" />
<link type="application/atom+xml;type=entry" rel="self" href="http://127.0.0.1:8580/directory/shows/My%20Show.show" />
<viz:empty>false</viz:empty>
</entry>
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:viz="http://www.vizrt.com/atom">
<title>My Show 2</title>
<author>
<name>Media Sequencer</name>
</author>
<id>tag:user,2017-02-03:0:/directory/shows/My%20Show.show</id>
<updated>2017-02-03T11:41:05Z</updated>
<summary>Show My Show</summary>
<category scheme="http://www.vizrt.com/types" term="directory" />
<category scheme="http://www.vizrt.com/types" term="show" />
<category scheme="http://www.vizrt.com/types" term="trio_4_layer_collection" label="Trio 4 Layer Collection" />
<link type="application/atom+xml;type=feed" rel="alternate" href="http://127.0.0.1:8580/show/%7B4575C71F-FC79-4813-A92F-D6297D5C517C%7D/" />
<link type="application/atom+xml;type=entry" rel="self" href="http://127.0.0.1:8580/directory/shows/My%20Show.show" />
<viz:empty>false</viz:empty>
</entry>
</feed>
Updated Query:
var exEl = xmlDoc.XPathSelectElements("//atom:feed/atom:entry[atom:category/#term='show']", nameSpaceManager_);
foreach (var showNode in exEl.Cast<XElement>())
{
var showName = showNode.XPathSelectElement("/atom:entry/atom:title", nameSpaceManager_).Value;
var linkTypes = showNode.XPathSelectElements("/atom:entry/atom:link[#rel='alternate']", nameSpaceManager_)
.Select(e => e.Attribute("type").Value);
}
You do almost everything right.
Just use XPathSelectElement instead of XPathEvaluate.
var showName = showNode.XPathSelectElement("/atom:entry/atom:title", nameSpaceManager_).Value;
var linkTypes = showNode.XPathSelectElements("/atom:entry/atom:link[#rel='alternate']", nameSpaceManager_)
.Select(e => e.Attribute("type").Value);

Sum same named xml nodes

I have edited this little MSDN example https://support.microsoft.com/en-us/kb/311530
And I have the following 2 XML's
Book1.xml
<?xml version="1.0"?>
<catalog>
<book1 id="1" />
<bookSum number="1" />
</catalog>
Book2.xml
<?xml version="1.0"?>
<catalog>
<book2 id="2" />
<bookSum number="1" specialAttribute="123" />
</catalog>
C# Code
XmlReader xmlreader1 = XmlReader.Create(#"C:\Book1.xml");
XmlReader xmlreader2 = XmlReader.Create(#"C:\book2.xml");
DataSet ds = new DataSet();
ds.ReadXml(xmlreader1);
DataSet ds2 = new DataSet();
ds2.ReadXml(xmlreader2);
ds.Merge(ds2);
ds.WriteXml(#"C:\Merge.xml");
Console.WriteLine("Completed merging XML documents");
Merge.xml (Book1.xml + Book2.xml)
<?xml version="1.0" standalone="yes"?>
<catalog>
<book1 id="1" />
<bookSum number="1" />
<bookSum number="1" specialAttribute="x" />
<book2 id="2" />
</catalog>
And the question is
how to join
<bookSum number="1" />
<bookSum number="1" specialAttribute="123" />
into one line ?
<bookSum number="2" specialAttribute="123" />
I did it this way and is working:
var doc = XDocument.Load(#"C:\Book1.xml");
doc.Root.Add(XDocument.Load(#"C:\Book2.xml").Root.Elements()); // merged
var sum = doc.Descendants("bookSum").Attributes("number").Sum(t => int.Parse(t.Value));
var xElement = new XElement("bookSum", new XAttribute("number", sum));
foreach(var attrib in doc.Descendants("bookSum").Attributes())
{
if (xElement.Attribute(attrib.Name) == null)
xElement.Add(attrib);
}
doc.Descendants("bookSum").ToList().ForEach(t => t.ReplaceWith(xElement));
doc.Root.Descendants("bookSum").First().Remove();
Console.WriteLine(doc);

C# returning an XML element with ancestors and self, but no other children

I have an xml doc layout like so
<?xml version="1.0" encoding="utf-8" ?>
<Document name="document name">
<DataSet name="dataset 1">
<Dimension name="dimension 1">
<Metric name="metric 1">
<Data value="1">
<Data value="2">
<Data value="3">
</Metric>
<Metric name="metric 2">
<Data value="4">
<Data value="5">
<Data value="6">
</Metric>
</Dimension>
<Dimension name="dimension 2">
<Metric name="metric 3">
<Data value="6">
<Data value="7">
<Data value="8">
</Metric>
<Metric name="metric 4">
<Data value="9">
<Data value="10">
<Data value="11">
</Metric>
</Dimension>
</DataSet>
</Document>
I am attempting to split the Metrics out with their ancestors but not with their siblings. For example I want a file to look like...
<?xml version="1.0" encoding="utf-8" ?>
<Document name="document name">
<DataSet name="dataset 1">
<Dimension name="dimension 1">
<Metric name="metric 1">
<Data value="1">
<Data value="2">
<Data value="3">
</Metric>
</Dimension>
</DataSet>
</Document>
and file 2 to look like ...
<?xml version="1.0" encoding="utf-8" ?>
<Document name="document name">
<DataSet name="dataset 1">
<Dimension name="dimension 1">
<Metric name="metric 2">
<Data value="4">
<Data value="5">
<Data value="6">
</Metric>
</Dimension>
</DataSet>
</Document>
My attempt to solve this was to create a method that would accept an xmlfile, outputDirectory, elementName, attributeName, and attributeValue.
This would allow me to search the document for a specific metric and pull it out into its own file with its entire tree, but not with it's siblings.
at the top of my method i have...
XDocument doc = XDocument.Load(xmlFile);
IEnumerable<XElement> elementsInPath = doc.Descendants()
.Elements(elementName)
.Where(p => p.Attribute(attributeName).Value.Contains(attributeValue))
.AncestorsAndSelf()
.InDocumentOrder()
.ToList();
However when I iterate through the elementsInPath The output gives all of the parents of the matched "Metric" with each parent return all of its children, and the only child i want present is the one that was matched by the input params.
Any help would be appreciated. Just for reference I save the files using the following snippet
int i = 1;
foreach (XElement element in elementsInPath)
{
XDocument tmpDoc = new XDocument();
tmpDoc.Add(element);
tmpDoc.Save(outputDirectory + elementName + "_" + i + ".xml");
i++;
}
Also to note, If I use the following code I get the exact metrics I am looking for, but i need to encapsulate them within their parents.
IEnumerable<XElement> elementsInPath = doc.Descendants(elementName)
.Where(p => p.Attribute(attributeName).Value.Contains(attributeValue))
.InDocumentOrder()
.ToList();
So you're really building a new document for each Metric element. The most straightforward way to do this would be:
foreach (XElement el in doc.Root.Descendants("Metric"))
{
XElement newDoc =
new XElement("Document",
new XAttribute(doc.Root.Attribute("name")),
new XElement("DataSet",
new XAttribute(el.Parent.Parent.Attribute("name")),
new XElement("Dimension",
new XAttribute(el.Parent.Attribute("name")),
el)
)
)
);
newDoc.Save(el.Attribute("name").Value.Replace(" ", "_") + ".xml");
}
This hopefully illustrates how the dynamic version of this would work - iterate through the ancestors and create new elements based on them:
foreach (XElement el in doc.Root.Descendants("Metric"))
{
XElement newDoc = el;
foreach(XElement nextParent in el.Ancestors()) // iterate through ancestors
{
//rewrap in ancestor node name/attributes
newDoc = new XElement(nextParent.Name, nextParent.Attributes(), newDoc);
}
newDoc.Save(el.Attribute("name").Value.Replace(" ", "_") + ".xml");
}
Just using the Ancestors() functionality won't work, because when you tried to add them it would also add their children (the siblings of the element you're trying to split on).

How to get the multiple values from xml?

My xml format is like
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<feed xml:base="http://google.com/en-US/syndicate/" xmlns:d="http://schemas.google.com/ado/2007/08/dataservices" xmlns:m="http://schemas.giooglt.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
<title type="text">Partners</title>
<id>http://googlre.com/en-US/syndicate/Partners</id>
<updated>2014-01-16T21:33:20Z</updated>
<link rel="self" title="Partners" href="Partners" />
<entry>
<id>http://pinpoint.microsoft.com/en-US/syndicate/Partners('4555')</id>
<title type="text">M55p; Co</title>
<summary type="text">
cccc is a Certified Partner, reseller, and implementer of
Key industries we work with include:
• Financial services
• Professional services
• Media / publishing
By focusing on mid-market to enterprise clients,
</summary>
<published>2009-07-21T14:23:50-07:00</published>
<updated>2013-11-22T15:00:46-08:00</updated>
<author>
<name>google chrome</name>
<uri>http://google.com/</uri>
<email>retee#gmail.com</email>
</author>
<link rel="edit" title="Partner" href="Partners('4255')" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Links" type="application/atom+xml;type=feed" title="Links" href="Partners('4559')/Links">
<m:inline>
<feed>
<title type="text">Links</title>
<id>http://google.com/('429')/Links</id>
<updated>2014-01-16T21:33:20Z</updated>
<link rel="self" title="Links" href="Partners('4ff')/Links" />
<entry>
<id>http://ryryr.com/en-US/syndicate/Links('ufufr')</id>
<title type="text">
</title>
<updated>2014-01-16T21:33:20Z</updated>
<author>
<name />
</author>
<link rel="edit" title="Link" href="Links('partnerpage')" />
<category term="google.Commerce.ferrr.Syndicate.V2010_05.Link" sch="" eme="http://schemas.frrr.com/ado/2007/08/dataservices/scheme" />
<content type="application/xml">
<m:properties>
<d:Type>pgooglrpartnerpage</d:Type>
<d:Description>google Partner Page</d:Description>
<d:Url>http://googlgt.com/en-US/PartnerDetails.aspx?PartnerId=42555&wt.mc_id=66ttet</d:Url>
</m:properties>
</content>
</entry>
<entry>
<id>http://googlet.com/en-US/syndicate/Links('tpartnerrfipage')</id>
<title type="text">
</title>
<updated>2014-01-19T04:01:49Z</updated>
<author>
<name />
</author>
<link rel="edit" title="Link" href="Links('pinpointpartnerrfipage')" />
<category term="google.Commerce.Marketplace.Syndicate.V2010_05.Link" scheme="http://schemas.google.com/ado/2007/08/dataservices/scheme" />
<content type="application/xml">
<m:properties>
<d:Type>tpartnerrfipage</d:Type>
<d:Description>RFI Page</d:Description>
<d:Url>http://pinpoint.microsoft.com/en-US/RFI.aspx?partnerId=4295719419&wt.mc_id=54545</d:Url>
</m:properties>
</content>
</entry>
</feed>
</m:inline>
</link>
</entry>
<entry>
<id>http://pinpoint.microsoft.com/en-US/syndicate/Partners('45')</id>
<title type="text">vfere</title>
<summary type="text">
cccc is a Certified Partner, reseller, and implementer of
Key industries we work with include:
• Financial services
• Professional services
• Media / publishing
By focusing on mid-market to enterprise clients,
</summary>
<published>2009-07-21T14:23:50-07:00</published>
<updated>2013-11-22T15:00:46-08:00</updated>
<author>
<name>google chrome</name>
<uri>http://google.com/</uri>
<email>retee#gmail.com</email>
</author>
<link rel="edit" title="Partner" href="Partners('4255')" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Links" type="application/atom+xml;type=feed" title="Links" href="Partners('4559')/Links" >
<m:inline>
<feed>
<title type="text">Links</title>
<id>http://google.com/('429')/Links</id>
<updated>2014-01-16T21:33:20Z</updated>
<link rel="self" title="Links" href="Partners('4ff')/Links" />
<entry>
<id>http://ryryr.com/en-US/syndicate/Links('ufufr')</id>
<title type="text">
</title>
<updated>2014-01-16T21:33:20Z</updated>
<author>
<name />
</author>
<link rel="edit" title="Link" href="Links('partnerpage')" />
<category term="google.Commerce.ferrr.Syndicate.V2010_05.Link" scheme="http://schemas.frrr.com/ado/2007/08/dataservices/scheme" />
<content type="application/xml">
<m:properties>
<d:Type>pgooglrpartnerpage</d:Type>
<d:Description>google Partner Page</d:Description>
<d:Url>http://googlgt.com/en-US/PartnerDetails.aspx?PartnerId=42555&wt.mc_id=66ttet</d:Url>
</m:properties>
</content>
</entry>
<entry>
<id>http://googlet.com/en-US/syndicate/Links('tpartnerrfipage')</id>
<title type="text">
</title>
<updated>2014-01-19T04:01:49Z</updated>
<author>
<name />
</author>
<link rel="edit" title="Link" href="Links('pinpointpartnerrfipage')" />
<category term="google.Commerce.Marketplace.Syndicate.V2010_05.Link" scheme="http://schemas.google.com/ado/2007/08/dataservices/scheme" />
<content type="application/xml">
<m:properties>
<d:Type>tpartnerrfipage</d:Type>
<d:Description>RFI Page</d:Description>
<d:Url>http://pinpoint.microsoft.com/en-US/RFI.aspx?partnerId=4295719419&wt.m</d:Url>
</m:properties>
</content>
</entry>
</feed>
</m:inline>
</link>
</entry>
</feed>
I have written the code with some help so as to parse the Xml and get the data as
var reader = new StreamReader(#"C:/Users/Administrator/Downloads/direct.xml")
var xmlDoc = XDocument.Load(reader);
XNamespace atom = "http://www.w3.org/2005/Atom";
XNamespace metadata = "http://schemas.giooglt.com/ado/2007/08/dataservices/metadata";
XNamespace dataservices = "http://schemas.google.com/ado/2007/08/dataservices";
var result = xmlDoc.Root.Elements(atom + "entry")
.Select(e => new {
Title = e.Element(atom + "title").Value,
Id = e.Element(atom + "id").Value,
Urls = e.Elements(atom + "link")
.Where(l => l.Element(metadata + "inline") != null)
.SelectMany(l => l.Element(metadata + "inline")
.Element(atom + "feed")
.Elements(atom + "entry")
.Select(e1 => e1.Element(atom + "content")
.Element(metadata + "properties")
.Element(dataservices + "Url").Value))
});
foreach (var item in result)
{
Debug.WriteLine("{0}, {1}, {2}", item.Title, item.Id,item.Urls);
Debug.WriteLine(item.Urls.GetType());
foreach(var i in item.Urls){
Debug.WriteLine("i :"+i);
}
}
My desired output is -
M55p; Co,http://pinpoint.microsoft.com/en-US/syndicate/Partners('4555'),http://googlgt.com/en-US/PartnerDetails.aspx? PartnerId=42555&wt.mc_id=66ttet
M55p; Co,http://pinpoint.microsoft.com/en-US/syndicate/Partners('4555'),http://pinpoint.microsoft.com/en-US/RFI.aspx?partnerId=4295719419&wt.mc_id=54545
vfere,http://pinpoint.microsoft.com/en-US/syndicate/Partners('45'),http://googlgt.com/en-US/PartnerDetails.aspx?PartnerId=42555&wt.mc_id=66ttet
vfere,http://pinpoint.microsoft.com/en-US/syndicate/Partners('45'),http: //pinpoint.microsoft.com/en-US/RFI.aspx?partnerId=4295719419&wt.m
But the output I am getting from the above piece of code is :
M55p; Co,http://pinpoint.microsoft.com/en-US/syndicate/Partners('4555'),System.Linq.Enumerable+<SelectManyIterator>d__14`2[System.Xml.Linq.XElement,System.String]
M55p; Co,http://pinpoint.microsoft.com/en-US/syndicate/Partners('4555'),System.Linq.Enumerable+<SelectManyIterator>d__14`2[System.Xml.Linq.XElement,System.String]
vfere,http://pinpoint.microsoft.com/en-US/syndicate/Partners('45'),System.Linq.Enumerable+<SelectManyIterator>d__14`2[System.Xml.Linq.XElement,System.String]
vfere,http://pinpoint.microsoft.com/en-US/syndicate/Partners('45'),System.Linq.Enumerable+<SelectManyIterator>d__14`2[System.Xml.Linq.XElement,System.String]
I am getting the output as specified above and I am not quite sure why am I getting the above output. I desire to get the result for each 'Url' as is specified in the desired output. been fighting for a while to get the desired result.
Any help is appreciated. Novice programmer, new to C# not sure how to get the output. Is this because of the wrong XML format?
Your code is trying to call ToString() on a Linq expression which is why you're seeing that System.Linq.Enumerable+ gobbledygook.
You need to enumerate the Urls:
foreach (var item in result)
{
var i = 0;
foreach (var url in item.Urls)
{
Debug.WriteLine("{0}, {1}, {2}", item.Title, item.Id, url);
Debug.WriteLine(url.GetType());
Debug.WriteLine("i : " + i++);
}
}
or a more succinct way to write this:
result.ToList().ForEach(item =>
{
var i = 0;
foreach (var url in item.Urls)
{
Debug.WriteLine("{0}, {1}, {2}", item.Title, item.Id, url);
Debug.WriteLine(url.GetType());
Debug.WriteLine("i : " + i++);
}
});

SelectNodes give the empty node even if the xml Contains the node

XPathNavigator nav = xmlDoc.CreateNavigator();
XmlNamespaceManager nsMgr = new XmlNamespaceManager(nav.NameTable);
nsMgr.AddNamespace(string.Empty,#"http://www.w3.org/2005/Atom");
nsMgr.AddNamespace("dxp",#"http://schemas.google.com/analytics/2009");
nsMgr.AddNamespace("openSearch",#"http://a9.com/-/spec/opensearch/1.1/");
XmlNodeList nodeList = xmlDoc.SelectNodes("entry",nsMgr); // nodeList is empty why?
After execution of above code nodeList is empty
But when I see the XMLDocument it contains the the required Nodes entry
Here is the the XMLDocument innerXML
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dxp="http://schemas.google.com/analytics/2009" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/">
<id>https://www.googleapis.com/analytics/v2.4/data?ids=ga:63294209&dimensions=ga:visitorType&metrics=ga:visitors&start-date=2012-10-06&end-date=2012-11-06</id>
<updated>2012-11-06T10:04:40.613Z</updated>
<title type="text">Google Analytics Data for Profile 63294209</title>
<link rel="self" type="application/atom+xml" href="https://www.googleapis.com/analytics/v2.4/data?ids=ga:63294209&dimensions=ga:visitorType&metrics=ga:visitors&start-date=2012-10-06&end-date=2012-11-06" />
<author>
<name>Google Analytics</name>
</author>
<generator>Google Analytics</generator>
<openSearch:totalResults>2</openSearch:totalResults>
<openSearch:startIndex>1</openSearch:startIndex>
<openSearch:itemsPerPage>1000</openSearch:itemsPerPage>
<dxp:aggregates>
<dxp:metric name="ga:visitors" type="integer" value="6709" />
</dxp:aggregates>
<dxp:containsSampledData>false</dxp:containsSampledData>
<dxp:dataSource>
<dxp:property name="ga:profileId" value="63294209" />
<dxp:property name="ga:webPropertyId" value="UA-34279407-1" />
<dxp:property name="ga:accountName" value="The Federal Savings Bank" />
<dxp:tableId>ga:63294209</dxp:tableId>
<dxp:tableName>The Federal Savings Bank</dxp:tableName>
</dxp:dataSource>
<dxp:endDate>2012-11-06</dxp:endDate>
<dxp:startDate>2012-10-06</dxp:startDate>
<entry>
<id>https://www.googleapis.com/analytics/v2.4/data?ids=ga:63294209&ga:visitorType=New+Visitor&start-date=2012-10-06&end-date=2012-11-06</id>
<updated>2012-11-06T10:04:40.613Z</updated>
<title type="text">ga:visitorType=New Visitor</title>
<link rel="alternate" type="text/html" href="http://www.google.com/analytics" />
<dxp:dimension name="ga:visitorType" value="New Visitor" />
<dxp:metric name="ga:visitors" type="integer" value="5240" />
</entry>
<entry>
<id>https://www.googleapis.com/analytics/v2.4/data?ids=ga:63294209&ga:visitorType=Returning+Visitor&start-date=2012-10-06&end-date=2012-11-06</id>
<updated>2012-11-06T10:04:40.613Z</updated>
<title type="text">ga:visitorType=Returning Visitor</title>
<link rel="alternate" type="text/html" href="http://www.google.com/analytics" />
<dxp:dimension name="ga:visitorType" value="Returning Visitor" />
<dxp:metric name="ga:visitors" type="integer" value="1469" />
</entry>
</feed>
There's a known issue in .NET with the default XML namespace - contrary to what is defined in the XML standards, in .NET you cannot use a string.Empty as the prefix - you need to use something else.
Try this:
XPathNavigator nav = xmlDoc.CreateNavigator();
XmlNamespaceManager nsMgr = new XmlNamespaceManager(nav.NameTable);
nsMgr.AddNamespace("def", #"http://www.w3.org/2005/Atom"); <== Give this a prefix!
nsMgr.AddNamespace("dxp", #"http://schemas.google.com/analytics/2009");
nsMgr.AddNamespace("openSearch", #"http://a9.com/-/spec/opensearch/1.1/");
XmlNodeList nodeList = xmlDoc.SelectNodes("/def:feed/def:entry", nsMgr);
Now, this list does have two nodes in it - right?

Categories

Resources