Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] XOM enforces whitespace for xpath text() expression

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: "Pieper, Aaron" <PieperA AT Pragmatics.com>
  • To: <xom-interest AT lists.ibiblio.org>
  • Subject: [XOM-interest] XOM enforces whitespace for xpath text() expression
  • Date: Mon, 23 May 2011 18:19:58 -0400

Hello,

I am working on some unit tests which use XPath to draw assertions on a
document. I encountered some surprising behavior, when evaluating the
following document.

<endpoint>
<service>getData
<errors/>
</service>
</endpoint>

The XPath expression /endpoint/service[text()='getData'] returns a
single node in some XML frameworks (like Dom4J), but returns zero nodes
in Xom. This is because Xom preserves leading/trailing whitespace. I'm
able to work around this by embedding the NormalizingFactory sample code
into my tests. At first I was frustrated that Xom behaved differently
from other frameworks; but, experimenting a little, this behavior is
consistent with the XSD specification, where leading/trailing whitespace
will invalidate a document in some cases. So, I think Xom is doing the
right thing here.

It might make sense to streamline this NormalizingFactory and package it
with Xom.

- Aaron





Archive powered by MHonArc 2.6.24.

Top of Page