Hi
Using Xml.XmlDocument I need to get all <rfd:li>-elements below
<photoshop:SupplementalCategories> in the below XML-sample.
I normally use GetElementsByTagName, but since there are other <rfd:id>
elements other places in the doc, I cant.
How do I navigate the tree and get the right nodes?
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="3.1.1-112">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/">
<crs:ToneCurve>
<rdf:Seq>
<rdf:li>0, 0</rdf:li>
<rdf:li>32, 22</rdf:li>
<rdf:li>64, 56</rdf:li>
<rdf:li>128, 128</rdf:li>
<rdf:li>192, 196</rdf:li>
<rdf:li>255, 255</rdf:li>
</rdf:Seq>
</crs:ToneCurve>
<photoshop:SupplementalCategories>
<rdf:Bag>
<rdf:li>Category 1</rdf:li>
<rdf:li>Category 2</rdf:li>
<rdf:li>Category 3</rdf:li>
</rdf:Bag>
</photoshop:SupplementalCategories>
</rdf:Description>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
Norm
Istvan Loerincz - 27 Sep 2006 14:03 GMT
Hi !
look at this example from MSND Library VS .NET 2003
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
XmlDocument doc = new XmlDocument();
doc.Load("booksort.xml");
//Create an XmlNamespaceManager for resolving namespaces.
XmlNamespaceManager nsmgr = new
XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("bk", "urn:samples");
//Select and display the value of all the ISBN attributes.
XmlNodeList nodeList;
XmlElement root = doc.DocumentElement;
nodeList = root.SelectNodes("/bookstore/book/@bk:ISBN", nsmgr);
foreach (XmlNode isbn in nodeList){
Console.WriteLine(isbn.Value);
}
}
}
Best Regards,
Istvan
Istvan Loerincz - 27 Sep 2006 14:07 GMT
Hi
look at this example from MSDN VS .NET 2003
[C#]
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
XmlDocument doc = new XmlDocument();
doc.Load("booksort.xml");
//Create an XmlNamespaceManager for resolving namespaces.
XmlNamespaceManager nsmgr = new
XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("bk", "urn:samples");
//Select and display the value of all the ISBN attributes.
XmlNodeList nodeList;
XmlElement root = doc.DocumentElement;
nodeList = root.SelectNodes("/bookstore/book/@bk:ISBN", nsmgr);
foreach (XmlNode isbn in nodeList){
Console.WriteLine(isbn.Value);
}
}
Best Regards,
Istvan
Istvan Loerincz - 27 Sep 2006 14:19 GMT
You can select a node with SelectSingleNode(..),
then you can, go down, with FirstChild(),
or go to the next Sibling element ( on the same level)
with NextSibling()
or first FirtChild() then while (...NextSibling != null) through all
child elements from the upper level.
or if you know the right level where your elements are,
you could get the elements with SelectNodes();
Best Regards,
Istvan
Klaus Jensen - 28 Sep 2006 10:50 GMT
> You can select a node with SelectSingleNode(..),
Thanks! :)