manoelcampos / xml2lua

XML Parser written entirely in Lua that works for Lua 5.1+. Convert XML to and from Lua Tables 🌖💱
MIT License
287 stars 73 forks source link

field names with colon in xml file #36

Closed aster94 closed 4 years ago

aster94 commented 4 years ago

hello @manoelcampos I have a xml files that in the fields has some colon, is it possible to read it?

This is what i tried and below there is an example file:

local xml2lua = require("xml2lua")
local handler = require("xmlhandler.tree")
local xml = xml2lua.loadFile("file.xml")
local parser = xml2lua.parser(handler)
parser:parse(xml)
local p= handler.x.rdf

But looks like that it is not working

<?xml version="1.0" encoding="UTF-8"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 4.4.0-Exiv2">
 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <rdf:Description rdf:about=""
    xmlns:xmp="http://ns.adobe.com/xap/1.0/"
    xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/"
    xmlns:darktable="http://darktable.sf.net/"
   xmp:Rating="1"
   xmpMM:DerivedFrom="IMG_1208_01.jpg"
   darktable:xmp_version="2"
   darktable:raw_params="0"
   darktable:auto_presets_applied="1"
   darktable:history_end="3">
   <darktable:mask_id>
    <rdf:Seq/>
   </darktable:mask_id>
   <darktable:mask_type>
    <rdf:Seq/>
   </darktable:mask_type>
   <darktable:mask_name>
    <rdf:Seq/>
   </darktable:mask_name>
   <darktable:mask_version>
    <rdf:Seq/>
   </darktable:mask_version>
   <darktable:mask>
    <rdf:Seq/>
   </darktable:mask>
   <darktable:mask_nb>
    <rdf:Seq/>
   </darktable:mask_nb>
   <darktable:mask_src>
    <rdf:Seq/>
   </darktable:mask_src>
   <darktable:history>
    <rdf:Seq>
     <rdf
      darktable:operation="flip"
      darktable:enabled="1"
      darktable:modversion="2"
      darktable:params="ffffffff"
      darktable:multi_name=""
      darktable:multi_priority="0"
      darktable:blendop_version="8"
      darktable:blendop_params="gz11eJxjYGBgkGAAgRNODGiAEV0AJ2iwh+CRxQcA5qIZBA=="/>
     <rdf
      darktable:operation="exposure"
      darktable:enabled="1"
      darktable:modversion="5"
      darktable:params="0000000010c7babce0ce773e00004842000080c0"
      darktable:multi_name=""
      darktable:multi_priority="0"
      darktable:blendop_version="8"
      darktable:blendop_params="gz11eJxjYGBgkGAAgRNODGiAEV0AJ2iwh+CRxQcA5qIZBA=="/>
     <rdf
      darktable:operation="exposure"
      darktable:enabled="1"
      darktable:modversion="5"
      darktable:params="000000007a362bbde0ce773e00004842000080c0"
      darktable:multi_name=""
      darktable:multi_priority="0"
      darktable:blendop_version="8"
      darktable:blendop_params="gz11eJxjYGBgkGAAgRNODGiAEV0AJ2iwh+CRxQcA5qIZBA=="/>
    </rdf:Seq>
   </darktable:history>
  </rdf:Description>
 </rdf:RDF>
</x:xmpmeta>
manoelcampos commented 4 years ago

Hello @aster94

I haven't seen any issues when using the tree handler for your XML. If you've found some issue, please be specific.

aster94 commented 4 years ago

This means I am making it wrong because I wasn't able to read it. How do you access the values with a colon? If I do

local xml2lua = require("xml2lua")
local handler = require("xmlhandler.tree")
local xml = xml2lua.loadFile("file.xml")
local parser = xml2lua.parser(handler)
parser:parse(xml)
local p= handler.x.rdf:li

The colon doesn't work

manoelcampos commented 4 years ago

That is a lua-related issue. Just use:

local p = handler.x["rdf:li"]
aster94 commented 4 years ago

You are completely right, that worked, sorry to bother you

manoelcampos commented 4 years ago

No problem.