Re: Does JSTL XML taglibs ignore XMLNamespace of input document?
I have worked out about this issue and I believe I have got an idea of betterment to the jakarta standard taglibs1.0.x and possibly to the JSTL specification. Here I refrain the initial issue I raised just to remind it. I coded the following JSP page - % taglib uri=/WEB-INF/x.tld prefix=x % x:parse var=NoNSabboon/b/a/x:parse x:parse var=WithNSn:a xmlns:n =someNamespacen:bbaan/n:b/n:a/x:parse $NoNS/a/b=x:out select=$NoNS/a/b/br $WithNS/a/b=x:out select=$WithNS/a/b/br $WithNS/n:a/n:b=x:out select=$WithNS/n:a/n:b/ - The only difference between $NoNS object and $WithNS object is XML Namespace usage. I got the following response from the application. - $NoNS/a/b=boon $WithNS/a/b= $WithNS/n:a/n:b= - I could not get baan output. I looked at the taglibs1.0.2 source code and studied Jaxen. Then I did an experiment (source code change) locally on my PC. I modifed the source code of org.apache.taglibs.standard.tag.common.xml.XPathUtil class slightly as follows: - /** * Returns a String given an XPath expression and a single context * Node. */ public String valueOf(Node n, String xpath) throws SAXPathException { staticInit(); XPath xp = new DOMXPath(xpath); //--- modification by MATSUHASHI,kazuaki-- start // // lookup a Map which should contain pairs of XML Namespace prefix // and URI to be used within XPath expression, then put them into // SimpleNamespaceContext object which will be refered by jaxen engine // // just insert the following statements, that's all Map nsCollection = (Map)pageContext.getAttribute(inputDocumentXmlNamespaces); if (nsCollection != null) { Set prefixes = nsCollection.keySet(); Iterator nsIterator = prefixes.iterator(); while (nsIterator.hasNext()) { String prefix = (String)nsIterator.next(); String nsuri = (String)nsCollection.get(prefix); System.out.println(prefix= + prefix); System.out.println(NSURI = + nsuri); nc.addNamespace(prefix, nsuri); } } //--- modification by MATSUHASHI,kazuaki--- end // return xp.valueOf(getLocalContext(n)); return xp.stringValueOf(getLocalContext(n)); } - The JSP to test the new class is as follows - % taglib uri=/WEB-INF/x.tld prefix=x % html body h2An experimental modification of JSTL XPath/h2 h3to enable access XML with SOME Namespaces/h3 pcase1 : input XML using NO Namespace --- possible to obtain boon by jakarta-taglibs standard-1.0.2/p x:parse var=NoNSabboon/b/a/x:parse table border=1 trtdXML/tdtdlt;alt;bboonlt;/blt;/a/td/tr trtdXPath/tdtd$NoNS/a/b/td/tr trtdvalue/td tdx:out select=$NoNS/a/b//td/tr /table brbr pcase2 :input XML using some Namespaces --- impossible to obtain baan by standard-1.0.2, but enabled by code modification/p x:parse var=WithNSn:a xmlns:n =someNamespaceURIn:bbaan/n:b/n:a/x:parse % page import=java.util.HashMap % % HashMap ns = new HashMap(); ns.put(p, someNamespaceURI); pageContext.setAttribute(inputDocumentXmlNamespaces, ns); % table border=1 trtdXML/tdtdlt;n:a xmlns:n=someNamespaceURI lt;n:bbaanlt;/n:blt;/n:a/td/tr trtdXPath/tdtd$WithNS/p:a/p:b/td/tr trtdvalue/td tdx:out select=$WithNS/p:a/p:b//td/tr /table /body /html - Then I could get the following display: - An experimental modification of JSTL XPath to enable access XML with SOME Namespaces case1 : input XML using NO Namespace --- possible to obtain boon by jakarta-taglibs standard-1.0.2 XML abboon/b/a XPath $NoNS/a/b value boon case2 :input XML using some Namespaces --- impossible to obtain baan by standard-1.0.2, enabled by code modification XML n:a xmlns:n=someNamespaceURIn:bbaan/n:b/n:a XPath $WithNS/p:a/p:b value baan - The code modification above is meant to inform Jaxen about the Namespace prefixes and URIs to be used within the XPath expression. The URI string is significant which should match with the URI string used in the input XML document, but the prefix is not really significant --- the prefix characters in the XPath does not have to be the same as the prefix characters used in the XML. The modification was enough to deal with (though just to print the text()
Re: Does JSTL XML taglibs ignore XMLNamespace of input document?
On Fri, 18 Oct 2002 [EMAIL PROTECTED] wrote: I have worked out about this issue and I believe I have got an idea of betterment to the jakarta standard taglibs1.0.x and possibly to the JSTL specification. Here I refrain the initial issue I raised just to remind it. I coded the following JSP page Sorry, I saw this the first time around, but it slipped through my mailbox because I was away at a conference. The issue isn't JSTL's, at least not directly. You're just not using XPath correctly. Consider your example: - %@ taglib uri=/WEB-INF/x.tld prefix=x % x:parse var=NoNSabboon/b/a/x:parse x:parse var=WithNSn:a xmlns:n =someNamespacen:bbaan/n:b/n:a/x:parse $NoNS/a/b=x:out select=$NoNS/a/b/br $WithNS/a/b=x:out select=$WithNS/a/b/br $WithNS/n:a/n:b=x:out select=$WithNS/n:a/n:b/ Here, both documents are parsed correctly and available for your use. However, the XPath expressions that you're using against the document that uses namespaces are incorrect. In XPath, n:a is not a valid step; it does not refer, as you seem to be expecting, to the node named 'a' in the namespace identified by prefix 'n'. If you want to refer to this node, you'll probably want to use the name() and namespace-uri() functions in XPath. See the XPath standard or chapter 8 of JSTL in Action. -- Shawn Bayern JSTL in Action http://www.jstlbook.com -- To unsubscribe, e-mail: mailto:taglibs-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:taglibs-user-help;jakarta.apache.org
Re: Does JSTL XML taglibs ignore XMLNamespace of input document?
Shawn Bayern wrote : In XPath, n:a is not a valid step; it does not refer, as you seem to be expecting, to the node named 'a' in the namespace identified by prefix 'n'. If you want to refer to this node, you'll probably want to use the name() and namespace-uri() functions in XPath. Yes, I fully understand what you say, but ... what I want is shortness of the JSP code. Consider the following example XML: a fairy long string of NamespaceURIs - SOAP-ENV:Envelope xmlns:SOAP-ENV =http://schemas.xmlsoap.org/soap/envelope/; SOAP-ENV:encodingStyle =http://schemas.xmlsoap.org/soap/encoding/; SOAP-ENV:Header t:Transaction xmlns:t=http://baseball.azb.co.jp/Apache/; SOAP-ENV:mustUnderstand=1 5 /t:Transaction /SOAP-ENV:Header SOAP-ENV:Body m:getPitchingResult xmlns:m =http://baseball.azb.co.jp/Apache/DataStore/; m:nameAkinobu Yoshida/m:name m:No00/m:No /m:getPitchingResult /SOAP-ENV:Body /SOAP-ENV:Envelope - Then if I want to obtain the string value of m:name element, the JSP with legal XPath would look like (I think) - x:out select=$foo/Envelope[namespace-uri() ='http://schemas.xmlsoap.org/soap/envelope']/Body[namespace-uri() ='http://schemas.xmlsoap.org/soap/envelope']/getPitchingResult[namespace-uri )='http://baseball.azb.co.jp/Apache/DataStore/']/name[namespace-uri() ='http://baseball.azb.co.jp/Apache/DataStore/']/ - This one line of code is too long! Don't you think so? How can I make this shorter? I believe that one of the greate benefits of the custom-tag technology is that it makes the JSP code shorter, easy to read. The way I suggested may not be seen orthodx. It is really a way of convenience. However I would like to point out why Namespaces in XML specification introduced namespace prefix itself? Isn't it a way of convenience to make XML documents withNamespaces shorter, easy to read? See the XPath standard or chapter 8 of JSTL in Action. Yes, definitely. I ordered it to amazon.com and waiting for I appreciate your comment very much. Kazuaki Matsuhashi QUICK Corp, Japan -- To unsubscribe, e-mail: mailto:taglibs-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:taglibs-user-help;jakarta.apache.org
Re: Does JSTL XML taglibs ignore XMLNamespace of input document?
additive: - x:out select=$foo/Envelope[namespace-uri() ='http://schemas.xmlsoap.org/soap/envelope']/Body[namespace-uri() ='http://schemas.xmlsoap.org/soap/envelope']/getPitchingResult[namespace-uri )='http://baseball.azb.co.jp/Apache/DataStore/']/name[namespace-uri() ='http://baseball.azb.co.jp/Apache/DataStore/']/ - This long line could be shorten by the way I suggested as follows : - c:set target=ns property=s value= http://schemas.xmlsoap.org/soap/envelope/ c:set target=ns property=t value= http://baseball.azb.co.jp/Apache/DataStore// x:out select=$foo/s:Envelpe/s:Body/t:getPitchingResult/t:name namespaces =${ns}/ - Kazuaki Matsuhashi QUICK Corp, Japan -- To unsubscribe, e-mail: mailto:taglibs-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:taglibs-user-help;jakarta.apache.org
Re: Does JSTL XML taglibs ignore XMLNamespace of input document?
On Fri, 18 Oct 2002 [EMAIL PROTECTED] wrote: This long line could be shorten by the way I suggested as follows : - c:set target=ns property=s value= http://schemas.xmlsoap.org/soap/envelope/ c:set target=ns property=t value= http://baseball.azb.co.jp/Apache/DataStore// x:out select=$foo/s:Envelpe/s:Body/t:getPitchingResult/t:name namespaces =${ns}/ - Indeed, this is one thing the standard could add in the future. It could also use a more specific syntax, along the lines of x:registerNamespace prefix=... uri=... scope=... / -- Shawn Bayern JSTL in Action http://www.jstlbook.com -- To unsubscribe, e-mail: mailto:taglibs-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:taglibs-user-help;jakarta.apache.org
Does JSTL XML taglibs ignore XMLNamespace of input document?
Hi, I just started learning JSTL, am especially interested in XML-related taglibs. I use jakarta-taglibs/standard-1.0.1 on tomcat4.1.3. I coded the following JSP page - %@ taglib uri=/WEB-INF/x.tld prefix=x % x:parse var=NoNSabboon/b/a/x:parse x:parse var=WithNSn:a xmlns:n =someNamespacen:bbaan/n:b/n:a/x:parse $NoNS/a/b=x:out select=$NoNS/a/b/br $WithNS/a/b=x:out select=$WithNS/a/b/br $WithNS/n:a/n:b=x:out select=$WithNS/n:a/n:b/ - The only difference between $NoNS object and $WithNS object is XML Namespace usage. I got the following response from the application. - $NoNS/a/b=boon $WithNS/a/b= $WithNS/n:a/n:b= - I can not get baan output. I do not see how the XPath expression should be written for $WithNS object using JSTL taglib I read JSTL specification document and as many resources on the web as I could find, and I have a feel that the JSTL specification is not explicit enough how to deal with XML namespace used in the input source. Am I wrong? If I am wrong and the told how to solve this, I would be very much pleased. -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]