如何打印嵌套的xml元素? [英] How to print nested xml elements?

查看:45
本文介绍了如何打印嵌套的xml元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例xml:

<Root>
  <Customers>
    <Customer>
      <CompanyName>Great Lakes Food Market</CompanyName>
      <ContactName>Howard Snyder</ContactName>
      <ContactTitle>Marketing Manager</ContactTitle>
      <Phone>(503) 555-7555</Phone>
      <FullAddress>
        <Address>2732 Baker Blvd.</Address>
        <City>Eugene</City>
        <Region>OR</Region>
        <PostalCode>97403</PostalCode>
        <Country>USA</Country>
      </FullAddress>
    </Customer>
  </Customers>
</Root>

在上述xml中,当我将客户"用作根节点并将xpath查询用作"/Root/Customers/Customer"时,我无法打印"FullAddress"的子节点,而当我使用"FullAddress"时"作为根节点,而xpath查询则作为"/Root/Customers/Customer/FullAddress",无法打印所有字段.

In the above xml, when I use "Customer" as the root node and xpath query as "/Root/Customers/Customer", I'm unable to print the child nodes of "FullAddress" and when I use "FullAddress" as the root node and the xpath query as "/Root/Customers/Customer/FullAddress", unable to print all the fields.

请帮助我提供打印所有xml元素(包括嵌套在单个报告中)的解决方案.

Kindly help me with the solution to print all the xml elements including the nested in a single report.

推荐答案

正确的XPath查询是

The correct XPath query is

<queryString language="XPath">
    <![CDATA[/Root/Customers/Customer]]>
</queryString>

这包括您的两个节点,要访问值为 FullAddress 节点,则在定义字段时也应在 fieldDescription 中使用XPath,因此, Address 通过 FullAddress/Address

This include both of your nodes, to access the value is FullAddress node you should use XPath also in fieldDescription when you define your field, hence Address is accessed through FullAddress/Address

如果 CompanyName 的字段声明为

<field name="CompanyName" class="java.lang.String">
    <fieldDescription><![CDATA[CompanyName]]></fieldDescription>
</field>

例如 City 的字段声明为

<field name="City" class="java.lang.String">
    <fieldDescription><![CDATA[FullAddress/City]]></fieldDescription>
</field>

这篇关于如何打印嵌套的xml元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆