shweta rokade
asked on
Xpath for root tag in XML
I need xpath for below (root tag) code ::
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<compound>
<name>FooBar</name>
<member>
<name>Something</name>
</member>
</compound>
</rootelement>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<rootelement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="index.xsd">
<compound>
<name>FooBar</name>
<member>
<name>Something</name>
</member>
</compound>
</rootelement>
what value you trying to grab there?
The path to compund.name is:
//compound/name
And the path to memeber.name is:
//member/name
ASKER
I need to define xpath for the </rootelement.......> line for xsi specailly how to define xpath please help.
/rootelement/@xsi:noNamesp aceSchemaL ocation
fetches that particular attribute
For the rootelement itself, see my first comment
fetches that particular attribute
For the rootelement itself, see my first comment
You name the root element as rootelement therefore it is slightly ambigious.
But the first comment is your solution.
But the first comment is your solution.
but that assumes that you have a namespace manager that binds the xsi: prefix to the correct namespace
in order to help you with that, we need to know the context you are using this in
(somewhat more text could help :-)
an alternative
/rootelement/@*[local-name () = 'noNamespaceSchemaLocation ']
in order to help you with that, we need to know the context you are using this in
(somewhat more text could help :-)
an alternative
/rootelement/@*[local-name
ASKER
I have tried below 2 xpath but its creating empty file . its not reading data
/Document[xlmns=@xsi:noNamespaceSchemaLocation]
/Document [xlmns:xsi=http://www.w3.org/2001/XMLSchema-instance/index.xsd]
Tell us PLEASE in more detail what exactly you need.
You failed to do so up till now
Both XPath expressions you show are NOT doing anything useful
/Document[xlmns=@xsi:noNam espaceSche maLocation ]
does this
return the root element Document on the condition that it has a child element "xlmns" that is equal to the value of its attribute @xsi:noNamespaceSchemaLoca tion
The second one is illegal XPath
/Document [xlmns:xsi=http://www.w3.org/2001/XMLSchema-instance/SEI-XML.xsd]
would say
return the root element Document on the condition that it has a child element "xsi" in the namespace bound to the prefix xlmns: that is equal to the element "//www.w3.org/2001/XMLSchema-instance/SEI-XML.xsd" in the namespace bound to the prefix http:
but the "//www.w3.org/2001/XMLSchema-instance/SEI-XML.xsd" is not a valid element name
I assume you want to compare the string value, for that you need to quote the string
/Document [xlmns:xsi="http://www.w3.org/2001/XMLSchema-instance/SEI-XML.xsd"]
but still that would not give you what you want
Please get some basic XPath first
There is a very rough introd here
https://www.geeksforgeeks.org/introduction-to-xpath/
very basic but you need to have at least that background to understand what we put up here
Then you need to explain the context.
Is this inside XSLT? XQuery, what version of XPath...
Try do be precise on what you want to do
Because you might be developing something in Java then claiming the XPath does not return anything...
But XPath returns a nodeset or a node, and after that you need to do something with that node(set)
So, lots of unknowns, if you want some more help, you need to put some more effort in yourself I fear
You failed to do so up till now
Both XPath expressions you show are NOT doing anything useful
/Document[xlmns=@xsi:noNam
does this
return the root element Document on the condition that it has a child element "xlmns" that is equal to the value of its attribute @xsi:noNamespaceSchemaLoca
The second one is illegal XPath
/Document [xlmns:xsi=http://www.w3.org/2001/XMLSchema-instance/SEI-XML.xsd]
would say
return the root element Document on the condition that it has a child element "xsi" in the namespace bound to the prefix xlmns: that is equal to the element "//www.w3.org/2001/XMLSchema-instance/SEI-XML.xsd" in the namespace bound to the prefix http:
but the "//www.w3.org/2001/XMLSchema-instance/SEI-XML.xsd" is not a valid element name
I assume you want to compare the string value, for that you need to quote the string
/Document [xlmns:xsi="http://www.w3.org/2001/XMLSchema-instance/SEI-XML.xsd"]
but still that would not give you what you want
Please get some basic XPath first
There is a very rough introd here
https://www.geeksforgeeks.org/introduction-to-xpath/
very basic but you need to have at least that background to understand what we put up here
Then you need to explain the context.
Is this inside XSLT? XQuery, what version of XPath...
Try do be precise on what you want to do
Because you might be developing something in Java then claiming the XPath does not return anything...
But XPath returns a nodeset or a node, and after that you need to do something with that node(set)
So, lots of unknowns, if you want some more help, you need to put some more effort in yourself I fear
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
"/rootelement " will give you the root element