xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Dupras <bri...@centera.com>
Subject RE: Simlpe XPointer / XPath / XLocator help
Date Thu, 13 Jan 2000 23:48:10 GMT
Awesome!  This is exaclty what I needed to get going.  One problem, though.
I've got the example code working below on an xml doc without namespaces.
As soon as I run it against a doc with namespaces, the xpath selection
breaks.  Below are my 2 xml docs, and their XPath selects.  Is this operator

Thanks again Scott,

Brian Dupras

In both cases, the contextNode is the .getDocumentNode() (<site_view> and
<pp:site_view> respectively)

No namespaces (works fine)
XPath : "./data/page/@rid" = "abdcedfghi234"

<?xml version="1.0" ?>
<site_view rid='urn:uuid:abdcedfghi899'>
    <editor>Brian Dupras</editor>
    <description>blah blah blah</description>
    <!--Main Page-->
    <page rid='abdcedfghi234' />

Namespaces (no nodes selected)
XPath : "./pp:data/pp:page/@rid" = no nodes selected

<?xml version="1.0" ?>
<pp:site_view rid='urn:uuid:abdcedfghi899'
    <pp:editor>Brian Dupras</pp:editor>
    <pp:description>blah blah blah</pp:description>
    <!--Main Page-->
    <pp:page rid='abdcedfghi234' />

Your sample code, changed a bit by me

public NodeList selectNodes(Node contextNode, String str) 
	throws SAXException 
	XPathSupportDefault xpathSupport = new XPathSupportDefault();
	XPath xpath	= new XPath(xpathSupport, null);
	XPathProcessorImpl parser = new XPathProcessorImpl(xpathSupport);
	parser.initXPath(xpath, str, null);
	XObject list = xpath.execute(xpathSupport, contextNode, null);
	NodeList nl = list.nodeset();

	//this debugout shows that no nodes are selected in the namespace
	debugout("selected " + (nl.getLength()) + " nodes<br>");

	return (nl.getLength() > 0) ? nl : null;

public Node selectSingleNode(Node contextNode, String str) 
	throws SAXException 
	NodeList nl = selectNodes(contextNode, str);
	return (nl != null) ? nl.item(0) : null;

How I'm calling the above code:
Node theNode = selectSingleNode(xmlelemSiteView, "./data/page/@rid");
debugout("selected: " + ((theNode!=null) ? theNode.getNodeValue() :

View raw message