ruby - Mechanize / Nokogiri failing to parse XML with xpath -
i receive xml file api. i'm trying parse mechanize receives xml file. underlying nokogiri. whatever can't seem return xpath variables. seems recognise xml file fine i.e comes in mechanize::xmlfile , shows elements if use nokogiri.
i can run.
xml.at("/")
and response, other .at or .search run returns nil. e.g.
xml.at("//duration")
an example response below.
@body = "<jobsearchresults xmlns:i=\"http://www.w3.org/2001/xmlschema-instance\" xmlns=\"http://schemas.aspiremediagroup.net/jobboard/1.0/beta\"><duration>p0dt0h0m0.328s</duration><jobcount>0</jobcount><jobids /><jobs /><pagecount>0</pagecount><pageno>0</pageno><pagesize>20</pagesize><proximitystats i:nil=\"true\" /><rolesuggestions><string>adding</string></rolesuggestions><search><accountgroupids i:nil=\"true\" /><accountids i:nil=\"true\" /><excludeunknownsalaries>false</excludeunknownsalaries><industries i:nil=\"true\" /><jobidsonly>false</jobidsonly><jobtypes><id>any</id></jobtypes><locations><location><country>gbr</country><id i:nil=\"true\" /><latitude i:nil=\"true\" /><longitude i:nil=\"true\" /><parentlocation i:nil=\"true\" /><text i:nil=\"true\" /></location></locations><maxage i:nil=\"true\" /><maxdistance>25</maxdistance><page>1</page><pagesize>20</pagesize><role>adgqeg</role><salaries i:nil=\"true\" /><skills i:nil=\"true\" /><sortorder>overall_score_desc</sortorder></search><skillssuggestions><string i:nil=\"true\" /></skillssuggestions><started>2016-06-29t08:53:18.2215898z</started><thispagesize>0</thispagesize></jobsearchresults>"
any ideas why that's not working?
seems running
xml.remove_namespaces!
fixes issue , allows search of document using // style xpath variables.
i suspect there's better solution out there.
Comments
Post a Comment