• Hi Julian,

    I've just started using this component and have come across a few problems/bugs. I've resolved these myself by maintaining my own structure for storing the xml (I use the component now only for the intitial parse of XML). I thought it would be useful to point out the problems for you or for any wpTools users (it took me quite some time to work out what was going wrong).

    1. If you load an xml file into the component and then immediately save it, all you are left with is the xml declaration. This seems to be due to the fact that the first thing wpxmlInterface's savetostream function does is clear FData, which seems to be the storage mechanism for the xml.

    I removed this and managed to save the XML.

    2. The XML that is saved is not then well-formed. At its very end it has a repeat of the XML declaration. This seems to be caused by the SaveToStream function, which calls DoWriteStart, which writes the XML declaration at the end of the file.

    3. Even if you comment out the call to doWriteStart, the saved XML is still not well-formed because of some extraneous characters at the very end of the file.

    4. I tried to write a tag at a specific spot in the XML file using onStartTag. I assumed that the new tag would be written within the currenttag, but it was just added to the end of the file.

    I hope this helps.

    Cheers

    Mark

    • Offizieller Beitrag

    Hi,

    I am a bit surprised, Normally you would use the WPXMLTree and this worked very well in the past. I am using it for configuration files and also for the HTML/CSS writer of WPTools 4. The language files are created by this class, too.
    The XMLInterface is the ancestor of XMLtree and basically only contains the reading/writing logic with the ability to parse XML tags into names and parameters at readtime and the ability to close opened tags automatically at write time. Since the XMLInterface does not store anyting it is not possible to do a load and a save.

    To use the TWPXMLTree for configuration files use this:

    Loading (in Form.OnCreate)

    Code
    XML:=  TWPCustomXMLTree.Create(Self);  try XML.LoadFromFile(    ExtractFilePath(application.EXEName) + 'test.xml' );    aName.Text := XML.TagByName('pdfcontol/name').Content;    aKey.Text := XML.TagByName('pdfcontol/key').Content;    aCode.Text := XML.TagByName('pdfcontol/code').Content  except  end;


    Saving:

    Code
    XML.Tree.AddTagValue('pdfcontol/C', 'Written by WPTools XML Interface - (C) WPCubed GmbH' );
      XML.Tree.AddTagValue('pdfcontol/name', aName.Text );
      XML.Tree.AddTagValue('pdfcontol/key', aKey.Text );
      XML.Tree.AddTagValue('pdfcontol/code', aCode.Text );
      try XML.SaveToFile(
        ExtractFilePath(application.EXEName) + 'test.xml') ;
      except
      end;

    [/b]

  • Hi Julian,

    Thanks for the reply. From your code it looks like the xmlInterface does store the xml data until you actually call the save procedure.

    I was puzzled that the interface does not actually save anything. I assumed it was the base component for languageControl and that saves!

    Anyway, I've got the xmlInterface doing exactly what I want it to do, by mirroring the xmlData in a stringlist when I load it and manipulating and saving the stringlist. Works well for me with just a few extra lines of code.

    Regards

    Mark

  • Julian,

    It just occurred to me. Why if you can't load and save to the xmlInterface does it have public load and save methods? I spent a lot of time trying to figure out what was going on with this component (about 5 hours yesterday). The help file tells you that it has a load and save method, but doesn't tell you anything else and, in particular, does not tell you that it does not work! Julian, I appreciate that writing and maintaining help files (particularly for something as huge as wpTools) is a nightmare job and please do not think I am getting at you, but sometimes it would be better not to have a component than to have one that is not documented.

    I know I've said this before, but please can you try and make the help files for v 5 more comprehensive. Even if you don't, I know I'll still buy it (and the next version etc) as I am a huge fan of the product. However, I think that more documentation would help everyone get more out of the product and would save you an awful lot of time that will otherwise be spent in answering basic and unnecessary questions.

    Regards,

    Mark

    • Offizieller Beitrag

    Mark,

    Thanks for the comment and also for liking my product!

    WPTools 5 manual is a lot better I hope since it was written while the RTF engine was constructed. But the shared components manual should not be so bad either. I am not sure if it was lost on the way, but originally there was a complete wpshared HLP file.
    (It is for download on https://www.wpcubed.com/ftp/wpsharedhlp.zip )
    which states:

    The XML support classes come in the flavor event driven : TWPXMLInterface and using a memory tree: TWPXMLTree:

    In the WPXMLInterface it says
    >>
    This class implements a XML support which triggers events to let *you* load and save XML data. The developer is only responsible to store the XML data while the component does the other part: parsing, translation of entities, conversion of parameter to stringlists, maintaining a read-stack at load time, automatic creation of missing tags at read time, automatic closing of tags at write time.

    This class was created to provide an easy to use XML interface and it does not yet support unicode and will not support DOM and other entities than the predefined XML entities + common HTML entities. Since it can be configured to also allow non standard XML input and output.
    If you need an XML tree stored in memory use the component TWPXMLTree.
    <<

    I hear sometimes that the manuals are insufficient but I also sometimes note that they are not read. I also want to mention that WPTools comes with a lot of source which should be at least once looked through to understand it better. Esspecially the unit WPRich.PAS is very important since it uses the RTF engine at a high level.

    Julian

    • Offizieller Beitrag

    Forgot to answer this:

    >>Why if you can't load and save to the xmlInterface does it have public load and save methods?<<

    The TWPXMLInterface creates events in this case. This might seem to be kind of dumb since you have to put basically all the the writing code into the event OnWriteTextStart. It was build this way since the XMLTree uses this method internally.

    Julian

  • Thanks Julian,

    Duly noted.

    I did originally have a shared help file. It's gone with more recent downloads and because xmlInterface (which is a shared component) was documented in the main wpTools help file, I assumed they'd been rolled into one.

    Regards,

    Mark