Don't forget you have to remove the `<?xml version=....?>` part of the XML before it will parse properly:
content = Shell.get_file_contents_utf8_sync('/path/to/file'); // or your preferred file-reading function // remove <?xml version=...?> (developer.mozilla.org/en-US/docs/E4X) content = content.replace(/^<\?xml\s+version\s*=\s*(["']).*?\1[^?]*\?>/, ''); xml = new XML(content); Then you can do stuff like `xml.tagname` to get a list of children with that tag name (use `xml.tagname.length()` to get the number of nodes, `xml.tagname[i]` to iterate through). You can also use double dot `xml..tagname` to find any descendant with 'tagname', not just the immediate children. And `xml.tagname.@attributename` (e.g. xml.a.@href) to retrieve that attribute. But when you do that the output is not a string - you need to use xml.a.@href.toString() to convert it. To get the text of a tag (e.g. <a href=...>Link Text</a>) you can use `node.text()`. On 9 November 2012 00:35, Jasper St. Pierre <jstpie...@mecheye.net> wrote: > You can use E4X to parse XML. It's a fancy language thing that's a bit > hard to get used to, and it's deprecated, but it works. > > https://developer.mozilla.org/en-US/docs/E4X > > > On Thu, Nov 8, 2012 at 7:12 AM, alok barsode <alokbars...@gmail.com>wrote: > >> Hi, >> >> I am writing a gnome shell extension for oFono. >> I need to know a way to parse an XML file in the extension. >> >> >> I am using gnome-shell 3.4 >> >> Thanks, >> Alok. >> >> _______________________________________________ >> gnome-shell-list mailing list >> gnome-shell-list@gnome.org >> https://mail.gnome.org/mailman/listinfo/gnome-shell-list >> >> > > > -- > Jasper > > > _______________________________________________ > gnome-shell-list mailing list > gnome-shell-list@gnome.org > https://mail.gnome.org/mailman/listinfo/gnome-shell-list > >
_______________________________________________ gnome-shell-list mailing list gnome-shell-list@gnome.org https://mail.gnome.org/mailman/listinfo/gnome-shell-list