SOLVED: Support for XML parsing in plugins

Let us know what you would like to see in the next version of this software

Moderator: kfury77

Forum rules
Please follow these guidelines when posting feature requests. This will help to increase the value of your contribution.

  • Do not create new topics for already requested features. Add your comments to the existing feature request topics instead;
  • Create separate topic for each feature suggestion. Do NOT post a number of non-related feature suggestions in a single topic;
  • Give your topic a meaningful title. Do NOT create topics with meaningless titles, such as "My Suggestion" or "My Problem".

Please note that we DO READ all suggestions, even if a reply is not posted. Thanks!

SOLVED: Support for XML parsing in plugins

Postby pmk65 » Mon Feb 27, 2017 7:49 pm

A lot of 3rd-party tools use XML for storing config data (Even WeBuilder does it :D)
Would it be possible to add "TXMLDocument" object support, so parsing of XML files can be done from within a plugin?
Using a Webkit object doesn't really help, as (AFIK) you can only transfer strings between the Webkit object and WeBuilder. So passing along multiple data is cumbersome.
There are 10 types of people in the world: Those who understand binary and those who don't.
User avatar
pmk65
 
Posts: 353
Joined: Sun Dec 20, 2009 9:58 pm
Location: Copenhagen, Denmark

Re: Feature Request: Support for XML parsing in plugins

Postby pmk65 » Thu Mar 16, 2017 10:43 am

Looks like there IS already some XML support in FastScript, as "TfsXMLDocument" and "TfsXMLItem" objects are available.
Then comes the ever returning question: How to use it?

I tried this:
Code: Select all
   var XMLDoc = new TfsXMLDocument;
   XMLDoc.Create = fmCreate;

   var XMLItem = new TfsXMLItem;
   XMLItem.Create;
   XMLItem.Name = "testname";
   XMLItem.Text = "testtext";

   var root = XMLDoc.Root;
      root.AddItem(XMLItem);

   XMLDoc.SaveToFile(Script.Path + "test.xml");

   delete XMLItem;
   delete XMLDoc;


That resulted in the following XML data saved in "test.xml":
Code: Select all
<?xml version="1.0"?><><testname testtext/></>


Which doesn't make much sense. I expected it to create a "testname" tag with the value "testtext"
There are 10 types of people in the world: Those who understand binary and those who don't.
User avatar
pmk65
 
Posts: 353
Joined: Sun Dec 20, 2009 9:58 pm
Location: Copenhagen, Denmark

Re: Feature Request: Support for XML parsing in plugins

Postby pmk65 » Thu Mar 16, 2017 3:06 pm

I think I got it figured out now, except for setting values. The following code:
Code: Select all
   var XMLDoc = new TfsXMLDocument;
   XMLDoc.Create = fmCreate;
   XMLDoc.Root.Name = "root";
   XMLDoc.Root.Text = "attrib=\"rootvalue\"";

   var XMLItem1 = XMLDoc.Root.Add();
   XMLItem1.Name = "first";
   XMLItem1.Text = "attrib=\"firstvalue\"";

   var XMLItem2 = XMLItem1.Add();
   XMLItem2.Name = "second";

   XMLDoc.SaveToFile(Script.Path + "test.xml");

   delete XMLDoc;



Will produce this XML data:
Code: Select all
<?xml version="1.0"?>
<root attrib="rootvalue">
   <first attrib="firstvalue">
      <second/>
   </first>
</root>


From the docs/source, I can see that the "Data" property of TfsXMLItem is defined as this:

property Data: Pointer read FData write FData;

Im guessing/hoping that is for setting values, but how do I work with pointers in FastScript/JScript?
There are 10 types of people in the world: Those who understand binary and those who don't.
User avatar
pmk65
 
Posts: 353
Joined: Sun Dec 20, 2009 9:58 pm
Location: Copenhagen, Denmark

Re: Feature Request: Support for XML parsing in plugins

Postby Aivars » Thu Mar 16, 2017 3:46 pm

As far as I know Fastscript doesn't support pointers at all. I'm checking out source code and apparently TfsXMLItem supports 3 properties: Name, Text and Data, but Data is Integer, so I'm not quite sure what that is for. I would have thought that Text is for tag content but according to your sample it's not so. Maybe this version does not support text content for nodes, only attributes (using xmlitem.Prop[...])?

This is all that is exported to scripting:

Code: Select all
      AddConstructor('constructor Create', CallMethod);
      AddMethod('procedure AddItem(Item: TfsXMLItem)', CallMethod);
      AddMethod('procedure Clear', CallMethod);
      AddMethod('procedure InsertItem(Index: Integer; Item: TfsXMLItem)', CallMethod);
      AddMethod('function Add: TfsXMLItem', CallMethod);
      AddMethod('function Find(const Name: String): Integer', CallMethod);
      AddMethod('function FindItem(const Name: String): TfsXMLItem', CallMethod);
      AddMethod('function Root: TfsXMLItem', CallMethod);
      AddProperty('Data', 'Integer', GetProp, SetProp);
      AddProperty('Count', 'Integer', GetProp, nil);
      AddDefaultProperty('Items', 'Integer', 'TfsXMLItem', CallMethod, True);
      AddIndexProperty('Prop', 'String', 'String', CallMethod);
      AddProperty('Name', 'String', GetProp, SetProp);
      AddProperty('Parent', 'TfsXMLItem', GetProp, nil);
      AddProperty('Text', 'String', GetProp, SetProp);


Maybe it's easier to pass the XML to Webkit and do the processing there?
Blumentals Software Programmer
User avatar
Aivars
Blumentals Software Developer
 
Posts: 1989
Joined: Thu Aug 22, 2002 1:40 pm
Location: Latvia

Re: Feature Request: Support for XML parsing in plugins

Postby Aivars » Thu Mar 16, 2017 3:52 pm

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.
Blumentals Software Programmer
User avatar
Aivars
Blumentals Software Developer
 
Posts: 1989
Joined: Thu Aug 22, 2002 1:40 pm
Location: Latvia

Re: Feature Request: Support for XML parsing in plugins

Postby pmk65 » Thu Mar 16, 2017 9:16 pm

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.. :lol:
(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>
There are 10 types of people in the world: Those who understand binary and those who don't.
User avatar
pmk65
 
Posts: 353
Joined: Sun Dec 20, 2009 9:58 pm
Location: Copenhagen, Denmark

Re: Feature Request: Support for XML parsing in plugins

Postby Aivars » Fri Mar 17, 2017 1:22 pm

I think Fastscript's version of XML is meant to be used internally, for saving/loading scripts and scripting language grammars, that's why the implementation is incomplete.

Excellent idea about using XMLDOM! I didn't even think about it, but indeed, it is possible to use ActiveX which opens a huge list of possibilities.
Blumentals Software Programmer
User avatar
Aivars
Blumentals Software Developer
 
Posts: 1989
Joined: Thu Aug 22, 2002 1:40 pm
Location: Latvia

Re: Feature Request: Support for XML parsing in plugins

Postby pmk65 » Fri Mar 17, 2017 9:07 pm

Aivars wrote:I think Fastscript's version of XML is meant to be used internally, for saving/loading scripts and scripting language grammars, that's why the implementation is incomplete.


Seems like a lot of the FastScript classes are "half baked", and lacking several features.

Like TTreeView. Here there's a "ImageIndex" property you can set, which refers to an image in a TImageList.
But FastScript has no support for TImageList, and neither does their implementation of TTreeView.
Nor can you make items in the TTreeView draggable, as it lacks events for drag/drop. :(

This is really annoying because their documentation sucks, so you will have to look for Delphi docs/examples instead.

Aivars wrote:Excellent idea about using XMLDOM! I didn't even think about it, but indeed, it is possible to use ActiveX which opens a huge list of possibilities.


Me neither, until I saw a Delphi example using it. :idea:
There are 10 types of people in the world: Those who understand binary and those who don't.
User avatar
pmk65
 
Posts: 353
Joined: Sun Dec 20, 2009 9:58 pm
Location: Copenhagen, Denmark


Return to HTMLPad / Rapid CSS / Rapid PHP / WeBuilder Feature Requests

Who is online

Users browsing this forum: No registered users and 1 guest