I know, it seems I'm having a conversation with myself.

After much struggling and investigation, I've determined that what I
need to do is remove the default namespace from a Document.  That is,
the namespace without a prefix.  I need to do this because I am not in
control of the XPath statement that will be used to query the document,
so I can't create my own prefix in the code for the query.  For
instance, given the following document:

<?xml version="1.0" encoding="UTF-8"?>
<Pip3A4PurchaseOrderRequest
xmlns="http://www.a4networks.com/schemas/opl";>                    
  <fromRole>
  stuff
  </fromRole>
</Pip3A4PurchaseOrderRequest>

... I need this XPAth to work: /Pip3A4PurchaseOrderRequest/fromRole

So my question is: what is the best/easiest way to remove this
namespace???



-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]] On Behalf Of David
Hooker
Sent: Thursday, September 05, 2002 11:31 AM
To: 'DOM4J-user (E-mail)'
Subject: RE: [dom4j-user] selectSingleNode() and namespaces


Ok, I found *some* help in the list archives:
http://www.geocrawler.com/archives/3/8797/2002/3/0/8220162/
It was even an answer to one of my own questions!

>From that post, I think what I should do is create a prefix for the
default namespace and use the prefix in my XPath expression I am passing
to selectSingleNode().  If that's correct, my question now is: what's
the best way to get the default namespace URI from a Document?


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]] On Behalf Of David
Hooker
Sent: Wednesday, September 04, 2002 6:03 PM
To: 'DOM4J-user (E-mail)'
Subject: [dom4j-user] selectSingleNode() and namespaces


Hi-

Two questions:

(1)

Ok, I have about a dozen places througout my system where I call
Document.selectSingleNode("some xpath").  This has been working fine
since the XML I've been processing has no default namespace.

(I'm assuming that "default namespace" is a xmlns="..." attribute in the
root element.)

Now, all of the sudden, I'm getting a document that has a root element
with a xmlns="something" attribute, and all my selectSingleNodes are
returning zilch.

How can I compensate for this... without having to bother with creating
namespace contexts and such... with as little change to my code as
possible?

====

(2)

As a related question, the XML I'm processing is actually the output of
a transform which I read back into a dom4j Document, do some things,
then write to XML using Document.asXML().  It is this call that is
writing the xmlns attribute to the root element.  Why?  Here's the
relevant part of the xslt:

<?xml version="1.0" encoding="UTF-8"?> 
   <xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns="http://www.a4networks.com/schemas/opl";
xmlns:conversions="conversions.uri"
exclude-result-prefixes="conversions"> 
   <xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes"/> 
   <xsl:strip-space elements="*"/> 
   ......
   <xsl:template match="/">                             
       <xsl:element name="Pip3A4PurchaseOrderRequest">  
           <xsl:element name="fromRole">                
   ......

The output looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<Pip3A4PurchaseOrderRequest
xmlns="http://www.a4networks.com/schemas/opl";>                    
  <fromRole>
  ......

[It is this namespace that is causing my problem in question (1) above.
If I take out this xmlns attribute, all my selectSingleNode() calls
work.]

All help appreciated.



-------------------------------------------------------
This sf.net email is sponsored by: OSDN - Tired of that same old
cell phone?  Get a new here for FREE!
https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user



-------------------------------------------------------
This sf.net email is sponsored by: OSDN - Tired of that same old
cell phone?  Get a new here for FREE!
https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user



-------------------------------------------------------
This sf.net email is sponsored by: OSDN - Tired of that same old
cell phone?  Get a new here for FREE!
https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to