gihefca Posted April 27, 2012 Share Posted April 27, 2012 Hi My goal is to get an id from install.rdf, XML file from Mozilla's extensions I've tried with _XMLDomWrapper but it don't seem to work I don't think it can't work with a regex, the id can be anywhere in the file and can have multiple instances of it Example of XML to parse. I need to extract the red one expandcollapse popup<?xml version="1.0"?> <RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#"> <Description about="urn:mozilla:install-manifest"> <!-- Target Application this extension can install into, with minimum and maximum supported versions. --> <em:targetApplication> <Description> <!-- thunderbird --> [b]<em:id>{3550f703-e582-4d05-9a08-453d09bdfdc6}</em:id>[/b] <em:minVersion>1.5</em:minVersion> <em:maxVersion>3.1.*</em:maxVersion> </Description> </em:targetApplication> [color=#ff0000][b]<em:id>{9C463B6A-CCBE-11DB-97FC-FBC955D89593}</em:id>[/b][/color] <em:name>printers</em:name> <em:type>2</em:type> <em:version>0.4.9</em:version> <em:optionsURL>chrome://fgprinters/content/options.xul</em:optionsURL> <em:description>Adds additional print options</em:description> <em:creator>Ferdinand Grassmann</em:creator> <em:homepageURL>http://www.grassmann.info/ferdinand</em:homepageURL> <em:requires> <Description> <!-- Lightning --> [b]<em:id>{e2fda1a4-762b-4020-b5ad-a41df1933103}</em:id>[/b] <em:minVersion>0.9</em:minVersion> <em:maxVersion>1.0pre</em:maxVersion> </Description> </em:requires> <em:targetApplication> <Description> <!-- Sunbird --> [b]<em:id>{718e30fb-e89b-41dd-9da7-e25a45638b28}</em:id>[/b] <em:minVersion>0.9</em:minVersion> <em:maxVersion>1.0pre</em:maxVersion> </Description> </em:targetApplication> </Description> </RDF> Thanks for help Link to comment Share on other sites More sharing options...
iamtheky Posted April 27, 2012 Share Posted April 27, 2012 is it always followed by the "printers" name line? if so something like: #include <file.au3> $max = _FileCountLines ("test.xml") for $i = 1 to $max $readline = filereadline("test.xml" , $i) If stringinstr($readline ,"<em:name>printers</em:name>") Then $line = filereadline ("test.xml" , $i - 1) exitloop EndIf next $id = stringregexp($line , "<em:id>(.*?)</em:id>" , 3) msgbox (0, '' , $id[0]) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
gihefca Posted April 27, 2012 Author Share Posted April 27, 2012 It's not always the same scheme used btw, I found a solution using XML parser o/ Big thanks to PsaltyDS #include <_XMLDOMWrapper.au3> msgbox(0,"install.rdf id",_ParseRDF("install.rdf")) Func _ParseRDF($file) $xmlFile = FileRead($file) $xmlFile = StringReplace($xmlFile,'xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"',"") $xmlNamespace = 'xmlns:em="http://www.mozilla.org/2004/em-rdf#"' If _XMLLoadXML($xmlFile, $xmlNamespace) Then $ret = _XMLGetValue("/RDF/Description/em:id") If UBound($ret)<>2 Then Return False Return $ret[1] EndIf Return False EndFunc Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now