You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Marco Büchler <ma...@studserv.uni-leipzig.de> on 2004/11/19 12:50:53 UTC
[Problem with namespace]
hi,
i've some problems using xml with the default namespace. i use Xalan
2.6.0. this is the problem:
i have an xml-file similar to this:
<?xml version="1.0" encoding="UTF-8"?>
<elem xmlns="uni-leipzig.de"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Version="2001-1"
xsi:schemaLocation="uni-leipzig.de ANY_URL">
<child name="test"/>
<child name="test2"/>
</elem>
now i want to use some xpath expressions like this /elem/child/@name
for this i use an example similar to the ApplyXPathDOM example
delievered by xalan.
objEvaluator = new XPathEvaluatorImpl( objMessage );
objResolver = objEvaluator.createNSResolver( objMessage );
objResult = (XPathResult)objEvaluator.evaluate(strXPath, objMessage,
objResolver, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
all this works fine for xml files like this:
<?xml version="1.0" encoding="UTF-8"?>
<elem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Version="2001-1" xsi:schemaLocation="uni-leipzig.de ANY_URL">
<child name="test"/>
<child name="test2"/>
</elem>
(files where the default namespace is not set). is this namespace set i
get an nullpointer exeception.
does have anyone an idea??
thankz
ciao
marco
Re: [Problem with namespace]
Posted by George Cristian Bina <ge...@sync.ro>.
> The alternative -- which is VERY bad practice -- is to match on node type
> with predicates to test the node's local name, thus bypassing namespace
> sensitivity.
You can also check the namespace, something like
//*[local-name()='test' and namespace-uri()='http://test.com']
will match all test elements from the http://test.com namespace.
Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Joseph Kesselman wrote:
>
>
>
> XPaths are namespace-aware. If you want to reference a node that's in a
> namespace, the XPath must use a prefix bound to that namespace. (XPath 2.0
> is introducing the ability to set a default namespace for an XPath, I
> believe, but Xalan doesn't support that yet.)
>
> The alternative -- which is VERY bad practice -- is to match on node type
> with predicates to test the node's local name, thus bypassing namespace
> sensitivity.
>
> ______________________________________
> Joe Kesselman, IBM Next-Generation Web Technologies: XML, XSL and more.
> "The world changed profoundly and unpredictably the day Tim Berners Lee
> got bitten by a radioactive spider." -- Rafe Culpin, in r.m.filk
Re: [Problem with namespace]
Posted by Joseph Kesselman <ke...@us.ibm.com>.
XPaths are namespace-aware. If you want to reference a node that's in a
namespace, the XPath must use a prefix bound to that namespace. (XPath 2.0
is introducing the ability to set a default namespace for an XPath, I
believe, but Xalan doesn't support that yet.)
The alternative -- which is VERY bad practice -- is to match on node type
with predicates to test the node's local name, thus bypassing namespace
sensitivity.
______________________________________
Joe Kesselman, IBM Next-Generation Web Technologies: XML, XSL and more.
"The world changed profoundly and unpredictably the day Tim Berners Lee
got bitten by a radioactive spider." -- Rafe Culpin, in r.m.filk