Click here to Skip to main content
13,054,018 members (73,714 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I've found a lot of articles about how to get node content by using simple xpath expresion and C#, for example:
a) xpath
b) C#
string xpathExpression = /bookstore/author/first-name"
nodes = navigator.Select(xpathExpression)

I wonder how to get content that is inside of element, and the same element is inside another element and another and another. Just take a look on code below:

<String `ABCabcABC abcABC abc ABCABCABC. '>

I only want to extract content ABCabcABC abcABC abc ABCABCABC from String element.
Do you know how to resolve problem by use Xpath expression and .NET C#?
Posted 14-Apr-13 23:37pm
CPallini 15-Apr-13 5:45am
Yours doesn't look a well formed XML.
For instance <ParaLine<String `ABCabcABC abcABC abc ABCABCABC. '>>
Should be:
<ParaLine><SomeTag String="BCabcABC abcABC abc ABCABCABC."></ParaLine>
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If your xml is like below then you can query it using Linq
var xml = @"<cell>
                     <string>ABCabcABC abcABC abc ABCABCABC</string></paraline></para></cellcontent></cell>";
            var list = XDocument.Parse(xml).Descendants("ParaLine")
                 .Select(x => x.Element("string").Value).ToList();

list object will contain all value of string element which is inside ParaLine element.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Problem is that file doesnt look like a simple xml.
I mean

One element include another element, here:
<NameElement1<NameElement2 <NameElement3 abababababababa >>>

So simple XPath syntax doesn't work "/Cell/CellContent/Para/ParaLine/String/text()";.
I ask about sth other solution then simple xpath expresion. Any ideas?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 15 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100