Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 5th, 2006, 01:45 PM
arthuryeung198@gmail.com
Guest
 
Posts: n/a
Default 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>

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

  #2  
Old December 5th, 2006, 01:55 PM
Richard Tobin
Guest
 
Posts: n/a
Default Re: XPATH Syntax to query?

In article <1165327470.617864.277900@j44g2000cwa.googlegroups .com>,
<arthuryeung198@gmail.comwrote:
Quote:
>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.
  #3  
Old December 5th, 2006, 01:55 PM
Joseph Kesselman
Guest
 
Posts: n/a
Default Re: XPATH Syntax to query?

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).
  #4  
Old December 5th, 2006, 11:55 PM
arthuryeung198@gmail.com
Guest
 
Posts: n/a
Default Re: XPATH Syntax to query?


"Joseph Kesselman дµÀ£º
"
Quote:
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!!

  #5  
Old December 6th, 2006, 12:15 AM
Joe Kesselman
Guest
 
Posts: n/a
Default Re: XPATH Syntax to query?

arthuryeung198@gmail.com wrote:
Quote:
//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
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles