【问题标题】:How many XML tree(parent children) can create in Java Marshalling and Unmarshalling在 Java Marshalling 和 Unmarshalling 中可以创建多少个 XML 树(父子级)
【发布时间】:2015-08-04 12:08:48
【问题描述】:

我想使用 java Marshalling 和 Unmarshalling 创建一个 XML 文件。如何开发Java类获取遵循Type XML。

<?xml version="1.0" encoding="UTF-8"?> 
<vxml version="2.0" xmlns="http://www.w3.org/2001/vxml" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xsi:schemaLocation="http://www.w3.org/2001/vxml 
 http://www.w3.org/TR/voicexml20/vxml.xsd">
  <form>
    <grammar src="cityandstate.grxml" type="application/srgs+xml"/>
    <block>
      <prompt bargein="false">
        <audio src="http://localhost.com/obl.wav"/>
      </prompt>
    </block>
  </from>
</vxml>

我想在使用 Hibernate、Spring 和 Maven 的 Jax-Rs Web 服务中获得这样的 XML。这个类想要通过 Jax-Rx web 服务运行。

【问题讨论】:

标签: java xml jax-rs marshalling unmarshalling


【解决方案1】:

由于您有可用的 XSD,您可以使用 JAXB2 Maven Plugin 为您生成适当的类型。

您可以通过将以下内容添加到您的 pom.xml 来做到这一点:

<project ...>
...
<build>
    <plugins>
        <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.12.3</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
...

它将尝试在src/main/resources 中查找您的 XSD 文件和可选绑定配置。如果您的 XSD 引用了其他 XSD 文件(如问题中所示),则这些引用的文件也需要存在于同一目录中。

【讨论】:

  • 我尝试这种方式,但我无法仅获得最后一个孩子的详细信息。
  • 没有看到你到底尝试了什么,很难说出了什么问题。
  • 以下类型的 XML 想要作为我在 Jax-rs Web 服务中的输出,想要使用 MarshallingUnmarshalling
猜你喜欢
  • 2020-10-21
  • 1970-01-01
  • 2021-12-12
  • 1970-01-01
  • 1970-01-01
  • 2012-02-28
  • 1970-01-01
  • 2018-05-23
  • 1970-01-01
相关资源
最近更新 更多