473,386 Members | 1,773 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.

how to get the element whose children fulfill the requirements

Hello,

I actually have two questions:

I have a xml like this:
<tab>
<category name="Software" > Test purpose
<subcategory name="Software">
<method url="addSoftware.aspx">Add</method>
<method url="editSoftware.aspx">Edit</method>
<method url="searchSoftware.aspx">Search</method>
</subcategory>
</category>
</tab>
1. How can I select the the category noe whose child (subcategory)'s name is
"Software"?
I tried Xpath expression "/tabs/category/subcategory[@name='Software']", but
it gives me the child node. Can someone tell me how to get the parent node
directly?

2. When I create XpthNodeIterator nav and use nav.Value to get the text of
node "Category", I actually gets the concatenated values of the node and all
its child nodes (e.g., in above example, I got Test purposeAddeditsearch).
Which method should I call to get just the text of one node (e.g. just get
"Test purpose" not "Test purposeAddeditsearch")?

Many Thanks
--
hello, please help
Nov 12 '05 #1
1 1025
Hi Jerry,

First a small clarification. In the XML Fragment you have posted, your root
tag is "tab" whereas in the XPATH, you have specified it as "tabs". I assume
"tabs" is the root and it will contain a collection of "tab" nodes. Having
this in mind, the expression to get the parent node is

/tabs/tab/category[subcategory[@name='Software']]

to get the name attribute of Category (which value is also Software)

/tabs/tab/category[subcategory[@name='Software']]/@name

For the Xpathnodeiterator, you need to create another iterator which will
loop through the Category and get the respective values.

Or you can use Xpathnodeiterator.current.value.

Thanks.

"jerry.xuddd" wrote:
Hello,

I actually have two questions:

I have a xml like this:
<tab>
<category name="Software" > Test purpose
<subcategory name="Software">
<method url="addSoftware.aspx">Add</method>
<method url="editSoftware.aspx">Edit</method>
<method url="searchSoftware.aspx">Search</method>
</subcategory>
</category>
</tab>
1. How can I select the the category noe whose child (subcategory)'s name is
"Software"?
I tried Xpath expression "/tabs/category/subcategory[@name='Software']", but
it gives me the child node. Can someone tell me how to get the parent node
directly?

2. When I create XpthNodeIterator nav and use nav.Value to get the text of
node "Category", I actually gets the concatenated values of the node and all
its child nodes (e.g., in above example, I got Test purposeAddeditsearch).
Which method should I call to get just the text of one node (e.g. just get
"Test purpose" not "Test purposeAddeditsearch")?

Many Thanks
--
hello, please help

Nov 12 '05 #2

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

Similar topics

1
by: slimzhao | last post by:
<title> <A ID="ID_1"/> <B ID="ID_2"/> <SomeThingElse ID="ID_1000"/> </title> What I want to do is to write a schema for <title>'s children, which element type is restricted to <xs:attribute...
4
by: Jean-Christophe Michel | last post by:
Hi, In a complex merging of two (non ordered) xml files i need to keep track of the elements of the second tree that were already merged with first tree, to copy only unused elements at the end....
3
by: Michael Reiche | last post by:
Question on XSL expression Got this XML: <Body> <Page> <Line no="9" detail="true"> <onefield>onefieldstext</onefield> <twofield>twofieldstext</twofield> </Line>
1
by: Matt | last post by:
I want to get the number of children of a given element. Below is my code attempt and the xml sample file. The caller is getElementChildNumber("persons");, I expect to get 2. Since there are 2...
6
by: Wole Ogunremi | last post by:
I guess this is a well asked question but it is tripping me up! I'm putting a forum together allowing xhtml markup content. I am validating against a schema but getting "Could not find schema...
6
by: Luke Dalessandro | last post by:
I'm not sure if this is the correct forum for platform specific (Mozilla/Firefox) javascript problems, so just shout and point me to the correct newsgroup if I'm being bad. Here's the deal... ...
5
by: Arturius mac Aidan | last post by:
I'm not sure if this has been addressed in more recent developments, but I'm reading the MathML specification which states "For example, it is not possible in XML to specify that the first child be...
43
by: michael.f.ellis | last post by:
The following script puzzles me. It creates two nested lists that compare identically. After identical element assignments, the lists are different. In one case, a single element is replaced. In...
3
by: Andrej Pavlovic | last post by:
Hi, Please look at the following HTML snippet: <body> some text <p>more text</p> even more text </body>
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:
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
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...
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
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...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.