Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

XML and Delphi [line number]

tijoentijoen Member Posts: 141
Hi!

Here i am again! xD
now I am using XML and I need to know the line of the node that I am parsing in the moment
i am using IXMLDocument and IXMLNode as described in about.delphi website

here is my code, i couldn't find a way to get the line number
do you guys know if I can do this with the code below or am i going to do in another way?

thanks in advance!!!

[code]
XMLDoc := TXMLDocument.Create(nil);
XMLDoc.FileName := PathToMain;

try
XMLDoc.Active := True;
except
on E : Exception do
begin
MessageDlg('Error while loading the xml file ('+ PathToMain +').'#13'Message: '+E.Message, mtError, [mbOk], 0);
Exit;
end;
end;

if XMLDoc.ChildNodes.First = nil then
begin
raise Exception.Create('XML file is empty.');
Exit;
end;

jNode := XMLDoc.DocumentElement.ChildNodes.First;

while jNode <> nil do
begin
ProcessNode(jNode, Form, False);
jNode := jNode.NextSibling;
end;

XMLDoc.Active := False;

[/code]

Joe

Comments

  • zibadianzibadian Member Posts: 6,349
    : Hi!
    :
    : Here i am again! xD
    : now I am using XML and I need to know the line of the node that I am
    : parsing in the moment
    : i am using IXMLDocument and IXMLNode as described in about.delphi
    : website
    :
    : here is my code, i couldn't find a way to get the line number
    : do you guys know if I can do this with the code below or am i going
    : to do in another way?
    :
    : thanks in advance!!!
    :
    : [code]:
    : XMLDoc := TXMLDocument.Create(nil);
    : XMLDoc.FileName := PathToMain;
    :
    : try
    : XMLDoc.Active := True;
    : except
    : on E : Exception do
    : begin
    : MessageDlg('Error while loading the xml file ('+ PathToMain +').'#13'Message: '+E.Message, mtError, [mbOk], 0);
    : Exit;
    : end;
    : end;
    :
    : if XMLDoc.ChildNodes.First = nil then
    : begin
    : raise Exception.Create('XML file is empty.');
    : Exit;
    : end;
    :
    : jNode := XMLDoc.DocumentElement.ChildNodes.First;
    :
    : while jNode <> nil do
    : begin
    : ProcessNode(jNode, Form, False);
    : jNode := jNode.NextSibling;
    : end;
    :
    : XMLDoc.Active := False;
    :
    : [/code]:
    :
    : Joe

    You cannot get the line-number, becauase the XML parser doesn't keep track of line numbers. You get the XML file as a tree of nodes, and the location of those nodes in the file is irrelevant.
  • tijoentijoen Member Posts: 141
    : You cannot get the line-number, becauase the XML parser doesn't keep
    : track of line numbers. You get the XML file as a tree of nodes, and
    : the location of those nodes in the file is irrelevant.

    I am building a xml, that inside a node, are javascript-like code that I am building to be my own language for customers to use, thats why I need the line number somehow
    because if they mess it up, i can tell them not only why they messed up, but where...
    if its not possible then I will have to create my own parser
    sucks :(
    thanks for the help
Sign In or Register to comment.