xpath problem

  • Thread starter Thread starter Gigs_
  • Start date Start date
G

Gigs_

How can i get children from specific parent if i have 2 or more same
parent with same childre? only difference is text inside children

<root>
<parent sifra="G1">
<child id=1>first text>/child>
<child id="2">second text</child>
</parent>
<parent sifra="G1">
<child id=1>third text>/child>
</parent>
</root>

i need to get "first text" first and than in another temp xmldocument
change some tag value with this one, if parent have more children,
than process them and write temp xml to third xml file and check for
second parent with sifra and get third text and same thing

thanks!
 
Gigs_ said:
How can i get children from specific parent if i have 2 or more same
parent with same childre? only difference is text inside children

<root>
<parent sifra="G1">
<child id=1>first text>/child>
<child id="2">second text</child>
</parent>
<parent sifra="G1">
<child id=1>third text>/child>
</parent>
</root>

i need to get "first text" first and than in another temp xmldocument
change some tag value with this one, if parent have more children,
than process them and write temp xml to third xml file and check for
second parent with sifra and get third text and same thing

Assuming the XML looks like this

<root>
<parent sifra="G1">
<child id="1">first text</child>
<child id="2">second text</child>
</parent>
<parent sifra="G1">
<child id="1">third text</child>
</parent>
</root>

then this C# code

XPathDocument doc = new XPathDocument(@"..\..\XMLFile2.xml");
foreach (XPathNavigator parent in
doc.CreateNavigator().Select("root/parent[@sifra = 'G1']"))
{
XPathNavigator child1 =
parent.SelectSingleNode("child[@id = '1']");
if (child1 != null)
{
Console.WriteLine(child1.Value);
}
}

outputs

first text
third text

which I think is part of what you want to achieve, namely iterating over
the parent elements where the sifra attribute has the value 'G1' and
outputting the contents of the child element with id being '1'.
 
Back
Top