* * *

Author Topic: fcl-xml domstring to string ?  (Read 4523 times)

JC

  • Newbie
  • Posts: 2
fcl-xml domstring to string ?
« on: March 02, 2010, 11:50:35 am »
Hello,

is possible convert PassNode.FirstChild.NodeValue (or PassNode.TextContent) to string ?

Code: [Select]
var
  PassNode: TDOMNode;
  Doc:      TXMLDocument;
 begin
  // Read in xml file from disk
  ReadXMLFile(Doc, 'c:\xmlfiles\test.xml');
  // Retrieve the "password" node
  PassNode := Doc.DocumentElement.FindNode('password');
  // Write out value of the selected node
  WriteLn(PassNode.NodeValue); // will be blank
  // The text of the node is actually a separate child node
  WriteLn(PassNode.FirstChild.NodeValue); // correctly prints "abc"
  // alternatively
  WriteLn(PassNode.TextContent);
  // finally, free the document
  Doc.Free;
end;

from http://wiki.freepascal.org/XML_Tutorial

Thanks


marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2776
Re: fcl-xml domstring to string ?
« Reply #1 on: March 02, 2010, 02:58:52 pm »
Convert how what where? If you try the above code, what goes wrong? :o

JC

  • Newbie
  • Posts: 2
Re: fcl-xml domstring to string ?
« Reply #2 on: March 02, 2010, 03:30:31 pm »
ah.. problem is here:

 var
  PassNode: TDOMNode;
  Doc:      TXMLDocument;
   s: string;

begin
     ReadXMLFile(Doc, 'test.xml');
     PassNode := Doc.DocumentElement.FindNode('name');
     s := PassNode.FirstChild.NodeValue;
     ..
     Doc.Free;
 end;


No problems with compiling but in program it make "access violation" error.

eny

  • Hero Member
  • *****
  • Posts: 1151
Re: fcl-xml domstring to string ?
« Reply #3 on: March 02, 2010, 03:33:24 pm »
You must check if PassNode.FirstChild is assigned:

Code: [Select]
if assigned(PassNode.FirstChild) then
  s := PassNode.FirstChild.NodeValue;
Win8 Prof (Win64); Lazarus 1.2.2 (#44758; win32 and win64)

LuizAmérico

  • Sr. Member
  • ****
  • Posts: 346
Re: fcl-xml domstring to string ?
« Reply #4 on: March 02, 2010, 05:11:40 pm »
Also, if you are working with UTF8 strings will be necessary to do the proper conversion:

s := UTF8Encode(PassNode.FirstChild.NodeValue);

delphi887

  • New member
  • *
  • Posts: 30
    • my personal website
Re: fcl-xml domstring to string ?
« Reply #5 on: August 28, 2012, 12:17:10 pm »
ah.. problem is here:

 var
  PassNode: TDOMNode;
  Doc:      TXMLDocument;
  s: string;

begin
     ReadXMLFile(Doc, 'test.xml');
     PassNode := Doc.DocumentElement.FindNode('name');
     s := PassNode.FirstChild.NodeValue;
     ..
     Doc.Free;
 end;


No problems with compiling but in program it make "access violation" error.
hi
I'm having the same problem and I did not find a solution
Please help me
Thanks

eny

  • Hero Member
  • *****
  • Posts: 1151
Re: fcl-xml domstring to string ?
« Reply #6 on: August 28, 2012, 08:24:50 pm »
hi
I'm having the same problem and I did not find a solution
Please help me
Thanks
What?
If you kick a 2.5 year old topic, then at least please read what was posted here.
Or open a new topic where you explain what the problem is you are experiencing.
Win8 Prof (Win64); Lazarus 1.2.2 (#44758; win32 and win64)

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads