当您进行搜索时,例如“柏林历史”时,您会要求一个URL
而且您会得到这样的XML结果:
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfResult
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://lookup.dbpedia.org/">
<Result>
<Label>Museum für Naturkunde</Label>
<URI>http://dbpedia.org/resource/Museum_für_Naturkunde</URI>
<Description></Description>
<Classes></Classes>
<Categories></Categories>
<Templates></Templates>
<Redirects></Redirects>
<Refcount>155</Refcount>
</Result>
<Result>
<Label>History of Berlin</Label>
<URI>http://dbpedia.org/resource/History_of_Berlin</URI>
<Description>
Berlin is the capital city of Germany. Berlin is a young city by European standards, founded in the 12th century.
</Description>
<Classes></Classes>
<Categories>
<Category>
<Label>History of Berlin</Label>
<URI>http://dbpedia.org/resource/Category:History_of_Berlin</URI>
</Category>
<Category>
<Label>History of Germany by location</Label>
<URI>http://dbpedia.org/resource/Category:History_of_Germany_by_location</URI>
</Category>
</Categories>
<Templates></Templates>
<Redirects></Redirects>
<Refcount>14</Refcount>
</Result>
</ArrayOfResult>
你是对的 URI
具有URI类别的元素,例如
<URI>http://dbpedia.org/resource/Category:History_of_Berlin</URI>
但是您应该注意的是,从文档的根部中,有
ArrayOfResult/Result/Categories/Category/URI
元素,而您想要的元素是
ArrayOfResult/Result/URI
元素。您只需要以不同的方式处理XML即可;不明白 全部 来自 全部 URI
元素,但只是从 URI
是子女的元素 Result
元素。我并不那么熟悉萨克斯的解析,但我认为重要的是,一旦您进入了 Result
, ,您只应该抓住 URI
如果您还没有输入另一个子元素 Result
.