开发者

Xpath Linked XML Values

I have master XML list that link开发者_运维问答s to other XML entities that I need to pull from. Here is an example of two of the feeds:

    <news state="Trial">
       <newsListItem href="http://api.newsfeed.com/x/news/800614671/">
       <id>800614671</id>
       <publishDate>2011-10-10T14:17:08</publishDate>
       </newsListItem>
       <newsListItem....> // Many more news items
    </news>

The url of newsListItem points to the secondary xml document that looks like:

    <newsItem encoding="UTF-8">
       <id>800614671</id>
       <state>Trial</state>
       <publishDate>2011-10-10T14:17:08</publishDate>
       <createdDate>2011-10-10T13:18:02</createdDate>
       <lastModifiedDate>2011-10-10T14:18:38</lastModifiedDate>
       <headline>Woman stabbed to death in south London</headline>
       <extract>Officers have confirmed a woman has been stabbed to death in a Bexleyheath street this morning.</extract>
       <categories href="http://api.newsfeed.com/x/news/800614671/categories/"/>
       <text format="html"><p>By Guy Kilty</p>
         <p>A woman has been stabbed to death and another has been injured in an attack in south London, police have confirmed.</p>
         <p>Officers were called to a busy street near the Asda supermarket in the Broadway area of Bexleyheath at 08:30 BST this morning (October 10th) following reports that a woman had been stabbed.</p>
         <p>The first victim was found with a stab wound and died at the scene, while the second had been stabbed in the hand and was taken to hospital.</p>
         <p>A Metropolitan Police spokesman said: &quot;Officers and the London Ambulance Service arrived on the scene and found a woman suffering stab wounds, who was pronounced dead at 8.41am.</p>
         <p>&quot;A second female suffered a knife injury to her hand. One woman has been arrested in connection with the incident.&quot;</p>
         <p>Police had no immediate information about the age of any of the people involved or any reason for the attack.</p>
       </text>
    </newsItem>

Is it possible to use XPath on the main feed to pull in data from the hrefs? I was originally looking at something like /news/newsListItem/@href/???/newsItem/headline, but I'm not sure that is the right track. Is this even possible with XPath?

Any advice would be greatly appreciated. This is my first time working with XPath.


Unfortunately for you, this is not possible. The best you can do is retrieve the href, load the second xml file and then retrieve the information you need.


There is an XPath function doc() with this signature:

fn:doc($uri as xs:string?) as document-node()?

It takes a URI and returns a document node. This should work; let me know if you need more details.


Probably you're asking about fn:doc($uri as xs:string?) as document-node()? function (is available in xPath 2.0). Not sure will it work - but your request can be rewritten as:

fn:doc(/news/newsListItem/@href)/newsItem/headline
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜