Subjects
Home
Xalan extension functions
Fomatting question serializing DOM with pretty print
xalan with pull parser
Cannot find the declaration
Apache Xalan drop support to run on JRE 1 1 x
Why does Doctype change processing of a document
Node set to XML string via Java extensions in Xalan J: possible?
Templates/Transformers + thread safety???
Problem evaluating xpath with muliple prefix with different namespace
remove an arbitrary attribute from xsl output
Xalan3 XSLT 2 0 XPath 2 0 support?
Problem using compiled translets with Xalan !!
Xalan and jstl 1 1 problem with transform tag
NullPointer in DOM2DTM getLocalName
URIResolvers base parameter with xsltc and cascaded imports
Performance problem for Xalan J on intel dual core
Standard libraries in JAXP?
Serializing a DOM tree to XML file, customize entities replacement
Library Conflict Involving BCEL Library
A question on how users are using <xsl:message >
Kevin Cormier as a new Apache Xalan J committer
Struggling to iterate over tokenized string
Xalan count() trouble
Problem with recursive xpath
Error when switching to java 1 5
document( ' ')
Problem with Xalan2 7 0 transformation
cr/lf options
entity encoded XML
can xalan transform 2 xml using one xslt?
Xalan J JIRA defect review Monday October 16, 2006 from 2:00 to 3:30 pm ED
xsl transform with cdata section elements
xslt parameters not expanded
Weird behavior of XPath evaluate()
How to avoid <xsl:message > instruction prints stylesheet file informations ?
Cannot find SimpleTransform subdirectory after installing Xalan J
recover from document not found exceptions
jdk1 5 and Xalan jar differences?
Performance Issue
Error/Bug adding floating point numbers
XPathAPI: eval exp using nodes with default namespace
modifying xalan to output invalid XML
NullPointerException
mege two separate xml nodes into one
Is this a XALAN document identification bug?
is StylesheetRoot really java io Serializable ?
transform() fails for DOMSource but succeeds for StreamSource
Thoughts on Transformer parameter passing
HELP, Xalan and jstl 1 1 problem with transformer
Problem with XPath namespace axis?
string utils:replace deleting search string if replacement string is an HTML
help with enumeration values pls
xalan 2 5 1 vs 2 7 performance question
How to insert/update in XML document
HTML Serialization and Handling of Ampersands in HREF Attributes
XHTML link tag stripping
SystemId Unknown; Line #24; Column #49; java lang NullPointerException
xpath text() help
Apostrophe problem with xalan 2 7 0
How to set variables in XML document?
Links
Home
Oracle database error code ...
 
Search:  
Power your search with and, or, +, -, or "some phrase" operators.
(xalan-j) : XPathAPI and namespaces

(xalan-j) : XPathAPI and namespaces

2006-02-14       - By sol myr
Reply:     1     2  

I'm having a problem with XPATH and namespaces.
Could anyone please help ?

I'm using apache XPathAPI, with java 1.4.
It works fine as long as there are no namespaces.
Unfortunately, when adding namespaces to the xml, XPathAPI fails to find the
desired element (returning null).
 
 --- code ----------------------------------------
 String xml=
    "< ns1:body xmlns:ns1='tempuri' >" +
           "< ns1:status > OK < / ns1:status >" +
    "< / ns1:body >";

 // Parse the above xml string:
DocumentBuilder docBuilder= DocumentBuilderFactory.newInstanc()
.newDocumentBuilder();
Document doc=docBuilder.parse(new InputSource(new StringReader(xml)));
Node root=doc.getDocumentElement();

// Tell XPathAPI that "ns1" is the prefix for namespace "tempuri" :
Element nsResolverNode=doc.createElement("NamespaceResolver");
nsResolverNode.setAttribute("xmlns:ns1", "tempuri");

// This returns "null", instead of the desired < status > element... why ?
Node subNode = XPathAPI.selectSingleNode(root, "ns1:body/ns1:status",
nsResolverNode);

 --- end code -------------------------------------
 

What am i doing wrong ? Do you know of a better way to do it ?

 Thanks very much.

   
---------------------------------
Brings words and photos together (easily) with
PhotoMail  - it's free and works with Yahoo! Mail.
<div><FONT face=Verdana>I'm having a problem with XPATH and namespaces.<BR
>Could anyone please help ?<BR><BR>I'm using apache XPathAPI, with java 1.4.<BR
>It works fine as long as there are no namespaces.<BR>Unfortunately, when adding
namespaces to the xml, XPathAPI fails to find the desired element (returning
null).</FONT></div>  <div><FONT face=Verdana></FONT>&nbsp;</div>  <div><FONT
face=Verdana>--- code ----------------------------------------</FONT></div>  
<div><FONT size=2>String xml=<BR>&nbsp;&nbsp;&nbsp;&nbsp; "&lt; ns1:body xmlns
:ns1='tempuri' &gt;" +</FONT></div>  <div><FONT size=2>&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "&lt; ns1:status &gt; OK &lt; / ns1:status &gt;"
+<BR>&nbsp;&nbsp;&nbsp;&nbsp; "&lt; / ns1:body &gt;";<BR></FONT></div>  <div>
<FONT size=2>// Parse the above xml string:<BR>DocumentBuilder docBuilder=
DocumentBuilderFactory.newInstanc().newDocumentBuilder();<BR>Document doc
=docBuilder.parse(new InputSource(new StringReader(xml)));<BR>N
ode
root=doc.getDocumentElement();<BR> <BR>// Tell XPathAPI that "ns1" is the
prefix for&nbsp;namespace "tempuri" :<BR>Element nsResolverNode=doc
.createElement("NamespaceResolver");<BR>nsResolverNode.setAttribute("xmlns:ns1",
"tempuri");<BR> <BR>// This returns "null", instead of the desired &lt; status
&gt; element... why ?<BR>Node subNode = XPathAPI.selectSingleNode(root, "ns1
:body/ns1:status", nsResolverNode);<BR>&nbsp;</FONT></div>  <div><FONT face
=Verdana>--- end code -------------------------------------</FONT></div>  <div>
<BR><BR>What am i doing wrong ? Do you know of a better way to do it ?<BR></div>
 <div>Thanks very much.</div><p>
    <hr size=1>Brings words and photos together (easily) with<br>
<a href="http://us.rd.yahoo.com/mail_us/taglines/PMall/*http://photomail.mail
.yahoo.com">PhotoMail </a> - it's free and works with Yahoo! Mail.