-1

这适用于 Java 中使用的 XQuery。我的代码正在处理其他 XML 文件,但这次它没有返回所需的数据。错误代码如下。它有什么问题?谢谢。

String queryString =
                    "declare variable $docName as xs:string external;" + sep +
                    "      for $TRACK in doc($docName)/playlist/tracklist/track " +
                    "   return " +
                    " <track><title>{$TRACK/title/text()}</title>" +
                    " <location>{$TRACK/location/text()}</location></track>";

这是目标 XML:

    <?xml version="1.0"?>
    -<playlist xmlns="http://xspf.org/ns/0/" version="1">
       -<trackList>-<track><location>http://radiotool.com/242.mp3</location><title>New                   York</title></track>
                   -<track><location>http://radiotool.com/243.mp3</location> <title>Chicago Repeater</title></track>
</trackList></playlist>
4

1 回答 1

1

这可能是因为源 XML 使用名称空间而您的 XPath 没有。这个怎么样:

String queryString =
                "declare namespace xsp='http://xspf.org/ns/0/'; " + 
                "declare variable $docName as xs:string external;" + sep +
                "  for $TRACK in doc($docName)/xsp:playlist/xsp:trackList/xsp:track " +
                "   return " +
                " <track><title>{$TRACK/xsp:title/text()}</title>" +
                " <location>{$TRACK/xsp:location/text()}</location></track>";
于 2013-03-13T18:33:06.963 回答