473,396 Members | 1,784 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,396 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 1247
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.