4 Replies Latest reply on Jan 4, 2009 1:39 PM by (nhok)

    Getting attributes from xml-node

      Hello all,

      I am trying to use the LrXml functions for analyesing an xml-file.
      I am parsing the file, so that I get a XML DOM object (domObj) of the following node


         öklasjdf
      asdfas


      Now I want to access the attributes, so I wrote in lua

      local attr = domObj.attributes()

      But I didn't find a way to access the attributes itselfs, I think mainly because I am not very familiar with lua. I tried the following two code sequences, but I always didn't get a result.

      local var1 = attr._mngid.value
      local var2 = attr["_mngid"].value

      Can somebody give me a hint, who the correct code sequnce would be to access the attribute of the node (that means, getting the value "23" out of it)?

      Thanks much in advanced!

      best regards
        Bernhard
        • 1. Re: Getting attributes from xml-node
          Level 1
          Hallo Bernhard.

          The attributes method should be called using the colon operator:
          local attr = domObj:attributes()
          

          Which is another notation for
          local attr = domObj.attributes(domObj)
          

          (So that the function implementation may access the actual instance to work on.) Small change and your code should work as intended.

          Herb
          • 2. Re: Getting attributes from xml-node
            Level 1
            Hello Herb,

            thanks for the tip, you are right, I missed the difference between colon and point!

            I tried it out with colon, but I also get with both code no return value. It seems, that something is wrong with the way I address the return code of domObj:attributes()

            local var1 = attr._mngid.value
            local var2 = attr["_mngid"].value

            If I place some logger Output in the code above, I never see the second call of myLogger:trace("var1")

            myLogger:trace("start")
            local var1 = attr._mngid.value
            myLogger:trace("var1")
            local var2 = attr["_mngid"].value
            myLogger:trace("var2")

            any Idea?

            best regards
            Bernie
            • 3. Re: Getting attributes from xml-node
              Level 1
              Your code looks correct to me (although it doesn't really trace the attribute value). Maybe the issue is located somewhere outside the scope of LrXml. Is the plug-in set to be reloaded every time it is called?

              If this does not help you might post the complete relevant code portion [preferably inside a html <pre> tag] so that we could make further investigation. ;)
              • 4. Re: Getting attributes from xml-node
                Level 1
                Hello Herb,

                thank you very much for your help, I now located the problem, it was lying inside my own code (I tried to access attr._mngid.value at a node, where no attribute _mngid exist), now it works everything allright.

                best regards
                Bernie