[SOLVED] Problem with XML export
lazarus / 21-General
----------------------------------------------------------------------
xinyiman · 2022-09-02 06:39
Hi all, I have to get this result on an xml file
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
139.9 1
0
139.8 0
1
but I get this
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
<![CDATA[art1]]></
<![CDATA[LIST1]]>
139.9 1
0
<![CDATA[ART2]]></
<![CDATA[LIST2]]>
139.8 0
1
and my code is as follows
What am I doing wrong?
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i var xdoc:
TXMLDocument; // variable to
document RootNode, parentNode, parentNode2, sku, pricelistName,
price, isSellable, isSearchable: TDOMNode;begin //create a document
xdoc := TXMLDocument.create; //create a root node RootNode :=
xdoc.CreateElement('prices'); Xdoc.Appendchild(RootNode);
// save root node //create a parent node RootNode:=
xdoc.DocumentElement; parentNode := xdoc.CreateElement('price');
RootNode.Appendchild(parentNode); parentNode :=
xdoc.CreateElement('sku'); // create a child node sku
:= xdoc.CreateTextNode(''); // insert a
value to node parentNode.Appendchild(sku); //
save node RootNode.ChildNodes.Item[0].AppendChild(parentNode);
// insert child node in respective parent node //create a child
node parentNode := xdoc.CreateElement('pricelistName');
pricelistName := xdoc.CreateTextNode('');
parentNode.Appendchild(pricelistName);
RootNode.ChildNodes.Item[0].AppendChild(parentNode); //create a
child node parentNode := xdoc.CreateElement('price'); price :=
xdoc.CreateTextNode('139.9'); parentNode.Appendchild(price);
RootNode.ChildNodes.Item[0].AppendChild(parentNode); //create a
child node parentNode := xdoc.CreateElement('isSellable');
isSellable := xdoc.CreateTextNode('1');
parentNode.Appendchild(isSellable);
RootNode.ChildNodes.Item[0].AppendChild(parentNode); //create a
child node parentNode := xdoc.CreateElement('isSearchable');
isSearchable := xdoc.CreateTextNode('0');
parentNode.Appendchild(isSearchable);
RootNode.ChildNodes.Item[0].AppendChild(parentNode); //create a
parent node RootNode:= xdoc.DocumentElement; parentNode2 :=
xdoc.CreateElement('price'); RootNode.Appendchild(parentNode2);
parentNode2 := xdoc.CreateElement('sku'); // create a
child node sku := xdoc.CreateTextNode('');
// insert a value to node parentNode2.Appendchild(sku);
// save node
RootNode.ChildNodes.Item[0].AppendChild(parentNode2); // insert
child node in respective parent node //create a child node
parentNode2 := xdoc.CreateElement('pricelistName'); pricelistName :=
xdoc.CreateTextNode('');
parentNode2.Appendchild(pricelistName);
RootNode.ChildNodes.Item[0].AppendChild(parentNode2); //create a
child node parentNode2 := xdoc.CreateElement('price'); price :=
xdoc.CreateTextNode('139.8'); parentNode2.Appendchild(price);
RootNode.ChildNodes.Item[0].AppendChild(parentNode2); //create a
child node parentNode2 := xdoc.CreateElement('isSellable');
isSellable := xdoc.CreateTextNode('0');
parentNode2.Appendchild(isSellable);
RootNode.ChildNodes.Item[0].AppendChild(parentNode2); //create a
child node parentNode2 := xdoc.CreateElement('isSearchable');
isSearchable := xdoc.CreateTextNode('1');
parentNode2.Appendchild(isSearchable);
RootNode.ChildNodes.Item[0].AppendChild(parentNode2);
writeXMLFile(xDoc, nome_file); // write to XML
Xdoc.free;
Thanks
----------------------------------------------------------------------
paweld · 2022-09-02 08:43
you must use CreateCDATASectionCode: Pascal
[Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i procedure
TForm1.Button1Click(Sender: TObject);var xdoc: TXMLDocument;
// variable to document RootNode,
parentNode, parentNode2, sku, pricelistName, price, isSellable,
isSearchable: TDOMNode; ms: TMemoryStream; begin //create a
document xdoc := TXMLDocument.create; //create a root node
RootNode := xdoc.CreateElement('prices');
Xdoc.Appendchild(RootNode); // save root
node //create a parent node RootNode:= xdoc.DocumentElement;
parentNode := xdoc.CreateElement('price');
RootNode.Appendchild(parentNode); parentNode :=
xdoc.CreateElement('sku'); // create a child node sku
:= xdoc.CreateCDATASection('art'); // insert a value to node -
CDATA parentNode.Appendchild(sku); // save
node RootNode.ChildNodes.Item[0].AppendChild(parentNode); //
insert child node in respective parent node //create a child node
parentNode := xdoc.CreateElement('pricelistName'); pricelistName :=
xdoc.CreateCDATASection('LIST1'); //CDATA
parentNode.Appendchild(pricelistName);
RootNode.ChildNodes.Item[0].AppendChild(parentNode); //create a
child node parentNode := xdoc.CreateElement('price'); price :=
xdoc.CreateTextNode('139.9'); parentNode.Appendchild(price);
RootNode.ChildNodes.Item[0].AppendChild(parentNode); //create a
child node parentNode := xdoc.CreateElement('isSellable');
isSellable := xdoc.CreateTextNode('1');
parentNode.Appendchild(isSellable);
RootNode.ChildNodes.Item[0].AppendChild(parentNode); //create a
child node parentNode := xdoc.CreateElement('isSearchable');
isSearchable := xdoc.CreateTextNode('0');
parentNode.Appendchild(isSearchable);
RootNode.ChildNodes.Item[0].AppendChild(parentNode); //create a
parent node RootNode:= xdoc.DocumentElement; parentNode2 :=
xdoc.CreateElement('price'); RootNode.Appendchild(parentNode2);
parentNode2 := xdoc.CreateElement('sku'); // create a
child node sku := xdoc.CreateCDATASection('ART2'); // insert
a value to node - CDATA parentNode2.Appendchild(sku);
// save node
RootNode.ChildNodes.Item[0].AppendChild(parentNode2); // insert
child node in respective parent node //create a child node
parentNode2 := xdoc.CreateElement('pricelistName'); pricelistName :=
xdoc.CreateCDATASection('LIST2'); //CDATA
parentNode2.Appendchild(pricelistName);
RootNode.ChildNodes.Item[0].AppendChild(parentNode2); //create a
child node parentNode2 := xdoc.CreateElement('price'); price :=
xdoc.CreateTextNode('139.8'); parentNode2.Appendchild(price);
RootNode.ChildNodes.Item[0].AppendChild(parentNode2); //create a
child node parentNode2 := xdoc.CreateElement('isSellable');
isSellable := xdoc.CreateTextNode('0');
parentNode2.Appendchild(isSellable);
RootNode.ChildNodes.Item[0].AppendChild(parentNode2); //create a
child node parentNode2 := xdoc.CreateElement('isSearchable');
isSearchable := xdoc.CreateTextNode('1');
parentNode2.Appendchild(isSearchable);
RootNode.ChildNodes.Item[0].AppendChild(parentNode2); ms :=
TMemoryStream.Create; writeXMLFile(xDoc, ms); //
write to xml stream Xdoc.free; ms.Position := 0;
memo1.Lines.LoadFromStream(ms); ms.Free; end;
----------------------------------------------------------------------
xinyiman · 2022-09-06 06:21
Thank you but my example is this
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
139.9 1
0
138.9 0
1
and result of your code is
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
139.9 1
0
139.8 0
1
It is not correct
----------------------------------------------------------------------
gerardus · 2022-09-06 08:05
He's got the structure mixed up, but this is not relevant.
The solution (CreateCDATASection) he gave you is valid.
----------------------------------------------------------------------
paweld · 2022-09-06 08:54
I may have removed something when making changes to the example code.
Attached is a sample program
----------------------------------------------------------------------
xinyiman · 2022-09-06 12:57
Quote from: paweld on September 06, 2022, 10:54:29 amI may have
removed something when making changes to the example code. Attached is
a sample program
Thank you very much