Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] XML whitespace in text

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Elliotte Rusty Harold <elharo AT metalab.unc.edu>
  • To: Nils_Kilden-Pedersen AT Countrywide.Com, xom-interest AT lists.ibiblio.org
  • Subject: Re: [XOM-interest] XML whitespace in text
  • Date: Tue, 29 Apr 2003 11:43:50 -0400

At 7:44 AM -0700 4/29/03, Nils_Kilden-Pedersen AT Countrywide.Com wrote:
Actually that should have been a reply to Dick H.
Wouldn't a CDATA section solve any formatting issues he's having, since
it's supposed to remain untouched?

No, XOM does not treat CDATA sections any differently after parse. They are treated like any other text. Thus if you tell XOM to add whitespace to indent things, it will add or change white space anywhere it deems fit (which is basically anywhere there is preexisting white space). It will delete white space that is adjacent to tags if it deems fit.

You might reasonably expect an xml:space="preserve" attribute to prevent this, though I won't swear it actually does. (Hmm, should write a unit test for that one.) But the bottom line is that if you tell Serializer to muck with your white space, don't be surprised when it mucks with your white space. :-)
--
Elliotte Rusty Harold
elharo AT metalab.unc.edu
Processing XML with Java (Addison-Wesley, 2002)
http://www.cafeconleche.org/books/xmljava
http://www.amazon.com/exec/obidos/ISBN%3D0201771861/cafeaulaitA
From elharo AT metalab.unc.edu Tue Apr 29 11:48:56 2003
Return-Path: <elharo AT metalab.unc.edu>
Delivered-To: xom-interest AT lists.ibiblio.org
Received: from mail.speakeasy.net (mail11.speakeasy.net [216.254.0.211])
by happyhouse.metalab.unc.edu (Postfix) with ESMTP id 42CD3200B7
for <XOM-interest AT lists.ibiblio.org>;
Tue, 29 Apr 2003 11:48:49 -0400 (EDT)
Received: (qmail 11957 invoked from network); 29 Apr 2003 15:48:49 -0000
Received: from unknown (HELO [192.168.254.4]) ([216.254.85.72])
(envelope-sender <elharo AT metalab.unc.edu>)
by mail11.speakeasy.net (qmail-ldap-1.03) with SMTP
for <laurent.bihanic AT atosorigin.com>; 29 Apr 2003 15:48:49 -0000
Mime-Version: 1.0
X-Sender: elharo AT mail.ibiblio.org
Message-Id: <p04330104bad44ea2a01d@[192.168.254.4]>
In-Reply-To: <3EAE998B.6060004 AT atosorigin.com>
References: <3E3941C4.1070904 AT atosorigin.com>
<p04330115bab66208745f@[192.168.254.4]> <3E9E94BA.2010501 AT atosorigin.com>
<3EAE998B.6060004 AT atosorigin.com>
Date: Tue, 29 Apr 2003 11:47:36 -0400
To: Laurent Bihanic <laurent.bihanic AT atosorigin.com>
From: Elliotte Rusty Harold <elharo AT metalab.unc.edu>
Subject: Re: [XOM-interest] XPath support for XOM
Content-Type: text/plain; charset="us-ascii" ; format="flowed"
cc: XOM-interest <XOM-interest AT lists.ibiblio.org>
X-BeenThere: xom-interest AT lists.ibiblio.org
X-Mailman-Version: 2.1.1
Precedence: list
List-Id: <xom-interest.lists.ibiblio.org>
List-Unsubscribe: <http://lists.ibiblio.org/mailman/listinfo/xom-interest>,
<mailto:xom-interest-request AT lists.ibiblio.org?subject=unsubscribe>
List-Archive: <https://lists.ibiblio.org/sympa/arc/xom-interest>
List-Post: <mailto:xom-interest AT lists.ibiblio.org>
List-Help: <mailto:sympa AT lists.ibiblio.org?subject=HELP>
List-Subscribe: <http://lists.ibiblio.org/mailman/listinfo/xom-interest>,
<mailto:xom-interest-request AT lists.ibiblio.org?subject=subscribe>
X-List-Received-Date: Tue, 29 Apr 2003 15:48:56 -0000

At 5:26 PM +0200 4/29/03, Laurent Bihanic wrote:
Hi,

One more remark: With a single method it will be quite difficult to deal with namespaces, especially default namespaces since XPath has no concept of default namespace.

You'll be searching from a context node, and my initial thoughts were that the namespaces in scope on the context node would be used for the prefix mapping; but you're right. That may not be enough, especially for the default namespace. Possibly I could use a dummy element as an optional holder of all necessary namespace bindings. I'll need to think about this further.
--
Elliotte Rusty Harold
elharo AT metalab.unc.edu
Processing XML with Java (Addison-Wesley, 2002)
http://www.cafeconleche.org/books/xmljava
http://www.amazon.com/exec/obidos/ISBN%3D0201771861/cafeaulaitA
From bill AT dehora.net Wed Apr 30 19:39:06 2003
Return-Path: <bill AT dehora.net>
Delivered-To: xom-interest AT lists.ibiblio.org
Received: from mail02.svc.cra.dublin.eircom.net
(mail02.svc.cra.dublin.eircom.net [159.134.118.18])
by happyhouse.metalab.unc.edu (Postfix) with SMTP id E214D200FB
for <XOM-interest AT lists.ibiblio.org>;
Wed, 30 Apr 2003 19:39:05 -0400 (EDT)
Received: (qmail 3348 messnum 334567 invoked from
network[194.125.184.102/p184-102.as1.snd.dublin.eircom.net]); 30 Apr
2003
23:39:04 -0000
Received: from p184-102.as1.snd.dublin.eircom.net (HELO dehora.net)
(194.125.184.102)
by mail02.svc.cra.dublin.eircom.net (qp 3348) with SMTP;
30 Apr 2003 23:39:04 -0000
Message-ID: <3EB05E28.4000602 AT dehora.net>
Date: Thu, 01 May 2003 00:37:12 +0100
From: =?ISO-8859-1?Q?Bill_de_h=D3ra?= <bill AT dehora.net>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US;
rv:1.3) Gecko/20030312
X-Accept-Language: en-ie, en, en-us
MIME-Version: 1.0
To: Elliotte Rusty Harold <elharo AT metalab.unc.edu>
Subject: Re: [XOM-interest] XPath support for XOM
References: <3E3941C4.1070904 AT atosorigin.com>
<p04330115bab66208745f@[192.168.254.4]>
<3E9E94BA.2010501 AT atosorigin.com>
<3EAE998B.6060004 AT atosorigin.com>
<p04330104bad44ea2a01d@[192.168.254.4]>
In-Reply-To: <p04330104bad44ea2a01d@[192.168.254.4]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
cc: Laurent Bihanic <laurent.bihanic AT atosorigin.com>
cc: XOM-interest <XOM-interest AT lists.ibiblio.org>
X-BeenThere: xom-interest AT lists.ibiblio.org
X-Mailman-Version: 2.1.1
Precedence: list
List-Id: <xom-interest.lists.ibiblio.org>
List-Unsubscribe: <http://lists.ibiblio.org/mailman/listinfo/xom-interest>,
<mailto:xom-interest-request AT lists.ibiblio.org?subject=unsubscribe>
List-Archive: <https://lists.ibiblio.org/sympa/arc/xom-interest>
List-Post: <mailto:xom-interest AT lists.ibiblio.org>
List-Help: <mailto:sympa AT lists.ibiblio.org?subject=HELP>
List-Subscribe: <http://lists.ibiblio.org/mailman/listinfo/xom-interest>,
<mailto:xom-interest-request AT lists.ibiblio.org?subject=subscribe>
X-List-Received-Date: Wed, 30 Apr 2003 23:39:06 -0000

Elliotte Rusty Harold wrote:
At 5:26 PM +0200 4/29/03, Laurent Bihanic wrote:

Hi,

One more remark: With a single method it will be quite difficult to deal with namespaces, especially default namespaces since XPath has no concept of default namespace.


You'll be searching from a context node, and my initial thoughts were that the namespaces in scope on the context node would be used for the prefix mapping; but you're right. That may not be enough, especially for the default namespace. Possibly I could use a dummy element as an optional holder of all necessary namespace bindings. I'll need to think about this further.

I've been using this signature lately:


NodeList match(Document doc, String xpath, Map namespaces);


the Map has URIs as keys and prefixes (containing 'xmlns:', that allows me to specify a default) as values. I did this specifically to hide the creating of documents as namespace holders and generally to avoid polluting my code with the consequences of dealing with XPaths that are no longer self contained things but instead need to refer to URIs via prefixes.


From that signature I can quickly build out an interface like this:

public interface Op
{

boolean copy(Document, String xpathFrom, String xpathTo, Map namespaces);

boolean remove(Document, String xpathTo, Map namespaces);

boolean move(Document, String xpathFrom, String xpathTo, Map namespaces);

boolean touch(Document, String xpathAt, String qName, Map attributes, Map namespaces, boolean overwrite);

boolean touch(Document, String xpathElem, Map attributes, Map namespaces, boolean overwrite);

}

which covers most of what I need to do with an XML document.



Bill de hÓra




Archive powered by MHonArc 2.6.24.

Top of Page