XML library

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

  1. agraham

    agraham Expert Licensed User

    Version 2.6 posted. XmlNode now has a Clone method that returns a deep or shallow clone of itself.

    There's no point mentioning them as I have no control over them. Unfortunately my convention for in or out is opposite to the IDE. My which is Input to the application is equivalent to its' [O] which is Output from the library. I think the IDE convention may be a Microsoft one whereas mine is common-sense :).
     
  2. mjcoon

    mjcoon Well-Known Member Licensed User

    Thank you yet again Andrew. I sorted out what I was doing wrong with my .xml -> .xml copying mechanism, but have now converted to the new Clone method and it works a treat.

    Regards, Mike.
     
  3. TWELVE

    TWELVE Active Member Licensed User

    Is this still the case..? That's too bad, i need this feature as well.Since most B4P Libs appear to me just as a .NET wrapper, my question would be then: is this feature contained in a newer .NET CF version ( 3.5 ?)..?

    For a string from a protocol conversation i might be done using B4P string operations but if it grows and get more complex over time the code might become bulky and too complicated.

    Maybe an existing piece of...code in C could be converted to a B4P Lib...


    regards,

    TWELVE
     
  4. agraham

    agraham Expert Licensed User

    Nope! C as an unmanaged language has nothing to do with .NET and any existing .NET code would have nothing to do with what you want.

    XMLReader and XMLWriter read/write .NET Streams. The library uses FileStreams. The way to do what you want would be to make MemoryStreams from which to read/write string data as a series of bytes and pass those streams to the library. It is not terribly difficult but I would not do it just for this one library but would make it more generic in a library like FilesEx and then just expose a Stream interface in the libraries that could make use of it. But I'm not likely to do that very soon.

    Anyway as you are accessing a server, presumably over a network, I would have thought the overhead of using temporary files would be pretty small.
     
  5. corwin42

    corwin42 Expert Licensed User

    I haven't tried it but I think you can use the XMLDocument object for this. With XMLDocument.LoadXml(xxx) you can load an XML document from a String and with the XMLDocument.xml property you should have access to the xml text of the XMLDocument object.
     
  6. mjcoon

    mjcoon Well-Known Member Licensed User

    I haven't tried it either (though I am using XML.dll to do KML), and LoadXML may work, but unfortunately the XML: property is described as:

    This suggests that the string you get does not include the document object itself. Thus a bit of massaging may be required.

    Mike.
     
  7. agraham

    agraham Expert Licensed User

    Here's a more comprehensive description of the XML property, which is actually the InnerXml property of the underlying .NET XmlDocument object.
    XmlDocument.InnerXml Property (System.Xml)

    The line in the help "Gets or sets the markup representing the children of the current node" which I dutifully copied to the help actually appears to be wrong in this instance and seems to be copied from the XmlNode.InnerXml property help where it is correct.
     
  8. mjcoon

    mjcoon Well-Known Member Licensed User

    I'm exploring parts of syntax of KML and GPX where elements are optional.

    Until now there have been several candidates that I wanted to process, so I have worked my way through a XMLNodeList of children. But now I want to process a <name> child node if present but no other children.

    So it seems overkill to build a XMLNodeList when I can just get the one I want by GetChild2("name"). But the problem I have is knowing if such a node was found.

    (The same would apply if looking for an attribute; it just so happens that the ones I want are all mandatory.)

    Short of using exception handling, how to determine if a node is present?

    Mike.
     
  9. agraham

    agraham Expert Licensed User

    You could try using the IsNull keyword

    If IsNull(GetChild2("name")) Then
    ....
    End If

    or

    myXnlNode.Value = GetChild2("name")
    If IsNull(myXnlNode.Value) Then
    ....
    End If
     
  10. mjcoon

    mjcoon Well-Known Member Licensed User

    Thanks Andrew, it's rather obvious when you point it out; I had not noticed it before.

    Cheers, Mike.
     
  11. mjcoon

    mjcoon Well-Known Member Licensed User

    A new problem with LoadXmlFile(). I have a KML file that is 2.1Mb which fails to load on PPC whereas it is OK on PC.

    So I guess this is a memory problem.

    Am I right that there is not going to be a solution to this problem?

    Mike.
     
  12. agraham

    agraham Expert Licensed User

    Correct! :(

    That large file probably expands into a huge XmlDocument object. Can you use an XmlReader instead, that won't suffer the same expansion problem?
     
  13. mjcoon

    mjcoon Well-Known Member Licensed User

    Thanks for the confirmation Andrew. Using XmlReader would be hard work because the crucial data gets decanted into arrays (hence my recent question about how to park a 2-D array in a file). So I need to know the size of the array first which would require two passes through the file. Unless I change to using collections, which I suppose would be slower in action...

    Mike.
     
  14. mjcoon

    mjcoon Well-Known Member Licensed User

    I cannot get to grip with prefixes and namespaces.

    How do I use this XMLWriter of library XML to get this sort of heading?
    Mike.
     
  15. PdaMoc

    PdaMoc Member Licensed User

    Hy agraham!

    I have a html document where I would like to use your library to get the content of an element.
    I have just class name. How can I get the content of the structure about the class name?

    Code:
    <div class="details-catbar"><span class="catbar-text"><h3>ESTO Fortuna 60305-2 falilámpa</h3></span></div>
    <div class=
    "product-image-first"><a href="http://www.bavill.hu/components/com_virtuemart/shop_image/product/ESTO_falil__mpa_5056fbac54c4f.jpg" title="ESTO Fortuna 60305-2 falilámpa" rel="rokbox[250 415](product3622)"><img src="http://www.bavill.hu/components/com_virtuemart/shop_image/product/ESTO_falil__mpa_5056fbac54aa3.jpg" alt="ESTO Fortuna 60305-2 falilámpa" border="0" width="300"></a></div>
    <div class=
    "home-featured-sku">Cikkszám: 60305-2</div>
    <span class=
    "productPrice">16 470 Ft        (27 % áfával)    </span>
    <div class=
    "product-description">
        <p>
    2 db LED égős fali lámpa. Hossza 170 mm. A lámpa burák átmérője 800 mm. Égők: 5 x 42 W. Foglalat: G9. Anyaga: króm és üveg.</p>
    </div>
     
  16. agraham

    agraham Expert Licensed User

    Firstly it needs well-formed XML and not HTML.

    Secondly, as I stated in the first post
     
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