2 Replies Latest reply on Dec 14, 2011 5:04 PM by areohbee

    xml parsing with LrXml


      Hi i hope its the last question for tonight ....

      im trying to parse xml im gettng , i have the flicker example that has some exml paprsing , but it using recurstion .

      i want to understand the basic here .

      say i have this xml :



        <message>authentication failure</message>




      and i want to get the value of <id> tag , how should i do it with LeXml , yep basic ...


      what i have is :

      // i dont understand this , what does it do ?

      local simpleXmlMetatable = {

          __tostring = function( self ) return self._value end




      local node = LrXml.parseXml( xmlString )

      local session_id = ""

      local type = string.lower( node:type() )

      if type == 'element' then


              local element = setmetatable( {}, simpleXmlMetatable ) < ---- CAN SOMEONE EXPLAIN ME WHAT IT IS ????

              element._name = node:name()       

              element._value = node:text()  < -- here im gettnig :  "10 authentication failure error "  , why it gives me all the values ? ?

               local id_node = node:childAtIndex(1)  < -- here i hoping to get the <id> tag but im gettng nil





        • 1. Re: xml parsing with LrXml
          DawMatt Level 3



          You are getting into some pretty advanced topics (metatables) here and it

          is going to be difficult and timeconsuming to answer these questions



          I suggest you have a read of some of the Programming in Lua book, which is

          available online. Specifically this section deals with metatables:





          • 2. Re: xml parsing with LrXml
            areohbee Level 6

            This code works:


            local xmlString = [[ 



              <message>authentication failure</message>




                                local sesnNode = LrXml.parseXml( xmlString )
                                local idNode = sesnNode:childAtIndex( 1 )
                                app:show{ info="ID: ^1", idNode:text() }


            "shows": 'ID: 4'


            As Matt said, I think you really need to read about metatables in the lua manual to understand that other stuff...