Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / September 2006

Tip: Looking for answers? Try searching our database.

Getting the right nodes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Klaus Jensen - 27 Sep 2006 11:27 GMT
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! :)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.