Re: Parsing XML in gnome-shell extension



hi Amy,


On Fri, Nov 9, 2012 at 1:10 AM, Amy <mathematical coffee gmail com> wrote:
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);

I was able to print the content after the content.replace() and it seems to remove the xml version part correctly.
Unfortunately the next line :  xml = new XML(content); does not execute. i have a global.log() print after it and it
does not get printed. is there some const i need to include?

Do u know of any extension which parses an xml file ?


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="" Text</a>) you can use `node.text()`.

Thanks so much for ur help. 
Sorry for the late response, I was on vacation :)

Cheers,
Alok. 

On 9 November 2012 00:35, Jasper St. Pierre <jstpierre 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 <alokbarsode 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





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]