cloocher / xmlhasher

Fast XML to Ruby Hash converter
MIT License
40 stars 20 forks source link

Xml parsing dont return attribute of tag #11

Open arjunmenon opened 6 years ago

arjunmenon commented 6 years ago

Hey I have an XML like this

<DIDL-Lite
    xmlns=\"urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/\"
    xmlns:upnp=\"urn:schemas-upnp-org:metadata-1-0/upnp/\"
    xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
    xmlns:dlna=\"urn:schemas-dlna-org:metadata-1-0/\"
    xmlns:sec=\"http://www.sec.co.kr/\"
    xmlns:pv=\"http://www.pv.com/pvns/\">
    <item id=\"0/all_tracks/47419\" parentID=\"0/all_tracks\" restricted=\"1\">
        <upnp:class>object.item.audioItem.musicTrack</upnp:class>
        <dc:title>The Local Train - Aaftaab Official Audio</dc:title>
        <dc:creator>&lt;unknown&gt;</dc:creator>
        <upnp:artist>&lt;unknown&gt;</upnp:artist>
        <upnp:albumArtURI>http://192.168.1.2:57745/external/audio/albums/113.jpg</upnp:albumArtURI>
        <upnp:albumArtURI dlna:profileID=\"JPEG_TN\">http://192.168.1.2:57745/external/audio/albums/113.jpg</upnp:albumArtURI>
        <upnp:album>Music</upnp:album>
        <ownerUdn>0ba501af-ad64-abe4-0000-000061ab1285</ownerUdn>
        <res protocolInfo=\"http-get:*:audio/mpeg:DLNA.ORG_PN=MP3;DLNA.ORG_OP=01;DLNA.ORG_FLAGS=01700000000000000000000000000000\" size=\"9388725\" duration=\"0:03:54.000\">http://192.168.1.2:57745/external/audio/media/47419.mp3</res>
    </item>
</DIDL-Lite>

When parsing it returns

{:"DIDL-Lite"=>
  {:xmlns=>"urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/",
   :"xmlns:upnp"=>"urn:schemas-upnp-org:metadata-1-0/upnp/",
   :"xmlns:dc"=>"http://purl.org/dc/elements/1.1/",
   :"xmlns:dlna"=>"urn:schemas-dlna-org:metadata-1-0/",
   :"xmlns:sec"=>"http://www.sec.co.kr/",
   :"xmlns:pv"=>"http://www.pv.com/pvns/",
   :item=>
    {:id=>"0/all_tracks/47409",
     :parentID=>"0/all_tracks",
     :restricted=>"1",
     :"upnp:class"=>"object.item.audioItem.musicTrack",
     :"dc:title"=>"Maahi Ve - Masala Coffee - Music Mojo Season 2 - Kappa TV",
     :"dc:creator"=>"<unknown>",
     :"upnp:artist"=>"<unknown>",
     :"upnp:albumArtURI"=>
      ["http://192.168.1.2:57745/external/audio/albums/113.jpg",
       "http://192.168.1.2:57745/external/audio/albums/113.jpg"],
     :"upnp:album"=>"Music",
     :ownerUdn=>"0ba501af-ad64-abe4-0000-000061ab1285",
     :res=>"http://192.168.1.2:57745/external/audio/media/47409.mp3"}}}

But if you notice the res tag, it is returning only the content which is a URL, but the tag has attributes like protocolinfo, duration, size, etc. I can't get them.

stepozer commented 5 years ago

Hello, in current project we use XmlHasher gem and added some patch for parsing attributes. I want add this functionality into current gem. Do have any suggestions about it?

Laykou commented 4 years ago

@stepozer Could you please share the change that you've done to access attributes? I'd also like to use this feature.

stepozer commented 4 years ago

@Laykou I will try share solution soon