473,386 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

xpath problem

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!
Jun 27 '08 #1
1 1246
Gigs_ wrote:
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'.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: gael.pegliasco | last post by:
Hi, How are you dear and nice helper :) ? I'm trying to test xpath with this simple program : import xml.dom.minidom from xml.xpath.Context import Context import xml.xpath
6
by: Ramon M. Felciano | last post by:
Helo all -- I'm trying to gain a deeper understand for what type of semi-declarative programming can be done through XML and XPath/XSLT. I'm looking at graph processing problems as a testbed for...
4
by: Son KwonNam | last post by:
In XSLT, is this possible to get value from xml using XPath which is in XSLT variable? I mean XPath strings can be dynamic while XSL Transforming. If possible, How?? Because I'm not a...
3
by: Kathy Burke | last post by:
Hi again, I'm using the following xpath (works in visualizer) with a SelectSingleNode("xpath") statement. //Station/(WI])]/@order Problem is I get an error "expression passed to this method...
5
by: jorgedelgadolopez | last post by:
Hi all, I am using the xpathnavigator evaluate function on .net (xpath 1 right?). Now I need to expand the code to do multiple contains, compare dates (such as 'before', 'between' and 'after'),...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.