xom-interest AT lists.ibiblio.org
Subject: XOM API for Processing XML with Java
List archive
- From: Michael Kay <mike AT saxonica.com>
- To: XOM API for Processing XML with Java <xom-interest AT lists.ibiblio.org>
- Subject: Re: [XOM-interest] Lexical information?
- Date: Tue, 31 May 2016 22:52:38 +0100
The Locator information supplied by mainstream XMLReader implementations is
pretty reliable. Of course, you sometimes encounter a "homebrew"
implementation of XMLReader (typically an XMLFilter) that doesn't follow the
specs.
The location information in a SAX parsing exception is only useful, of
course, when parsing fails. When you're doing semantic (application-level)
validation, this isn't the case.
Of course, a naive implementation of node.getLineNumber() etc would add
significantly to the memory occupancy of node objects. Saxon's approach is
that (a) when building the tree, you have to ask for location information to
be retained (setLineNumbering(true)), and (b) the location information is
then held in a separate data structure which only exists when this option is
requested.
Michael Kay
Saxonica
> On 31 May 2016, at 22:41, Elliotte Rusty Harold <elharo AT ibiblio.org> wrote:
>
> If the SAX parser reports that, XOM will pass it along in the
> ParsingException and I think, in the exception message.
>
> Beyond that, I suppose I could use Locators if the SAX parser makes them
> available. I haven't checked lately. Are they reliable these days? But I'm
> still not sure it's worth the added API weight.
>
>
> On Tue, May 31, 2016 at 2:05 PM, Michael Kay <mike AT saxonica.com> wrote:
>
>> There is of course no universal definition of what constitutes "lexical"
>> information.
>>
>> However, the use cases for retaining line/column information are perhaps
>> stronger than for the things like CDATA sections and entity references that
>> we often classify under this heading. Almost anything that can be described
>> as "validation" - whether it's XSD-like validation, or semantic validation
>> such as an XSLT processor performs on XSLT input, needs to give the user
>> feedback in terms of line/column locations, and a tree model that preserves
>> line and column information is almost essential for such applications.
>>
>> Michael Kay
>> Saxonica
>>
>>
>>> On 31 May 2016, at 19:31, Elliotte Rusty Harold <elharo AT ibiblio.org>
>> wrote:
>>>
>>> No, Xerces/SAX throws away a lot of lexical information; and XOM throws
>>> away more. General purpose parsers are not adequate for the rare use
>> cases
>>> such as editors that actually need to preserve the lexical information.
>>>
>>> On Tue, May 31, 2016 at 8:04 AM, <nu.xom AT io7m.com> wrote:
>>>
>>>> Hello.
>>>>
>>>> I'm writing a program that accepts a XOM-produced AST and performs
>>>> various operations on it.
>>>>
>>>> There are various properties of the AST that cannot be expressed by a
>>>> RELAX-NG or XSD schema, so there are inevitably errors that need to be
>>>> raised when the AST is invalid in some way. In order to allow those
>>>> errors to be acceptable to users, I need to be able to show them
>>>> line and column numbers indication the locations of the errors.
>>>>
>>>> The problem: XOM appears to discard all lexical information (if any is
>>>> even provided by the underlying parser). Is there any way I can arrange
>>>> for lexical information to be preserved in any way? I'm open to any
>>>> suggestion whatsoever (even populating an IdentityHashMap that maps XOM
>>>> produced nodes to lexical information would be fine).
>>>>
>>>> I would assume that the solution would first involve getting SAX or
>>>> whatever is doing the parsing to supply that information (which it
>>>> presumably does at some point, because many of the exception types have
>>>> line and column information). I would then somehow need to intercept
>>>> that information before XOM consumes it, and then somehow associate the
>>>> produced XOM nodes with the information I intercepted.
>>>>
>>>> M
>>>> _______________________________________________
>>>> XOM-interest mailing list
>>>> XOM-interest AT lists.ibiblio.org
>>>> http://lists.ibiblio.org/mailman/listinfo/xom-interest
>>>>
>>>
>>>
>>>
>>> --
>>> Elliotte Rusty Harold
>>> elharo AT ibiblio.org
>>> _______________________________________________
>>> XOM-interest mailing list
>>> XOM-interest AT lists.ibiblio.org
>>> http://lists.ibiblio.org/mailman/listinfo/xom-interest
>>
>>
>> _______________________________________________
>> XOM-interest mailing list
>> XOM-interest AT lists.ibiblio.org
>> http://lists.ibiblio.org/mailman/listinfo/xom-interest
>>
>
>
>
> --
> Elliotte Rusty Harold
> elharo AT ibiblio.org
> _______________________________________________
> XOM-interest mailing list
> XOM-interest AT lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/xom-interest
-
[XOM-interest] Lexical information?,
nu.xom, 05/31/2016
-
Re: [XOM-interest] Lexical information?,
Elliotte Rusty Harold, 05/31/2016
- Re: [XOM-interest] Lexical information?, nu.xom, 05/31/2016
-
Re: [XOM-interest] Lexical information?,
Michael Kay, 05/31/2016
-
Re: [XOM-interest] Lexical information?,
Elliotte Rusty Harold, 05/31/2016
- Re: [XOM-interest] Lexical information?, Michael Kay, 05/31/2016
-
Re: [XOM-interest] Lexical information?,
Elliotte Rusty Harold, 05/31/2016
-
Re: [XOM-interest] Lexical information?,
Elliotte Rusty Harold, 05/31/2016
Archive powered by MHonArc 2.6.24.