繁体   English   中英

Xquery:使用 Java 返回多个数据元素?

[英]Xquery: returning multiple data elements using Java?

我有以下xml

<Products>
    <Product>
        <name>Sample name</name>
        <attribute id="sampleid" location="sampleLocation" type="sampleType"/>
        <price>12345</price> 
    </product>
</Products> 

如何从此 XML 返回给定名称的以下数据(始终唯一):

1. location (e.g. "sampleLocation")
2. type (e.g. "sampleType")
3. price (e.g. 12345

我目前能够单独查询每个以返回值,但我不确定将多个值一起返回的语法。

单个位置查询示例:

 ResourceSet resourceSet = service.query(
                        format("//Products/Product[name='%s']" +
                                        "/attribute/@Location/string()"
                                , StringEscapeUtils.escapeXml(journey_Name)
                        ));

上面的查询将返回:“sampleLocation”。

以下查询返回三个字符串的序列:

/Products/Product/(string(attribute/@location), string(attribute/@type), string(price)) 

如何将三个字符串的序列返回到您的 Java 应用程序取决于您使用的 XQuery 处理器和 API,您没有告诉我们。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM