Lazarus
Programming => General => Topic started by: JC on March 02, 2010, 11:50:35 am
-
Hello,
is possible convert PassNode.FirstChild.NodeValue (or PassNode.TextContent) to string ?
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
-
Convert how what where? If you try the above code, what goes wrong? :o
-
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.
-
You must check if PassNode.FirstChild is assigned:
if assigned(PassNode.FirstChild) then
s := PassNode.FirstChild.NodeValue;
-
Also, if you are working with UTF8 strings will be necessary to do the proper conversion:
s := UTF8Encode(PassNode.FirstChild.NodeValue);
-
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
-
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.