Aivars wrote:Maybe it's easier to pass the XML to Webkit and do the processing there?
That's what Im currently doing. But when I saw that there was some XML objects available directly in FastScript, I just had to see how it worked.
Aivars wrote:I inspected the code further and it seems that:
1) Data is not used when saving to XML
2) Text content in nodes is not supported in this version.
It doesn't really make sense having XML objects that can't set/get the node contents. That's one of the most important features of XML.
It's sad that the documentation for FastScript is so limited and the total lack of example code.
Even the forum at
https://www.fast-report.com/ sucks. There's hardly any replies to customer questions.
In the 1.7
FastScript source, "TfsXMLItem" is defined as this (Line 22):
Code: Select all
private
FData: Pointer; { optional item data }
FItems: TList; { subitems }
FName: String; { item name }
FParent: TfsXMLItem; { item parent }
FText: String; { item attributes }
And then (Line 47):
Code: Select all
public
property Count: Integer read GetCount;
property Data: Pointer read FData write FData;
property Items[Index: Integer]: TfsXMLItem read GetItems; default;
property Name: String read FName write FName;
property Parent: TfsXMLItem read FParent write SetParent;
property Prop[Index: String]: String read GetProp write SetProp;
property Text: String read FText write FText;
And in the function ValueToXML (Line 171):
Code: Select all
function ValueToXML(const Value: Variant): String;
begin
case TVarData(Value).VType of
varSmallint, varInteger, varByte:
Result := IntToStr(Value);
varSingle, varDouble, varCurrency:
Result := FloatToStr(Value);
varDate:
Result := DateToStr(Value);
varOleStr, varString, varVariant:
Result := StrToXML(Value);
varBoolean:
if Value = True then Result := '1' else Result := '0';
else
Result := '';
end;
end;
That looks like Data
is used for *
something*.
But I discovered that using "Microsoft.XMLDOM" is
MUCH easier and better documented..
(So Im not going to bother more with TfsXMLItem.)
Example (Reading XML):
Code: Select all
var XMLDom = CreateOleObject("Microsoft.XMLDOM");
XMLDom.ASync = false;
XMLDom.validateOnParse = true;
XMLDom.Load(Script.Path + "test.xml");
if (XMLDom.parseError.errorCode != 0) {
Script.Message("Error loading XML: " + XMLDom.parseError.reason);
return;
}
var nodes = XMLDom.selectNodes("/root/item");
for (var i=0;i<nodes.length;i++) {
var node = nodes.Item[i];
var value = node.Text;
var name = node.getAttribute("name");
if (name == null) name = "*";
Script.Message(_t(value) + " " + name);
}
Content of "test.xml":
Code: Select all
<?xml version="1.0"?><root>
<item>1</item>
<item name="five">5</item>
<item>9</item>
<item>11</item>
</root>