Solved

Xml nested

Posted on 2004-10-10
3
209 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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
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 tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now