查看完整版本: 这个编码到底那儿错了?

nana 2008-4-17 13:18

这个编码到底那儿错了?

我想要下面这个结果,但是我写出的编码为什么得不出来?到底那儿错了?
<?xml version="1.0" encoding="utf-8" ?>
<category xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:yahoo:jp:auc:category" xsi:schemaLocation="urn:yahoo:jp:auc:category [url=http://api.auctions.yahoo.co.jp/AuctionWebService/V1/CategoryTree.xsd][color=black]http://api.auctions.yahoo.co.jp/ ... V1/CategoryTree.xsd[/color][/url]">
<categoryId>23568</categoryId>
<categoryName>ソフトウェア</categoryName>
<categoryPath>オークション > コンピュータ > ソフトウェア</categoryPath>
<parentCategoryPath>オークション > コンピュータ</parentCategoryPath>
<isLeaf>false</isLeaf>
<childCategoryNum>4</childCategoryNum>
<childCategory>
.
.
.
我的编码如下:
[color=darkred]$KCODE = 's'
require 'open-uri'
require 'rexml/document'
require 'cgi'

BASE_URI = 'http://api.auctions.yahoo.co.jp/AuctionWebService/V1/CategoryTree'

def print_categoryId(term)
  term = CGI::escape(term)
  xml = open(BASE_URI + "?appid=saikeina&category=#{term}").read
  document = REXML:document.new(xml)
  
  REXML::XPath.each(document, '/category/categoryId/[]') do |categoryId|
    #begin
    f = File.open("003.txt" , "w+")
    f.write(document)
    f.close
    #end
  end
end

(puts "Usage: #{$0} [search term]"; exit) if ARGV.empty?
print_categoryId(ARGV.join(' '))[/color]

我的编码得出来的结果:
<?xml version='1.0' encoding='UTF-8'?>
<category xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='urn:yahoo:jp:auc:category [url]http://api.auctions.yahoo.co.jp/AuctionWebService/V1/CategoryTree.xsd'[/url] xmlns='urn:yahoo:jp:auc:category'>
        <categoryId>0</categoryId>
        <categoryName>オークション</categoryName>
        <categoryPath>オークション</categoryPath>
        <parentCategoryPath/>
        <isLeaf>false</isLeaf>
        <childCategoryNum>25</childCategoryNum>
        <childCategory>
        .
        .
        .

帮忙看看,我到底那儿错啦?问题有点儿麻烦,谢谢各位!

[[i] 本帖最后由 nana 于 2008-4-17 13:20 编辑 [/i]]

rubylee 2008-4-18 14:57

你上面的结果从哪来的

人家本身就是25个childCategory呀

除非你在xpath里面做过滤条件吧。。

zoubin200999 2008-9-4 15:49

什么版本的哦?
页: [1]
查看完整版本: 这个编码到底那儿错了?