xpath

Counting nodes in XSLT whose parent nodes have certain attributes

I have XML like this: <exam> <section name="SampleSection1"> <attributes> <variable_name data_type="String" value="SCORE"/> </attributes> <item name="SampleItem1-1"/> <item name="SampleItem1-2"/> <item name="SampleItem1-3"/> </section> <section name="SampleSection2"> ...

get id of the node with maximum value

i have something like this <ValueSet> <value id="0">109.3</value> <value id="1">110.6</value> <value id="2">111.1</value> <value id="3">111.5</value> </ValueSet> and i need the id of the node that has the maximum value, i need do this in javascript using Xpath. i do this: var path = "//ValueSet[not(value <= precedi...

Get a specific XML node's position with XPATH?

Let me start by saying I know about position() but I can't seem to figure out how to make it work in this context. What I'm trying to do is iterate through my body of text and find all images. These will be turned into links that say "Figure 1" and so on. The number is provided by the position() of a corresponding node in a different no...

Xpath and variables

Hi, i have an xpath expression that search a static value, in this example 'test' XPathExpression expr = xpath.compile("//doc[contains(., 'test')]/*/text()"); How to pass a variable instead of a fixed text ? i use java on eclipse platform, is there a way to read a java string o declare a xpath variable? Thanks ...

java.io.IOException: Server returned HTTP response code: 503 for URL: http://www.w3.org/TR/html4/strict.dtd

Hey, I'm getting this error with following line: Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(html.toString()))); Details: java.io.IOException: Server returned HTTP response code: 503 for URL: http://www.w3.org/TR/html4/strict.dtd at sun.net.www.proto...

Get elements of specific hierarchy level

Is there any way to retrieve all elements of specific hierarchy level using XPath? Upd. <A> <B>1</B> <B>2</B> </A> <C> <D>3</D> <D>4</D> </C> I need to retrieve all B and D elements (hierarchy level = 2) ...

Exception while querying HTML for ID using HTML Agility Pack

I'm using the HTML Agility pack to parse an ASPX file inside Visual Studio. I'm searching for an element with a specified ID attribute. The code I'm using is: var html = new HtmlAgilityPack.HtmlDocument(); html.LoadHtml(docText); if (html.DocumentNode != null) { try { var tagsWithId = html.DocumentNode.SelectNodes(...

XPath and lxml syntax

Hi everyone. I have a XML file with the structure as shown below: <x> <y/> <y/> . . </x> The number of <y> tags are arbitrary. I want to get the text of the <y> tags and for this I decided to use XPath. I have figured out the syntax, say for the first y: (Assume root as x) textFirst = root.xpath('y[1]/text()') This wor...

Is this impossible with xpath?

Is it possible with xpath to get the result transformed somehow, just like it can be done with SQL? Given the following: <a> <b x="1" y="2" z="3"> <b x="2" y="2" z="3"> </a> For example if I wanted to get all b nodes, but i don't want the z attribute to be part of the the results. Or another thing which Iam thinking about is to ...

Retrieving XML element name using t-SQL

If I have: <quotes> <quote> <name>john</name> <content>something or other</content> </quote> <quote> <name>mary</name> <content>random stuff</content> </quote> </quotes> How do I get a list of the element names 'name' and 'content' using T-SQL? The best I've got so far is: declare @xml xml set @xml = ... sele...

JDOM, XPath and Namespace Interactions

Hi all, I'm having a very frustrating time extracting some elements from a JDOM document using an XPath expression. Here's a sample XML document - I'd like to remove the ItemCost elements from the document altogether, but I'm having trouble getting an XPath expression to evaluate to anything at the moment. <srv:getPricebookByCompan...

How to get nodes using xpath

When I have 2 set of nodes with same element name for ex : <contacts> <names> ... </names> <names> ... </names> </contacts> Normally I'd use //contacts/names to get the node, but how do I do if they have the same name how do I get second or first or nth? ...

Stuck with XPath

Can somebody find what is wrong with this code. It always returns o nodes no matter whatever XPath I chose DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(true); domFactory.setIgnoringComments(true); domFactory.setIgnoringElementContentWhitespace(true); DocumentBuilder builder = do...

xpath: how can i query for an element named test with no attributes at all?

I would like to be able to find an element named 'test' with no attributes at all. How can I do that using XPATH? If i just query for /test it finds me all the test elements even with the ones that contain attributes. example: <main> <test id="test1">txt</test> <test>txt2</test> </main> Querying for //test will find me both of the ...

php xpath: query within a query result

Hello. I'm trying to parse an html file. The idea is to fetch the span's with title and desc classes and to fetch their information in each div that has the attribute class='thebest'. here is my code: <?php $example=<<<KFIR <html> <head> <title>test</title> </head> <body> <div class="a">moshe1 <div class="aa">haim</div> </div> <di...

select all matching nodes using xpath and xslt (without additional templates or for-each)

Hi! I have a particular problem that I can't seem to solve. Is it possible to select all nodes using xpath and xslt without the use of additional templates or for-each? Example xml: <aaa id="11"> <aaa id="21"></aaa> <bbb id="22"> <aaa id="31"></aaa> <bbb id="32"></bbb> <ccc id="33"></ccc> <ddd ...

Use XPath to select the element with a certain token in the value

I have the following XML: <ZMARA SEGMENT="1"> <MATERIAL>000000000030001004</MATERIAL> <PRODUCT_GROUP>14000IAA</PRODUCT_GROUP> <PRODUCT_GROUP_DESC>HER 30 AR NEW Size</PRODUCT_GROUP_DESC> <CLASS_CODE>I046</CLASS_CODE> <CLASS_CODE_DESC>Heritage 30</CLASS_CODE_DESC> ...

In XSLT/XPath, how do I get the first attribute that doesn't match a specific name?

I have this snippet of XSLT code: <xsl:variable name="key" select="@*[1]"/> But I need it to actually set key to be the first attribute (if it exists) that doesn't have a special name. So both of these nodes would have the same key, and special_attr is ignored if it exists. <MyNode var="1" /> <MyNode special_attr="foo" var="1" /> ...

How to get nodelist using java/XPath in an xml file having namespaces and prefixes

How to get nodelist using XPath with namespaces and prefixes? This java code segment doesnt seem to work. NodeList shows = (NodeList) xPath.evaluate("//ns1:Request", new InputSource(new FileReader("sample.xml")), XPathConstants.NODESET); here's the sample.xml for input: 5ec9d112:1292fffd92a 1 ...

XPath in java won't accept variable in expression

Hey all, Can someone be kind enough to explain me why xPath.evaluate("/MEMBER_LIST/MEMBER[1]/ADDRESS", nodeMemberList, XPathConstants.STRING) Returns the value I'm looking for and why xPath.evaluate("/MEMBER_LIST/MEMBER[" + i + "]/ADDRESS", nodeMemberList, XPathConstants.STRING) Returns an empty String? I have to do these in a f...