You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by "Albert, Kevin" <kj...@software.rockwell.com> on 2000/06/02 20:12:11 UTC
XPathAPI.selectSingleNode
I'm using Cocoon 1.7.3 (with Xalan 1.0.1) on Tomcat, and am trying to use XPathAPI to select a specific node in an XML document ... but am having trouble getting selectSingleNode to work.
I could just use the DOM getElementsByTagName and then verify that I've got the desired element node, but I'd rather select it directly with selectSingleNode.
Any suggestions/comments would be very appreciated.
Regards,
Kevin Albert
I've got the following schema doc:
<?xml version="1.0" encoding="UTF-8"?>
<schema targetNamespace="http://rsi-logic2k/specweb" xmlns="http://www.w3.org/1999/XMLSchema" xmlns:rsi-fdd="http://rsi-logic2k/specweb">
<simpleType base="string" name="actionType">
<enumeration value="send">
<annotation><documentation>to transport from one location to another location</documentation></annotation>
</enumeration>
</simpleType>
</schema>
and in the following XSP page, I would like to select the simpleType[@name='actionType'] node using XPathAPI.selectSingleNode():
<?xml version="1.0"?>
<?cocoon-process type="xsp"?>
<xsp:page language="java" xmlns:xsp="http://www.apache.org/1999/XSP/Core">
<xsp:structure>
<xsp:include>org.apache.xerces.dom.*</xsp:include>
<xsp:include>org.apache.xerces.parsers.*</xsp:include>
<xsp:include>org.apache.xml.serialize.*</xsp:include>
<xsp:include>org.w3c.dom.*</xsp:include>
<xsp:include>XPathAPI</xsp:include>
</xsp:structure>
<page>
<xsp:logic xml:space="preserve">
String paramOptionType = "Action";
String optionFileSpec = "webapps/docroot/specweb/features/fdd/" + paramOptionType + "s/index.xsd";
InputSource optionFile = new InputSource(optionFileSpec);
DOMParser parser = new DOMParser();
parser.parse(optionFile);
Document docOption = parser.getDocument();
<!-- This returns null -->
Node optionTypeNode = XPathAPI.selectSingleNode(docOption.getDocumentElement(),"simpleType[@name='actionType']");
<!-- This returns null -->
Node optionTypeNode = XPathAPI.selectSingleNode(docOption.getDocumentElement(),"simpleType");
<!-- This returns null -->
Node optionTypeNode = XPathAPI.selectSingleNode(docOption.getDocumentElement(),"//simpleType");
<!-- This returns null -->
Node optionTypeNode = docOption.getElementsByTagName("simpleType[@name='actionType']");
<!-- This returns the simpleType node -->
Node optionTypeNode = XPathAPI.selectSingleNode(docOption.getDocumentElement(),"child::*[1]");
<!-- This returns the simpleType node -->
Node optionTypeNode = docOption.getElementsByTagName("simpleType").item(0);
</xsp:logic>
</page>
</xsp:page>