473,396 Members | 2,010 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 Syntax to query?

Hello all,

I have got an XML looks like the following. How can I use an XPATH
command to select //hostname and //instance? If there is no instance in
the sever, just skip, so it returns

<hostname>Host A</hostname>
<instance name="TOM" port="12345"/>
<instance name="TOM1" port="12346"/>
<hostname>Host B</hostname>
<hostname>Host C</hostname>
<instance name="TOM2" port="12345"/>
<instance name="TOM3" port="12346"/>
Basically, I want to select all the hostname, and certain field in the
<serverblock.

Thanks!

=============
<?xml version="1.0" encoding="UTF-8"?>
<servers>
<server>
<record_info>
<lastchecked>20050316</lastchecked>
<hostname>Host A</hostname>
</record_info>
<components>
<instance name="TOM" port="12345"/>
<instance name="TOM1" port="12346"/>
</components>
<supp_info>
<contact name="TOM" email=""/>
<contact name="MARY" email=""/>
</supp_info>
</server>
<server>
......
</server>
<server>
......
</server>
</servers>

=============

Dec 5 '06 #1
4 1441
In article <11**********************@j44g2000cwa.googlegroups .com>,
<ar************@gmail.comwrote:
>I have got an XML looks like the following. How can I use an XPATH
command to select //hostname and //instance?
//hostname | //instance

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Dec 5 '06 #2
The XPath to "all hostname elements, at any dept" is simply //hostname,
which you seem to be aware of... so I presume your question is about how
to request that the XPath be executed, and that depends on what
environment you're working in (which you didn't tell us).
Dec 5 '06 #3

"Joseph Kesselman дµÀ£º
"
The XPath to "all hostname elements, at any dept" is simply //hostname,
which you seem to be aware of... so I presume your question is about how
to request that the XPath be executed, and that depends on what
environment you're working in (which you didn't tell us).
Thanks Richard and Joseph,

//hostname | //instance kind of works, but it will give like all the
hostname, and then all the instance

<hostname>
<hostname>
<hostname>
<instance>
<instance>
<instance>

but i need to have them in order,
like
<hostname>
<instance>
<instance>
<hostname << if there is no instance then just return nothing

<hostname>
<instance>

Sorry I should have mentioned, I am Java and the JDOM API

Any more advice please

Thanks!!

Dec 5 '06 #4
ar************@gmail.com wrote:
//hostname | //instance kind of works, but it will give like all the
hostname, and then all the instance
That XPath expression should yield everything in document order. If that
isn't what you're seeing, your implementation of XPath is broken.
--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Dec 6 '06 #5

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

Similar topics

14
by: inquirydog | last post by:
Hi- One frusterating thing for me with xsl is that I don't know how to make xslt throw some sort of exception when a value-of path does not exist. For instance, suppose I have the following...
8
by: Terry P | last post by:
Are there any tools (java classes, tag libraries) which can translate xpath statements into a SQL query? Given an xpath query which has a predicate that filters node values or attributes, I want...
1
by: Brad Hehe | last post by:
I am attempting to use XPath to query for a specific node in the sample XML I've provided below. I'm unsure of the exact XPath syntax, but I believe I need the following query to get the proper...
2
by: C# newbie | last post by:
Hi, How can I make my XPath query to return both "Bob" & "bob" (during search for a string) ? any idea? thanks
9
by: David Thielen | last post by:
Hi; I am sure I am missing something here but I cannot figure it out. Below I have a program and I cannot figure out why the xpath selects that throw an exception fail. From what I know they...
10
by: TR | last post by:
I'm trying the select a element based on values of two attributes. In the Xml doc i need to look at an attribute minVal and maxVal. if the Value I'm passing in in the xPath is greate than min...
3
by: beachboy | last post by:
can we get the max value of element from xpath e.g: Xpath Query Expression: /Books/Book to select XMLNode which id is "3" Can I use Xpath to get the MAX Book id? Thanks in advanced.
3
by: Jason Mobarak | last post by:
Hello -- I'm attempting to get a handle on how to do xpath queries with System.Xml -- so far the biggest hurdle has been how to deal with a default namespace. If I use the test xml: <?xml...
7
by: Tim Hallwyl | last post by:
Hi, there! As I understand the XPaht recommendation, the context node is a node; not a node-list, not XPath object -- but a single node. Now, the WS-BPEL 2.0 specification allows an XML simple...
6
by: Phantom | last post by:
I totally need the help of the XML experts up here, I can't figure this one out, I've been working on it for hours today, googling my brains out. I need to write an xpath query string that...
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: 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
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...
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...

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.