XML library

Discussion in 'Additional Libraries' started by agraham, Nov 21, 2008.

  1. agraham

    agraham Expert Licensed User

    That does look like good practice. I won't support encodings other than UTF8 but I will make it write the encoding attribute on any future release.
     
  2. corwin42

    corwin42 Expert Licensed User

    Hi Andrew,

    if you have some time, can you please add a new Open() Method with the possibility to pass IgnoreWhitespace and IgnoreComments properties of XMLReaderSettings (or just expand the normal Open() but I don't know if you want to change the interface?

    Code:
    public void Open2(String filename, Boolean ignoreComment, Boolean ignoreWhitespace)
            {
                Close();
                XmlReaderSettings set = new XmlReaderSettings();
                set.IgnoreComments = ignoreComment;
                set.IgnoreWhitespace = ignoreWhitespace;
                rdr = System.Xml.XmlReader.Create(filename, set);
            
    }
    I have tested it with reading GPX files and this makes a major speed improvement.

    Thanks very much
    Markus
     
  3. agraham

    agraham Expert Licensed User

    Version 2.4 posted with XmlReader.Open2 added as requested above and the UTF8 encoding attribute written when saving by XmlDocument and XmlWriter also as discussed previously.
     
  4. mjcoon

    mjcoon Well-Known Member Licensed User

    I've just downloaded v2.4 (wondering how I'll get on with using it for KML).

    The Help says for XmlNodeList that "Count : Int32 [O] : Gets the number of XmlNodes in the XmlNodeList."

    I'm sure that, as hinted by "Gets" and by other examples, this property should be listed as "" ("I signifies readable, O signifies settable.")
     
  5. agraham

    agraham Expert Licensed User

    Yes, probably a YACPO (Yet Another Cut And Paste Oversight) :(
     
  6. mjcoon

    mjcoon Well-Known Member Licensed User

    I still haven't tried using the XML library. (I've been writing my KML as plain text.)

    But I've had a play with the demo programs.

    Got a complaint when I tried to execute (under PC IDE) XmlDocumentDemo.sbp that line 94
    Code:
    SbXml.Append(CRLF & InsetStr & "<" & nicename & " " & GetAttributes)
    has InsetStr which has not been assigned a value. At start of Sub SaveChildNodes, if
    Code:
    If Inset > 0 Then
    is false then it will not be set. Should it merely be a null string in this case?

    If I continue regardless the indented listing that I see (after dismissing an empty MsgBox!) has only some nested <font> items. Perhaps this is because the supplied TestDoc.xml file has a missing <font> terminator? Viewing with IE6 suggests this might be the case.

    When I tried XmlReadWrriteDemo.sbp (sic) I saw a listing of the XML and noticed that there is a duplication:
    Code:
    ' Lookup the prefix and write the ISBN element.
      wtr.WriteStartElement("ISBN")
      wtr.WriteString(
    "1-861003-78")
      wtr.WriteString(
    "1-861003-78")
      wtr.WriteEndElement
    This is probably just a pasting typo, but what is stranger is that I experimentally tried (just to see the effect) altering it to
    Code:
    ' Lookup the prefix and write the ISBN element.
      wtr.WriteStartElement("ISBN")
      wtr.WriteString(
    "1-861003-78a; ")
      wtr.WriteString(
    "1-861003-78b")
      wtr.WriteEndElement
    when I tried to type the space after ";" the IDE crashes! (message attached)

    Mike.
     
  7. agraham

    agraham Expert Licensed User

    Uncheck Tools-> Check for unassigned /unused variables. I'm afraid I tend to run with this off as it sometimes flags things that I don't regard as errors.

    The default for an unassigned variable is an empty string.

    I can't see a missing font terminator in TestDoc.xml, in fact if there was one I would expect that the XML parser would throw an exception to that effect although I do admit that the examples were thrown together in haste and that I am not brilliant at, nor particularly interested in, XML (nor HTML). This library sort of ran away from me as people requested extra features!

    I also get an IDE crash like you - from the stack trace it looks like a bug in the IDE at Dbasic.CCodePage.SmartHelp :(. One for Erel methinks!
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    @agraham or mjcoon can you upload a some program with this behavior?
     
  9. agraham

    agraham Expert Licensed User

    Just load XmlReadWrrite.sbp from the XML2.4 library archive, place the cursor within the "1-861003-78" string at line 39 or 40 and press space.
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    Did you change the classes XMLReader / XMLWriter to XmlReader / XmlWriter (the difference is in the 'ml')?

    Removing rdr and wtr and adding them back will fix this issue.
     
  11. agraham

    agraham Expert Licensed User

    Looking back in the source code archives I find that I did on the major upgrade to version 2.0 from 1.2. So I guess it's a partial case-insensitivity in whatever parses the Designer section of the source code file then?
     
  12. Erel

    Erel Administrator Staff Member Licensed User

    Something like that. I didn't find the exact point of failure as it not likely to happen again.
     
  13. mjcoon

    mjcoon Well-Known Member Licensed User

    I'm happy to rescind my comment that there is a </font> missing; it's at the end of the file. Virtually the whole document is contained in the outermost font element which is no doubt valid but not what I was expecting!

    I have successfully written my KML using XMLWriter, and read it back in again with XmlDocument.LoadXmlFile. I did the latter because I want to be able to add further structure to my file (several bites at my cherry!) and I can't see that this is going to be easy with XmlReader.

    But I still don't understand some aspects of XmlDocument (despite having briefly used M$'s DOM at work before retiring). In particular the help says "The different Node types that may be specified by the CreateNode methods are as follows." but I cannot find how to set the node type. There is a property, but it can only be read, not set.

    Mike.
     
  14. agraham

    agraham Expert Licensed User

    I would have thought that inevitable if you want a certain body style without having loads of font elements around individual bits of text.
    That makes at least two of us then!

    You can't change a node type. It has to be created as the type you want by XmlDocument.CreateNode.

    I'm afraid that the .NET XmlDocument and its' related Node objects don't map very well onto Basic4ppc as there are lots of them, one for each type of Node. Fortunately they are inherit from XmlNode with small differences so you can get away with only having a single XmlNode object in Basic4ppc.
     
  15. mjcoon

    mjcoon Well-Known Member Licensed User

    Yes; the document uses lots of "font elements around individual bits of text" as well. That is what led to my confusion. I guess the outermost sets up a default font which is reverted to at the end of each embedded font usage.

    Ah, may I tread in your pioneering footsteps?

    Thanks. I had found XmlDocument.CreateNode, but I have not yet used it successfully. The Help says "The should be assigned to the ControlRef of an XmlNode object for further processing." but many Help items say that, so maybe it is not highly significant! I don't understand the implication that the method has no effect on the XmlDocument node itself (I am presuming) rather than being a method of the node that is being created/established.

    Part of my problem is the lack of match between the Help for V2.4 and the methods that are offered by the IDE. E.g. the former has three variants of CreateElement for XmlDocument whereas the IDE offers me none. The Help has one variant of CreateNode whereas the IDE offers two.

    Also I see that the properties that are offered by the IDE for multiple (all?) objects are annotated as [O] when is obviously appropriate. But this is, I suppose, merely documentary and easy to ignore!

    Mike.
     
  16. agraham

    agraham Expert Licensed User

    It just returns a new XmlNode, you have to be able to make one somehow but you don't want literally hundreds of XmlNode objects littering up your Basic4ppc (or C#) program so you create it, assign it an XmlNode, play with it, add it to the document and move on to the next.

    Sorry, when I added XmlNode and XmlNodeList I removed the CreateElement methods and added CreateNode instead but was obviously a little sloppy updating the help.

    I can't document how to use the DOM (especially as I don't fully understand it myself!). I can provide the means of manipulating it, amend those means in the light of feedback and requests, but as I say in the library help "Overview" topic it needs other resources to be able to undertand how to use it.
     
  17. agraham

    agraham Expert Licensed User

    A revised help file is now available at post #1.

    EDIT :- Removed and replaced by version 2.5
     
    Last edited: Jan 13, 2010
  18. mjcoon

    mjcoon Well-Known Member Licensed User

    Thank you very much Andrew.

    I have now got XmlDocumentDemo.sbp.CreateNode to work for me. I had originally used this method immediately after the XmlDocument.New1 and it then failed ("Object reference not set to an instance of an object" see image). After I had done XmlDocument.LoadXmlFile it works. Fortunately this is how I could arrange things in my program (since the KML file is generated in the first place with your XMLWriter).

    So perhaps the New1 generates an "empty" Basic4PPC object with no underlying .NET XmlDocument object but this does not support CreateNode. So if I did not have a starter-for-ten KML/XML file, how would I get out of this Catch-22 situation?

    If I've got it wrong and there is no Catch-22, could you enhance your demo XmlDocumentDemo.sbp to include the creation of a trivial XmlDocument from scratch (no Load!)?

    Mike.
     
  19. agraham

    agraham Expert Licensed User

    After Googling I've found how to create a new XML document from scratch.

    In version 2.5 now posted. XmlDocument.New1 now creates a new document and adds the obligatory XML declaration. Also the new XmlDocument.CreateDocument method discards any existing document and creates a new one. This in itself is not a valid XML docuemnt. To form the smallest legal XML document a root element needs to be added.
     
  20. mjcoon

    mjcoon Well-Known Member Licensed User

    Thank you, Andrew, that is amazingly responsive of you.

    I'll just mention the IDE-hints for the properties of (all?) the objects as having annotation of [O] where is obviously intended as a to-do item for the next release.

    Speaking of the next release, could the XmlNode object have a "Clone" method? I see in XmlNode Members (System.Xml) (which I am guessing is the underlying .NET object though I don't understand the relationship between System.Xml and .NET) has a Clone method.

    This is because my program is generating KML files with multiple Placemarks with the same structure and cloning would be a convenient and, I assume, efficient way of creating them. I am currently using the XML text property to do this replication and having some problem that I do not yet understand. Not having to do this serialisation and parsing would, I imagine, be much mmore efficient and reliable.

    Mike.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice