Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Modeling (top-level project) » Get line number in xml file from EObject URI
Get line number in xml file from EObject URI [message #380819] Fri, 13 July 2007 08:52 Go to next message
Marko Tomljenovic is currently offline Marko TomljenovicFriend
Messages: 62
Registered: July 2009
Member
Hello guys,
I need some help regarding the above mentioned problem. I want to create a
multipage editor where the model data of an xml file is represented in a
text editor and another graphical/form based editor. In case of an invalid
input to the model elements I want to use error markers in both editors to
show the error.

The problem now is that I do not know how to calculate the line number of
an EObjects URI (EcoreUtil.getURI(EObject)) assuming I am not dealing with
a proxy.

Please help me, I am searching for a solution for quite a while now.

Greetings Marko
Re: Get line number in xml file from EObject URI [message #380820 is a reply to message #380819] Fri, 13 July 2007 13:17 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33139
Registered: July 2009
Senior Member
Marko,

This is an EMF-specific question best asked on the EMF newsgroup, which
I've added to the "to" list of the reply. More comments below.


Marko T. wrote:
> Hello guys,
> I need some help regarding the above mentioned problem.
I don't see anything above...
> I want to create a multipage editor where the model data of an xml
> file is represented in a text editor and another graphical/form based
> editor.
There were some recent threads discussing this. I suspect the best
approach its to use WTP's structured editing DOM, but I've not
experimented with that yet and there's not even an EMF bugzilla
enhancement request to look into providing a source view in the
generated editor, even though I've suggested several times to folks that
they might want to open one.
> In case of an invalid input to the model elements I want to use error
> markers in both editors to show the error.
Yes, that would be cool.
>
> The problem now is that I do not know how to calculate the line number
> of an EObjects URI (EcoreUtil.getURI(EObject)) assuming I am not
> dealing with a proxy.
There is no way right now to directly compute this since such
information is not stored anywhere. During parsing, the lexical handler
does know source positions, but they aren't recorded. Similarly, during
save, one could determine source positions, but they aren't recorded
there either. The only recording mechanism we have is when you save to
DOM (XMLResource.save(Document,Map,DOMHandler) you can save associations
between the created objects and their originating DOM. You could use
that mechanism to create a structured editing DOM and display that in a
structured text view and thereby be able to associate error markers on
EObject to positions in a source view.
>
> Please help me, I am searching for a solution for quite a while now.
It's really quite a daunting task you face. It would be quite
interesting for EMF to provide a mechanism for building up a map of
EObject to source positions while parsing a SAX stream. Feel free to
open a bugzilla enhancement request for that. I can't promise we'll do
it quickly though, but I've always wanted to be able to generate a
source view for EMF's generated editors, so I'm quite motivated to do
this eventually, time and resource permitting...
>
> Greetings Marko
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Get line number in xml file from EObject URI [message #380822 is a reply to message #380820] Fri, 13 July 2007 14:00 Go to previous messageGo to next message
Peter Nehrer is currently offline Peter NehrerFriend
Messages: 241
Registered: July 2009
Senior Member
Marko, Ed,

I've attempted to do something similar in "Simple Compare for EMF"
(http://www.eclipticalsoftware.com/emf/#compare), because I wanted to be
able to display the text that corresponds to a particular object's
containment tree when double-clicked in the structural comparison viewer
(and for that I need to know the range occupied by the said tree).

Basically the solution does what Ed mentioned -- remembering the current
line/column information provided by SAX's Locator as the document is
parsed. However, this is still just an approximation -- Locator does not
guarantee exact information, by contract. Thus, you'll see that in some
JRE versions the location information is exact, while in others the best
you can do is get the line number (but not column), etc.

For a robust generic solution, you'd need a custom parser that reports
exact location information. You'd also have to work out some XML features,
such as parameterized entity references, x-includes, etc.

The source code is available as part of the SDK at
http://www.eclipticalsoftware.com/updates (haven't had the time to make it
available for browsing).

--Peter
Re: Get line number in xml file from EObject URI [message #380826 is a reply to message #380822] Fri, 13 July 2007 14:18 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33139
Registered: July 2009
Senior Member
Peter,

I believe that by parsing using the SED DOM you could would get exact
locations from that DOM and hence by building a DOM/EObject association
(not sure how to do that yet while parsing from the DOM) you'd have
what's needed. I suppose a related alternative would be ensure that the
lexical handler has the right information somehow from the SED DOM.
Another possibility is to ensure that the SAX handler you use is based
on a specific implementation that has good line numbers. So many issues
to consider, like entities, and now x-include has to be thrown into the
general mix...


Peter Nehrer wrote:
> Marko, Ed,
>
> I've attempted to do something similar in "Simple Compare for EMF"
> (http://www.eclipticalsoftware.com/emf/#compare), because I wanted to
> be able to display the text that corresponds to a particular object's
> containment tree when double-clicked in the structural comparison
> viewer (and for that I need to know the range occupied by the said tree).
>
> Basically the solution does what Ed mentioned -- remembering the
> current line/column information provided by SAX's Locator as the
> document is parsed. However, this is still just an approximation --
> Locator does not guarantee exact information, by contract. Thus,
> you'll see that in some JRE versions the location information is
> exact, while in others the best you can do is get the line number (but
> not column), etc.
>
> For a robust generic solution, you'd need a custom parser that reports
> exact location information. You'd also have to work out some XML
> features, such as parameterized entity references, x-includes, etc.
>
> The source code is available as part of the SDK at
> http://www.eclipticalsoftware.com/updates (haven't had the time to
> make it available for browsing).
>
> --Peter
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Get line number in xml file from EObject URI [message #594215 is a reply to message #380819] Fri, 13 July 2007 13:17 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33139
Registered: July 2009
Senior Member
Marko,

This is an EMF-specific question best asked on the EMF newsgroup, which
I've added to the "to" list of the reply. More comments below.


Marko T. wrote:
> Hello guys,
> I need some help regarding the above mentioned problem.
I don't see anything above...
> I want to create a multipage editor where the model data of an xml
> file is represented in a text editor and another graphical/form based
> editor.
There were some recent threads discussing this. I suspect the best
approach its to use WTP's structured editing DOM, but I've not
experimented with that yet and there's not even an EMF bugzilla
enhancement request to look into providing a source view in the
generated editor, even though I've suggested several times to folks that
they might want to open one.
> In case of an invalid input to the model elements I want to use error
> markers in both editors to show the error.
Yes, that would be cool.
>
> The problem now is that I do not know how to calculate the line number
> of an EObjects URI (EcoreUtil.getURI(EObject)) assuming I am not
> dealing with a proxy.
There is no way right now to directly compute this since such
information is not stored anywhere. During parsing, the lexical handler
does know source positions, but they aren't recorded. Similarly, during
save, one could determine source positions, but they aren't recorded
there either. The only recording mechanism we have is when you save to
DOM (XMLResource.save(Document,Map,DOMHandler) you can save associations
between the created objects and their originating DOM. You could use
that mechanism to create a structured editing DOM and display that in a
structured text view and thereby be able to associate error markers on
EObject to positions in a source view.
>
> Please help me, I am searching for a solution for quite a while now.
It's really quite a daunting task you face. It would be quite
interesting for EMF to provide a mechanism for building up a map of
EObject to source positions while parsing a SAX stream. Feel free to
open a bugzilla enhancement request for that. I can't promise we'll do
it quickly though, but I've always wanted to be able to generate a
source view for EMF's generated editors, so I'm quite motivated to do
this eventually, time and resource permitting...
>
> Greetings Marko
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Get line number in xml file from EObject URI [message #594225 is a reply to message #380820] Fri, 13 July 2007 14:00 Go to previous message
Peter Nehrer is currently offline Peter NehrerFriend
Messages: 241
Registered: July 2009
Senior Member
Marko, Ed,

I've attempted to do something similar in "Simple Compare for EMF"
(http://www.eclipticalsoftware.com/emf/#compare), because I wanted to be
able to display the text that corresponds to a particular object's
containment tree when double-clicked in the structural comparison viewer
(and for that I need to know the range occupied by the said tree).

Basically the solution does what Ed mentioned -- remembering the current
line/column information provided by SAX's Locator as the document is
parsed. However, this is still just an approximation -- Locator does not
guarantee exact information, by contract. Thus, you'll see that in some
JRE versions the location information is exact, while in others the best
you can do is get the line number (but not column), etc.

For a robust generic solution, you'd need a custom parser that reports
exact location information. You'd also have to work out some XML features,
such as parameterized entity references, x-includes, etc.

The source code is available as part of the SDK at
http://www.eclipticalsoftware.com/updates (haven't had the time to make it
available for browsing).

--Peter
Re: Get line number in xml file from EObject URI [message #594235 is a reply to message #380822] Fri, 13 July 2007 14:18 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33139
Registered: July 2009
Senior Member
Peter,

I believe that by parsing using the SED DOM you could would get exact
locations from that DOM and hence by building a DOM/EObject association
(not sure how to do that yet while parsing from the DOM) you'd have
what's needed. I suppose a related alternative would be ensure that the
lexical handler has the right information somehow from the SED DOM.
Another possibility is to ensure that the SAX handler you use is based
on a specific implementation that has good line numbers. So many issues
to consider, like entities, and now x-include has to be thrown into the
general mix...


Peter Nehrer wrote:
> Marko, Ed,
>
> I've attempted to do something similar in "Simple Compare for EMF"
> (http://www.eclipticalsoftware.com/emf/#compare), because I wanted to
> be able to display the text that corresponds to a particular object's
> containment tree when double-clicked in the structural comparison
> viewer (and for that I need to know the range occupied by the said tree).
>
> Basically the solution does what Ed mentioned -- remembering the
> current line/column information provided by SAX's Locator as the
> document is parsed. However, this is still just an approximation --
> Locator does not guarantee exact information, by contract. Thus,
> you'll see that in some JRE versions the location information is
> exact, while in others the best you can do is get the line number (but
> not column), etc.
>
> For a robust generic solution, you'd need a custom parser that reports
> exact location information. You'd also have to work out some XML
> features, such as parameterized entity references, x-includes, etc.
>
> The source code is available as part of the SDK at
> http://www.eclipticalsoftware.com/updates (haven't had the time to
> make it available for browsing).
>
> --Peter
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Get line number in xml file from EObject URI
Next Topic:Generating code with stereotypes
Goto Forum:
  


Current Time: Tue Apr 23 06:33:29 GMT 2024

Powered by FUDForum. Page generated in 0.03658 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top