xpath interview questions
Top xpath frequently asked interview questions
How would one get the value of attribute1 (blah) in the following xml using xslt:
<name attribute1="blah" attribute2="blahblah">
</name>
Source: (StackOverflow)
I have a well formed XHTML page.
I want to find the destination URL of a link when I have the text that is linked.
Example
<a rel='nofollow' href="http://stackoverflow.com">programming questions site</a>
<a rel='nofollow' href="http://cnn.com">news</a>
I want an XPath expression such that if given programming questions site
it will give http://stackoverflow.com
and if I give it news
it will give http://cnn.com
.
Source: (StackOverflow)
I want to write something of the sort:
//a[not contains(@id, 'xx')]
(meaning all the links that there 'id' attribute doesn't contain the string 'xx')
I can't find the right syntax.
Source: (StackOverflow)
Having the following XML:
<node>Text1<subnode/>text2</node>
How do I select either the first or the second text node via XPath?
Something like this:
/node/text()[2]
of course doesn't work because it's the merged result of every text inside the node.
Source: (StackOverflow)
How do you do case conversion in XSL?
<xsl:variable name="upper">UPPER CASE</xsl:variable>
<xsl:variable name="lower" select="???"/>
Source: (StackOverflow)
When searching for items in complex JSON arrays and hashes, like:
[
{ "id": 1, "name": "One", "objects": [
{ "id": 1, "name": "Response 1", "objects": [
// etc.
}]
}
]
Is there some kind of query language I can used to find an item in [0].objects where id = 3
?
Source: (StackOverflow)
Just looking at my XML field, my rows look like this:
<person><firstName>Jon</firstName><lastName>Johnson</lastName></person>
<person><firstName>Kathy</firstName><lastName>Carter</lastName></person>
<person><firstName>Bob</firstName><lastName>Burns</lastName></person>
Note that these are three rows in my table.
I'd like to return a SQL result as a table as in
Jon | Johnson
Kathy| Carter
Bob | Burns
What query will accomplish this?
Source: (StackOverflow)
I am looking for something like:
getElementByXpath(//html[1]/body[1]/div[1]).innerHTML
I need to get the innerHTML of elements using JS (to use that in Selenium WebDriver/Java, since WebDriver can't find it itself), but how?
I could use Id attribute, but not all elements have Id attribute.
[FIXED]
I am using jsoup to get it done in Java. That works for my needs.
Thanks for the answers. :)
Source: (StackOverflow)
I have the problem selecting nodes by attribute containing more than one word.
Example:
<div class="atag btag" />
This is my xpath expression: //*[@class='atag']
The expression only works with <div class="atag" />
but not for the above shown.
Any suggestions?
Source: (StackOverflow)
.NET 3.5 doesn't completely support XPATH 2.0 or XSLT 2.0, which is just too bad. Does anyone know if these two will be included and fully supported in any future .NET versions?
Source: (StackOverflow)
Given an XML structure like so:
<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book>
<title lang="eng">Harry Potter</title>
<price>29.99</price>
</book>
<book>
<title lang="eng">Learning XML</title>
<price>39.95</price>
</book>
</bookstore>
How could I get the value of lang
(where lang
is eng
in book title), for the first element?
Source: (StackOverflow)
Given this XML, what XPath returns all elements whose prop
attribute contains Foo
(the first three nodes):
<bla>
<a prop="Foo1"/>
<a prop="Foo2"/>
<a prop="3Foo"/>
<a prop="Bar"/>
</bla>
Source: (StackOverflow)
I want to read XML data using XPath in Java, so for the information I have gathered I am not able to parse XML according to my requirement.
here is what I want to do:
Get XML file from online via its URL, then use XPath to parse it, I want to create two methods in it. One is in which I enter a specific node attribute id, and I get all the child nodes as result, and second is suppose I just want to get a specific child node value only
<?xml version="1.0"?>
<howto>
<topic name="Java">
<url>http://www.rgagnonjavahowto.htm</url>
<car>taxi</car>
</topic>
<topic name="PowerBuilder">
<url>http://www.rgagnon/pbhowto.htm</url>
<url>http://www.rgagnon/pbhowtonew.htm</url>
</topic>
<topic name="Javascript">
<url>http://www.rgagnon/jshowto.htm</url>
</topic>
<topic name="VBScript">
<url>http://www.rgagnon/vbshowto.htm</url>
</topic>
</howto>
In above example I want to read all the elements if I search via @name and also one function in which I just want the url from @name 'Javascript' only return one node element.
I hope I cleared my question :)
Thanks.
Kai
Source: (StackOverflow)
Using a xpath query how do you find if a node (tag) exists at all?
For example if I needed to make sure a website page has the correct basic structure like /html/body and /html/head/title
Source: (StackOverflow)