xpath

ancestor-or-self

Hi everyone, I have the following xml: <?xml version="1.0" encoding="utf-8" ?> <ROLES> <ROLE type="A"> <USER name="w" /> <USER name="x" /> <ROLE type="B"> <USER name="x" /> <USER name="y" /> </ROLE> <ROLE type="C"> <USER name="x" /> <USER name="y" /> <USER name="z" /> ...

Linq to XML vs DOM

Hi, In one of the applications we are developing we do lot of XML processing. Currently we use DOM and XPath for most of the processing and we are not much happy with the performance. At the moment we are considering of moving XML processing logic to LINQ and our initial investigations suggest LINQ performance is much better than DOM....

HtmlAgilityPack selecting childNodes not as expected

I am attempting to use the HtmlAgilityPack library to parse some links in a page, but I am not seeing the results I would expect from the methods. In the following I have a HtmlNodeCollection of links. For each link I want to check if there is an image node and then parse its attribures but the SelectNodes and SelectSingleNode methods o...

Xpath and XmlNameSpace

I have the following XML <?xml version="1.0"?> <FileHeader xmlns="urn:schemas-ncr-com:ECPIX:CXF:FileStructure:020001" VersionNumber="020001" TestFileIndicator="P" CreationDate="13012009" CreationTime="172852" FileID="0000000001" > <Item ItemSeqNo="09011340010009" PayorBankRoutNo="00704524" Amount="3980...

XPath partial of attribute known

I known the partial value of an attribute in a document, but not the whole thing. Is there a character I can use to represent any value? For example, a value of a label for an input is "A. Choice 1". I know it says "Choice 1", but not whether it will say "A. " or "B. " before the "Choice 1". Below is the relevant HTML. There are oth...

XPath - Get node with no child of specific type

XML: /A/B or /A I want to get all A nodes that not have any B childs. I´ve tried /A[not(B)] /A[not(exists(B))] without success I prefer a solution with the syntax /*[local-name()="A" and .... ], if possible. Any ideas that works? Clarification. The xml looks like: <WhatEver> <A> <B></B> </A> </WhatEver> or <WhatEver> ...

Dom4j detach node, Jython

Hey, I am using Dom4j to detach a node, like below: <div name="divName"> Some Text Here <span>Some Text Here</span> </div> I am selecting the div node by name and then using the detach method to remove it: xpathValue = "//*[contains(@name, 'divName')]" xpath = dom.createXPath(xpathValue) if xpath != None: nodes =...

Q: Update XML doc

I am a beginner to XML and XPath in C#. Here is an example of my XML doc: <root> <folder1> ... <folderN> ... <nodeMustExist>... <nodeToBeUpdated>some value</nodeToBeUpdated> .... </root> What I need is to update the value of nodeToBeUdpated if the node exists or add this node after the nodeMustExist if n...

How to typecast a string to an xPath expression to return a nodeset w/out Javascript

In xPath I have a string that I need to evaluate as an expression to return a nodeset; is this possible without javascript? How? If it matters, I'm using Firefox. ...

SQL Server 2005 XML Queries

Is there a way to apply a schema to an xml column to type values such as Date, int, decimal, etc? Also, when querying the contents with XPath is there a way to do check against the actual type and not its string value? Should we even try this, is there a performance hit with doing raw string checks for these values, or should we even b...

XPath - How can I query for a parent node satisfying an attribute presence condition?

I need to query a node to determine if it has a parent node that contains a specified attribute. For instance: <a b="value"> <b/> </a> From b as my focus element, I'd like to execute an XPath query: ..[@b] that would return element a. The returned element must be the parent node of a, and should not contain any of a's siblings....

xpath with curl gives empty result?

This code gives me an empty result. I expect it to print out the titles from the XML-file. I need to use Curl to get the file. <?php function get_url($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); $data = curl_exec(...

XPath can't find a table by id

I'm doing some screen scraping using WATIJ, but it can't read HTML tables (throws NullPointerExceptions or UnknownObjectExceptions). To overcome this I read the HTML and run it through JTidy to get well-formed XML. I want to parse it with XPath, but it can't find a <table ...> by id even though the table is there in the XML plain as da...

Selecting a specific table with XPath

I've got an XHTML document, and I want to select the only table in it with class="index". If I understand correctly, the descendant axis will select all nodes directly and indirectly descending from the current node, so here's what I've got. //descendant::table[@class="index"] It doesn't appear to be working when tested with xmlstar...

Using XPath in SelectSingleNode: Retrieving individual element from XML if it's present.

My XML looks like : <?xml version=\"1.0\"?> <itemSet> <Item>one</Item> <Item>two</Item> <Item>three</Item> .....maybe more Items here. </itemSet> Some of the individual Item may or may not be present. Say I want to retrieve the element <Item>two</Item> if it's present. I've tried the following XPaths (in C#...

How might I determine the XPath of a DOM element?

In JavaScript, supposing I have a reference to an element, how do I retrieve an XPath expression that would select it? Is there something like objElement.xpath? ...

How can I modify a given xpath string to only have nodes that exist in a specific xml document

I build a xpath string based on all filled-out fields in a form submitted by a user. In my xml document, not all form fields necessarily exist as nodes. When I try to do doc.SelectNodes(xpath); I get an exception System.Xml.XPath.XPathException that my xpath has an invalid token. How can I modify the xpath string to only include tho...

Get out of memory with dataSet.GetXml()

I've got error "System.OutOfMemoryException" if dataSet is too large and the memory is enough. The size of file "file1.xml" is about 36 MB. What is the way to solve this problem? Thanks in advance. private XPathDocument GetXML(DataSet ds) { ds.WriteXml("file1.xml"); ds.WriteXmlSchema("file1.xsd"); XPathDocu...

Using xpath/xslt to get the anchor part of the page url

Hi I'm writing a template in xslt with xpath 1.0 and need to access the anchor tag from the url of the current page. For example, the url: http://localhost/destinations/london.aspx#accommodation I need to be able to get #accommodation and assign it to a variable. I realise I'm somewhat limited by using xpath 1.0 - has anyone got any e...

Select first result in XPath

I've looked at this question: http://stackoverflow.com/questions/453191/select-first-instance-only-with-xpath But if I have a node-set like this: <container value=""> <data id="1"></data> <data id="2">test</data> <container> <data id="1">test</data> <data id="3">test</data> </container> </container> Now my scenario i...