Solved

Xml nested

Posted on 2004-10-10
3
212 Views
Last Modified: 2010-04-15
Hello,

i have got a XML File like this:

<?xml version="1.0" standalone="yes"?>
<Core>
  <Entries>
    <Name>Sample</Name>
    <Link>www.test.org</Link>
    <Comments>
      <Name>localhorsti</Name>
      <Text />
    </Comments>
  </Entries>
  <Entries>
    <Name>k</Name>
    <Link>www.sample.com</Link>
    <Comments>
      <Name>username</Name>
      <Text />
    </Comments>
    <Comments>
      <Name>author</Name>
      <Text />
    </Comments>
  </Entries>
</Core>

and now i want to get all the 'Comment' rows of the second 'Entries' row and set it to a DataSource.

How to do that ?
Thanks, Manuel
0
Comment
Question by:MLeandroK
3 Comments
 
LVL 10

Accepted Solution

by:
Hans Langer earned 500 total points
ID: 12273770
Hi,
use Xpath = "/Core/Entries/Comments[2]"

This is a exelent site of examples of XPath, take a look.
http://www.zvon.org/xxl/XPathTutorial/Output/example1.html

Other Way is use System.Xml.XmlDocument Class

XmlDocument xmldoc = new XmlDocument
xmldoc.load("YourXmlFile.xml")
xmldoc.SelectNodes("/Core/Entries/Comments").Item(1) or  xmldoc.SelectSingleNode("/Core/Entries/Comments[2]")
xmldoc.SelectSingleNode("/Core/Entries/Comments[2]").InnerXml <- Return Xml Node as string

GL
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

808 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