Hi Filip,
Thanks for the replie(s).
I ended up using an XMLFilter and doing roughly what you said above.

Dhanji.

On Tue, Aug 26, 2008 at 1:58 AM, Filip Jirsák <[EMAIL PROTECTED]> wrote:

> Hi Dhanji,
> you can override org.dom4j.DocumentFactory and you can insert yout own
> Locator2 (with setDocumentLocator() method) into
> org.dom4j.io.SAXContentHandler, so you can obtain location information
> from your Locator. Than you can read the location information from
> supplied Locator in DocumentFactory and write down this info at newly
> created node – into some Map, or you can override DefaultElement,
> DefaultAttribute and so on and write location information to your
> overriden instances of these classes.
>
> There is no way how to obtain the location information from DOM4J
> without overriding classes, because DOM representation of XML has no
> relationship with XML in file with lines and columns, so it doesn't
> make sense to store this information somewhere in DOM4J standard
> classes.
>
> Somethink like this:
>
> org.xml.sax.Locator locator = new …;
> DocumentFactory documentFactory = new DocumentFactoryWithLocator(locator);
> SAXContentHandler contentHandler = new SAXContentHandler(documentFactory );
> contentHandler.setDocumentLocator(locator);
>
>
> org.xml.sax.XMLReader reader = …;
>
> reader.setContentHandler(contentHandler );
> reader.parse(…);
>
> Document document = contentHandler.getDocument();
>
> In DocumentFactoryWithLocator you will have methods like this:
>
>  public Element createElement(QName qname) {
>        ElementWithLocation element =  new ElementWithLocation (qname);
>        element.setLocation(locator.getLineNumber(),
> locator.getColumnNumber());
>        return element;
>    }
>
> And so on…
>
>
> Sincerely,
>
> Filip Jirsák
>
> 2008/8/23 Dhanji R. Prasanna <[EMAIL PROTECTED]>:
> > Hi,
> > First, dom4j is great.
> > Second, I am using SAX parsing and would like to obtain document line
> number
> > information associated with dom4j Elements (or Nodes). Is this possible?
> > What's the best way to go about it?
> > I tried searching the list but didnt turn up much. Any help is
> appreciated.
> > Thanks!
> > Dhanji.
> > -------------------------------------------------------------------------
> > This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> > Build the coolest Linux based applications with Moblin SDK & win great
> > prizes
> > Grand prize is a trip for two to an Open Source event anywhere in the
> world
> > http://moblin-contest.org/redirect.php?banner_id=100&url=/
> > _______________________________________________
> > dom4j-user mailing list
> > dom4j-user@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/dom4j-user
> >
> >
>
>
>
> --
> Filip Jirsák
> [EMAIL PROTECTED]
>
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
dom4j-user mailing list
dom4j-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to