xpath

how to use xpath in python

Is there a full implementation? How is the library used, where is its website? ...

Regex Rejecting matches because of Instr

What's the easiest way to do a "instring" type function with a regex. For example, how could I reject a whole string because of the presence of a single character such as ":" for example: "this" - okay "there:is" - not okay because of ":" More practically, how can I match the following string: //foo/bar/baz[1]/ns:foo2/@attr/text() ...

XPATHS and Default Namespaces

What is the story behind XPATH and support for namespaces? Did XPATH as a specification precede namespaces? If I have a document where elements have been given a default namespace: <foo xmlns="uri" /> It appears as though some of the XPATH processor libraries won't recognize //foo because of the namespace whereas others w...

XPath and Selecting a single node

I'm using XPath in .NET to parse an XML document, along the lines of: XmlNodeList lotsOStuff = doc.SelectNodes("//stuff"); foreach (XmlNode stuff in lotsOStuff) { XmlNode stuffChild = stuff.SelectSingleNode("//stuffChild"); // ... etc } The issue is that the XPath Query for stuffChild is always returning the child of the first ...

How do I select an XML-node based on its content?

How can I use XPath to select an XML-node based on it's content? If I e.g. have the following xml and I want to select the <author>-node that contains Ritchie to get the author's full name: <books> <book isbn='0131103628'> <title>The C Programming Language</title> <authors> <author>Ritchie, Dennis M.</author> ...

Can I create a value for a missing tag in XPath?

I have an application which extracts data from an XML file using XPath. If a node in that XML source file is missing I want to return the value "N/A" (much like the Oracle NVL function). The trick is that the application doesn't support XSLT; I'd like to do this using XPath and XPath alone. Is that possible? ...

Can XPath match on parts of an element's name?

I want to do this: //*fu, which returns all nodes whose name ends in fu, such as <tarfu /> and <snafu />, but not <fubar /> ...

Count Xpaths in XmlSpy

I am using XmlSpy to analyze an xml file, and I want to get a quick count of the number of nodes that match a given xpath. I know how to enter the xpath and get the list of nodes, but I am really just interested in the count. Is it possible to get this? I'm using XmlSpy Professional Edition version 2007 sp2, if it matters. ...

How to load an xml string in the code behind to databound UI controls that bind to the XPath of the XML?

Every sample that I have seen uses static XML in the xmldataprovider source, which is then used to databind UI controls using XPath binding. Idea is to edit a dynamic XML (structure known to the developer during coding), using the WPF UI. Has anyone found a way to load a dynamic xml string (for example load it from a file during runtim...

xslt and xpath: match conditionally upon current node value

given the following xml: <current> <login_name>jd</login_name> </current> <people> <person> <first>John</first> <last>Doe</last> <login_name>jd</login_name> </preson> <person> <first>Pierre</first> <last>Spring</last> <login_name>ps</login_name> </preson> </people> how can i get "John Doe" from within...

Getting The XML Data Inside Custom XPath function

Is there a way to get the current xml data when we make our own custom XPath function (see here). I know you have access to an XPathContext but is this enough? Example: Our XML: <foo> <bar>smang</bar> <fizz>buzz</fizz> </foo> Our XSL: <xsl:template match="/"> <xsl:value-of select="ourFunction()" /> </xsl:template> How do w...

How do get element out of xml file

From a service i get a xml-file. Now I want to get one of those element out of the file. I think I should go into some xpath - any good starter reference ? ...

Get list of XML attribute values in Python

I need to get a list of attribute values from child elements in Python. It's easiest to explain with an example. Given some XML like this: <elements> <parent name="CategoryA"> <child value="a1"/> <child value="a2"/> <child value="a3"/> </parent> <parent name="CategoryB"> <child value="b1"/> ...

Flatten XML to HTML table using XSLT

There must be a generic way to transform some hierachical XML such as: <element1 A="AValue" B="BValue"> <element2 C="DValue" D="CValue"> <element3 E="EValue1" F="FValue1"/> <element3 E="EValue2" F="FValue2"/> </element2> ... </element1> into the flattened XML (html) picking up selected attributes along the way and...

Using SQL Server 2005's XQuery select all nodes with a specific attribute value, or with that attribute missing.

Update: giving a much more thorough example. The first two solutions offered were right along the lines of what I was trying to say not to do. I can't know location, it needs to be able to look at the whole document tree. So a solution along these lines, with /Books/ specified as the context will not work: SELECT x.query('.') FROM @x...

Are .NET 3.5 XPath classes and methods XSLT 2.0 compatible?

I'd like to use regular expressions in selecting elements using the match function. I'd prefer not to use an external library (such as saxon) to do this. ...

How do you bind in xaml to a dynamic xpath?

I have a list box that displays items based on an xpath. This xpath changes depending on user selection elsewhere in the gui. The xpath always refers to the same document. At the moment i use some c# code behind to change the binding of the control to a new xpath expression. I'd like instead to bind in xaml to an xpath and then change...

Choosing xpath version for .net IIS apps

We've got a .net CMS running on IIS 6 which uses xslt templates. It seems to be running xpath 1.0 (as we can't use any 2.0 functionality). How do we go about installing or specifying that IIS should use xpath 2.0? Is it installed per server, or can we specify which version to use on a per-application pool or per-site basis? Thanks a lo...

Number of nodes meeting a conditional based on attributes

Below is part of the XML which I am processing with PHP's XSLTProcessor: <result> <uf x="20" y="0"/> <uf x="22" y="22"/> <uf x="4" y="3"/> <uf x="15" y="15"/> </result> I need to know how many "uf" nodes exist where x = y. In the above example, that would be 2. I've tried looping and incrementing some var, but I can'...

What is the correct XPath for choosing attributes that contain "foo"

I haven't used XPath much nor read through tutorials. Given this XML, what XPath returns the first three nodes: <bla> <a prop="Foo1"/> <a prop="Foo2"/> <a prop="3Foo"/> <a prop="Bar"/> </bla> ...