0

Hi,
I am very new to this forum. I started learning XPath queries.
Can anyone please assist me on how to get elements from an xml where it doesn't contains any root element.

Thanks,
Vishwanath

2
Contributors
10
Replies
22
Views
2 Years
Discussion Span
Last Post by xml_looser
0

For example, I wan tto find the book element where the book id is bk101 from the below xml conetent:

<book id="bk101">
      <author>Gambardella, Matthew</author>
      <description>with XML.</description>
</book>
<book id="bk201">
      <author>Gambardella, Matthew</author>
      <description>with XML.</description>
</book>
<book id="bk301">
      <author>Gambardella, Matthew</author>
      <description>with XML.</description>
</book>

Thanks in advance,
Vishwanath

0

copy in xml window

<?xml version="1.0"?>
<bookstore>
    <book id="bk101">
        <author>Gambardella, Matthew</author>
        <description>with XML.</description>
    </book>
    <book id="bk201">
        <author>Gambardella, Matthew</author>
        <description>with XML.</description>
    </book>
    <book id="bk301">
        <author>Gambardella, Matthew</author>
        <description>with XML.</description>
    </book>
</bookstore>

and in xpath window

//book[@id="bk201"]/author

result

<author>Gambardella, Matthew</author>

if you not root node indicates it will never go
there are semi-regular in xml to which one must adhere to in order to apply it to

without rootnode

error

Error:DOMDocument::loadXML() [<a href='domdocument.loadxml'>domdocument.loadxml</a>]: Extra content at the end of the document in Entity, line: 5
0

Hi,
If the xml has root node, I am able to get the result. But I want to try XPath to get a particular book where the xml will not have a root node. There are multiple book elements exists with different ids but these elements are not wrapped under a root node.

As I mentioned in my first post, there is no root element.

Thanks,
Vishwanath

0

xpath evaluations go only with valid xml files

for me the question is answered herewith
to regulate the keeping of xml
in xpath then ask without rootnode with '/ /'
the means to address all child nodes

0

So, We can't do XPath query agaonst the xml data which doesn't have a root node?

0

everything which does not comply with the rules of xml
is not xml
see html xml is similar but is not xml
only by restrictions and user-dtd
and so from version 5 it is always more to xml

I suspect your question is create xpath request
without the root node to use and comes with 2 flash
the node and determine with the help xpath and attribute
is the node found

xml file

<?xml version="1.0"?>
    <bookstore>
    <book id="bk101">
    <author>Gambardella, Matthew</author>
    <description>with XML.</description>
    </book>
    <book id="bk201">
    <author>Gambardella, Matthew</author>
    <description>with XML.</description>
    </book>
    <book id="bk301">
    <author>Gambardella, Matthew</author>
    <description>with XML.</description>
    </book>
    </bookstore>

xpath

//*[@id="bk101"]

result

<author>Gambardella, Matthew</author>
<description>with XML.</description>
</book>
This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.