3 Replies Latest reply on Jun 28, 2010 2:12 AM by areohbee

    Using LrXml builderInstance to create a CDATA section

    Vladimir Vinogradsky Level 1

      Could somebody confirm or deny the following:

      LrXml doesn't seem to support the ability to embed a CDATA section in XML.

      For example, I can't find a way to produce something like this using the XML builder object:

       

      <?xml version="1.0" ?>

      <var>

      <name>var1</name>

      <value>

      <string><![CDATA[value123]]></string>

      </value>

      </var>

       

      Thanks.

        • 1. Re: Using LrXml builderInstance to create a CDATA section
          areohbee Level 5

          My memory is a little hazy, but I definitely had a problem with this which I finally got around using this code fragment:

           

                      t[#t + 1] = '<![CDATA['
                      for line in file:lines() do
                          t[#t + 1] = line
                      end
                      t[#t + 1] = ']' .. ']>' -- ********** this being the key line.

           

          I concluded the problem was with the lua parser itself (or maybe the way Lightroom calls it?), since the errors I was getting had to do with correct interpretation of the lua file itself, not the xml generation per se.

           

          Once separating the CDATA closure string I was able to use LrXml to build the CDATA into an xml file without any more problems.

           

          Hope this helps, and please let me/us know if it does or does not - thanks.

          Rob

          • 2. Re: Using LrXml builderInstance to create a CDATA section
            Vladimir Vinogradsky Level 1

            The double square bracket closing the CDATA section was never a problem. I had issues with LrXml encoding the opening angle bracket as an &lt; entity:

             

                local xml = LrXml.createXmlBuilder(false)

             

                xml:beginBlock("var")
                xml:tag("name", "var1")
                xml:beginBlock("value")
                xml:tag("string", "<![CDATA[value123]]>")
                xml:endBlock()
                xml:endBlock()

             

                local strXML = xml:serialize()

             

            Produces the following maligned XML:

             

            <?xml version="1.0"?>
            <var>
            <name>var1</name>
            <value>
            <string>&lt;![CDATA[value123]]></string>
            </value>
            </var>

             

            I guess one way to go about it is to run serialized XML through string.gsub to un-encode the "&lt;![CDATA[" sequence as follows:

             

            strXML = string.gsub(strXML, "&lt;!%[CDATA%[", "<![CDATA[")

             

            This is a nasty workaround, but this appears to be the only way to get the job done. Now my serialized XML looks as expected:

             

            <?xml version="1.0"?>
            <var>
            <name>var1</name>
            <value>
            <string><![CDATA[value123]]></string>
            </value>
            </var>

             

            This only leaves me wondering as to why LrXml doesn't support CDATA sections through its API, they are not that uncommon...

            • 3. Re: Using LrXml builderInstance to create a CDATA section
              areohbee Level 5

              Vladimir,

               

              Yes - my memory is coming back to me - I too had to do the same thing as you - sorry, I missed it last time around.

               

              In fact, I submitted a bug report / feature request about it - shortly after SDK 2.0 was released. Hard to imagine why that fell through the crack between SDK2.0 and SDK3.0 - its a pretty glaring ooooooops...

               

              I try to give Adobe the benefit of the doubt, but when stuff like this persists I can't help but scratch my head...

               

              I do think we can use the official bug-report form for SDK bugs as well - I suspect Adobe takes them more seriously than bug reports in the forum. I think this qualifies...

               

              https://www.adobe.com/cfusion/mmform/index.cfm?name=wishform

               

              Rob