Click here to Skip to main content
15,879,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
/bookstore/author/first-name
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:

<Cell
<CellContent
<Para
<ParaLine
<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
Comments
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>

Problem is that file doesnt look like a simple xml.
I mean
<NameElement1>
<NameElement2>
abababababababa.
</NameElement1>
</NameElement2>

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?
 
Share this answer
 
If your xml is like below then you can query it using Linq
C#
var xml = @"<cell>
                     <cellcontent>
                     <para>
                     <paraline>
                     <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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900