AnythingToXML and XMLToAnything Updates

I spent some time updating AnythingToXML last month with a feature that allows for type hinting. I was trying to avoid this, but XMLToAnything really can not be made smart enough to know that something was once an array with only one element in it. Instead it will interpret it as a Coldfusion struct. Since XMLToAnything was written to reverse XML created with AnythingToXML I added the type hinting to the XML generation. If there is no type hinting it will still work as before and attempt a best-guess on what the XML should become.

5 thoughts on “AnythingToXML and XMLToAnything Updates”

  1. Sorry to bother you, but I am looking at the xmlToAnything library and not sure how to use it. I see the XMLToAnything.cfc loads up the other components in it’s init(), and I see a toStruct() function in the component, but I would think I would also see toArray() and toQuery() in there as well.

    If I do:

    I am assuming this is my entry point into the library, so converting XML to a structure would be:

    I see that it generates a struct and nested array of structs, which I can work with. Maybe am I misunderstanding. Do I always call toStruct() and the library will figure out the best way to return it or can I call toQuery() and toArray()?

    1. Hi, yes the idea would be to call toStruct() and XMLToAnything would figure the rest out.

      
      
      
      

      DISCLAIMER: I would not use XMLToAnything in a production environment. Unlike AnythingToXML the XMLToAnything library is not very polished and your mileage may vary on its effectiveness. Code is provided “as is”. It exists mostly as an interesting programming challenge to see how well I could reverse what AnythingToXML had created.

      …Then again it may work just fine for your situation. Good luck

  2. Gotcha. FYI, works good on a twitter timeline. Also it’s being used in Taffy, a REST implementation.

    Curious why is your example though why you are trying to istantiate XMLToAnyThing twice:

    I get an error when I try that, but this works for me:

  3. Hey Dan,
    Sweet. I didn’t know that. That is really cool to hear! I guess some people have tested this code more than I have 😛

    Not sure what you mean by instantiate twice? createObject(‘component’, ‘XMLToAnything.XMLToAnything’) means use the XMLToAnything.cfc in the XMLToAnything directory.

    If you wrap your code wtih <pre lang=’cfm’> it should display.

Leave a Reply

Your email address will not be published. Required fields are marked *