Home » Language IDEs » ServerTools (WTP) » Line number for a node in XML?
Line number for a node in XML? [message #190350] |
Thu, 22 March 2007 18:54  |
Eclipse User |
|
|
|
Is there an available way to simply get a line number for a given Node in
a document? I've searched and searched, but I can't seem to find anything.
This is an xml document in a file in a project. I have a Document and
Node. Is there anything else I might need?
- Paul
|
|
| | | | | | |
Re: Line number for a node in XML? [message #190491 is a reply to message #190485] |
Mon, 26 March 2007 15:54   |
Eclipse User |
|
|
|
Nitin Dahyabhai wrote:
>>> Ah yes! That's exactly what I need. Second question: what's the best
>>> way to get an IDocument for an XML file?
> If it's a SSE IDOMNode, you can ask it for its "structured document"
> as that's the corresponding IDocument.
Thanks a ton! That was a lot simpler than I was making it, apparently.
Looks like I was lost in the maze of interfaces.
So given an IDOMNode, all you really need to do is:
int lineNumber =
node.getStructuredDocument().getLineOfOffset(node.getStartOf fset());
Will test this and post results.
>> I should add that we are a) basing this off a possibly changing XML
>> file, and b) we don't want to add "UI" dependencies. (that is, this is
>> used during validation and should be usable in a headless environment,
>> if needed)
> Headless access to the models can be had using the model manager
> instance returned from
> org.eclipse.wst.sse.core.StructuredModelManager.getModelMana ger().
> You'll want to use a getModelForEdit if you plan to save the
> changes, and be sure to release the model when you're done with it.
If done headlessly, we won't be making changes to the documents. It would
be purely a way to report validation errors as part of a build process. I
just wanted to make sure I could find a way to access line numbers without
resorting to "visible" (e.g. widgets and editors) UI code. (I also
believe that the translator framework does the model reading and writing
part, so if they can work headlessly, so can we.)
Thanks again!
- Paul
|
|
| | | | |
Re: Line number for a node in XML? [message #190609 is a reply to message #190601] |
Wed, 28 March 2007 15:17   |
Eclipse User |
|
|
|
David Kerber wrote:
> paul.fullbright@oracle.com says...
>> Nitin Dahyabhai wrote:
>>
>> > It's simply that programmers and code like to start counting by
>> > using "zero", but people count starting with "one".
>>
>> I did think of that, but when you say something like "line number", I'd
>> think it would match up with the *actual* line number. There's no line 0,
>> at least in eclipse.
> But in java, the first character position in a string is number 0, so
> it's consistent with java standards.
True, but when you have line numbers turned on in your editor, and you
have an error on line X, and the error's location is "line X-1", I'd think
those standards aren't the ones to be applying.
|
|
|
Re: Line number for a node in XML? [message #190617 is a reply to message #190609] |
Wed, 28 March 2007 15:38   |
Eclipse User |
|
|
|
Originally posted by: merks.ca.ibm.com
Paul,
I ran into this type of issue long ago as well. But clearly it can't be
changed anymore, so whatever the reason, good or bad, it's just that way
now...
Paul Fullbright wrote:
> David Kerber wrote:
>
>> paul.fullbright@oracle.com says...
>>> Nitin Dahyabhai wrote:
>>>
>>> > It's simply that programmers and code like to start counting by >
>>> using "zero", but people count starting with "one".
>>>
>>> I did think of that, but when you say something like "line number",
>>> I'd think it would match up with the *actual* line number. There's
>>> no line 0, at least in eclipse.
>
>> But in java, the first character position in a string is number 0, so
>> it's consistent with java standards.
>
> True, but when you have line numbers turned on in your editor, and you
> have an error on line X, and the error's location is "line X-1", I'd
> think those standards aren't the ones to be applying.
>
|
|
| | |
Goto Forum:
Current Time: Fri Mar 14 05:43:03 EDT 2025
Powered by FUDForum. Page generated in 0.04685 seconds
|