Title: RE: Extracting information from XML files

I am currently facing the problem of default namespaces with xpath _expression_.
I read the link that you provided on how to deal with this. According to this,
the XPath _expression_ must include a namespace prefix that you have mapped with
a xmlns declaration. I tried that in my experiment and got the following result.


This simple xml document.

the xpath _expression_ needs to have the prefix
<ShortZipCodeResponse xmlns="http://webservices.eraserver.net/">
        <ShortZipCodeResult>78681</ShortZipCodeResult>
</ShortZipCodeResponse>

The xpath _expression_ is
/ShortZipCodeResponse/ShortZipCodeResult
As expected it does not return any node.

When I change the namespace from default namespace to one with prefix, then the
xpath _expression_ "/ShortZipCodeResponse/ShortZipCodeResult" works fine.
<ShortZipCodeResponse xmlns:foo="http://webservices.eraserver.net/">
        <ShortZipCodeResult>78681</ShortZipCodeResult>
</ShortZipCodeResponse>

But if I change the xpath _expression_ in the second case to
"/foo:ShortZipCodeResponse/foo:ShortZipCodeResult"
it again does not seem to work.

How do I go about solving this problem?
When I generate the XPath _expression_, I do not have the namespace prefix information (since the
document is received later in our application), so
how would I qualify the _expression_ with namespace prefix.

Any help will be greatly appreciated.
Thanks

Vikas


-----Original Message-----
From: Joseph Kesselman [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 19, 2002 9:45 AM
To: [EMAIL PROTECTED]
Subject: RE: Extracting information from XML files


On Thursday, 12/19/2002 at 09:10 EST, "Rick Bullotta"
<[EMAIL PROTECTED]> wrote:
> I is simple as long as there  aren't default namespaces in the XML
> document...<g>.  Then it  gets  UGGGLY! ;>

Not horribly ugly -- you just have to remember to map the _namespaces_ in
your XPath, not just to use corresponding prefixes. The same complication
arises if the XML document redeclared a prefix; you need to use separate
prefixes for the two different namespace URIs when writing your XPath.

For an overview of how to deal with this, see
http://xml.apache.org/xalan-j/faq.html#faq-N101B9

(I do wish XPath had a non-prefix-based version of its syntax. It'd be
extremely wordy, but it'd be a lot more robust and easier to generate. I'm
considering proposing that they add that alternative in XPath 2.0...)

______________________________________
Joe Kesselman  / IBM Research


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to