1
<DataSet xmlns="http://www.atcomp.cz/webservices">
<xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="file_mame">...</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<alldata xmlns="">
<category diffgr:id="category1" msdata:rowOrder="0">
<category_code>P.../category_code>
<category_name>...</category_name>
<subcategory diffgr:id="subcategory1" msdata:rowOrder="0">
<category_code>...</category_code>
<subcategory_code>...</subcategory_code>
<subcategory_name>...</subcategory_name>
</subcategory>
....
如何獲取所有categories
和subcategories
的數據?用Nokogiri解析XML文件?
我想是這樣的:
reader.xpath('//DataSet/diffgr:diffgram/alldata').each do |node|
但是這給了我:
undefined method `xpath' for #<Nokogiri::XML::Reader:0x000001021d1750>
感謝你回答約翰,但不幸的是,腳本不進入循環=>所以解析不會開始 – user984621 2012-07-17 19:12:05
此外,我只是試圖打印出'put doc',結果只是'<?xml version =「1.0」?>'' ,這很奇怪 – user984621 2012-07-17 19:22:13
它聽起來像你的'my_ document_string_or_io'是空的 – 2012-07-17 21:34:21