Recent

Author Topic: XML get value from node value  (Read 1602 times)

eldonfsr

  • Hero Member
  • *****
  • Posts: 591
XML get value from node value
« on: July 27, 2020, 12:06:11 am »
Hi just started with xml, i create a file params.xml  but when read no get values on node

  ReadXMLFile(Doc, 'Params.xml');
   RootNode := Doc.GetElementsByTagName('parameters');
   StockNode:= Doc.DocumentElement.FindNode('stockceros');

stocknode dont show me any value is possible to get value directly like that i follow wiki tutorial.

any help is great thanks
Enrique

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: XML get value from node value
« Reply #1 on: July 27, 2020, 12:35:13 am »
1) Is it declared right?
Code: Pascal  [Select][+][-]
  1. RootNode, StockNode: TDOMNode;
  2. Doc: TXMLDocument;

2) How does xml file looks like? Paste it here, please, if it is not too long.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

eldonfsr

  • Hero Member
  • *****
  • Posts: 591
Re: XML get value from node value
« Reply #2 on: July 28, 2020, 04:22:09 pm »
Thanks for replay this the file xml

<?xml version="1.0" encoding="utf-8"?>
<parameters>
  <stockceros Value="N"/>
</parameters>

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: XML get value from node value
« Reply #3 on: July 28, 2020, 05:39:04 pm »
XML file is OK.
This code works:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var RootNode, StockNode: TDOMNode;
  3.     Doc: TXMLDocument;
  4. begin
  5.   if FileExists('Params.xml') then writeln('Yes ');  //only a check, binary is in lib/x86_64-linux/
  6.   ReadXMLFile(Doc, 'Params.xml');
  7.  //  RootNode := Doc.GetElementsByTagName('parameters');
  8.   StockNode:= Doc.DocumentElement.FindNode('stockceros');
  9.   writeln('Value ', StockNode.Attributes[0].NodeValue);
  10.   Doc.Free;
  11. end;

RootNode is not necessary. Output is:
Code: Pascal  [Select][+][-]
  1. Yes
  2. Value N

You can alternatively use
Code: Pascal  [Select][+][-]
  1. StockNode:= Doc.DocumentElement.FirstChild;
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

 

TinyPortal © 2005-2018