Using this simplified XSD (simplified, but still verbose as all XSDs tend to be):

使用这个简化的XSD(简化,但仍然详细,因为所有XSD往往是):

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="[redacted]">
 <xsd:element name="Statement" type="BILLINGSTATEMENTTYPEType"/>

 <xsd:complexType name="BILLINGSTATEMENTTYPEType">
  <xsd:sequence>
   <xsd:element name="AccountSection" type="ACCOUNTSECTIONTYPEType"/>
   <xsd:element name="DataSection" type="DATASECTIONTYPEType"/>
   <xsd:element name="Summary" type="SUMMARYTYPEType"/>
  </xsd:sequence>
 </xsd:complexType>

 <xsd:complexType name="ACCOUNTSECTIONTYPEType">
  <xsd:sequence>
    <xsd:element name="Foo" type="xsd:string" maxOccurs="unbounded" minOccurs="0"/>
  </xsd:sequence>
 </xsd:complexType>

 <xsd:complexType name="DATASECTIONTYPEType">
  <xsd:sequence>
   <xsd:element name="Bar" type="xsd:string" maxOccurs="unbounded" minOccurs="0"/>
  </xsd:sequence>
 </xsd:complexType>

 <xsd:complexType name="SUMMARYTYPEType">
  <xsd:sequence>
   <xsd:element name="Baz" type="xsd:string" maxOccurs="unbounded" minOccurs="0"/>
  </xsd:sequence>
 </xsd:complexType>

</xsd:schema>

I generated a JAR file (using the <xmlbean> Ant task from xmlbeans), and everything appears to look great, I get all the right types and whatnot. But when I have it parse this simplified document:

我生成了一个JAR文件(使用xmlbeans中的 Ant任务),一切看起来都很棒,我得到了所有正确的类型和诸如此类的东西。但是当我解析这个简化的文档时:

<Statement>
    <AccountSection>
        <Foo>bar</Foo>
    </AccountSection>
    <DataSection>
    </DataSection>
    <Summary>
    </Summary>
</Statement>

Using this code:

使用此代码:

public class XmlTest {
    public static void main(String[] args) throws Exception {
        File xmlFile = new File("./data/test.xml");
        FileInputStream xmlStream = new FileInputStream(xmlFile);

        BILLINGSTATEMENTTYPEType statement = BILLINGSTATEMENTTYPEType.Factory.parse(xmlStream);

        ACCOUNTSECTIONTYPEType acctSection = statement.getAccountSection();

        System.out.println(statement.xmlText());
        System.out.println("acctSection is null:" + (acctSection == null));
    }
}

The acctSection (and any of the child sections I've tried) are always null, even though it is fully parsing the document.

acctSection(以及我尝试过的任何子节)总是为null,即使它完全解析了文档。

Output:

<Statement>
    <AccountSection>
        <Foo>bar</Foo>
    </AccountSection>
    <DataSection>
    </DataSection>
    <Summary>
    </Summary>
</Statement>
acctSection is null:true

Why is it null? Why are they all null? Did I improperly define something somewhere in my XSD? I've used xmlbeans before successfully and never had this issue, which is why I'm sure I'm missing something but I've been unable to find it.

为什么它是空的?他们为什么都是空的?我是否在XSD中的某处不正确地定义了某些内容?我在成功之前使用过xmlbeans,从来没有遇到过这个问题,这就是为什么我确定我错过了一些东西,但我一直无法找到它。

2 个解决方案

#1


3

I'm not an export in xmlbeans myself, but I noticed that you used the Factory of the complex type to parse the xml. Can you try to use StatementDocument.Factory instead?

我自己不是xmlbeans的导出,但是我注意到你使用了复杂类型的Factory来解析xml。您可以尝试使用StatementDocument.Factory吗?

更多相关文章

  1. Java反射---getGenericSuperclass和ParameterizedType参数化类型
  2. 黑马程序员——Java学习笔记 String类和基本数据类型对象包装类
  3. jswdk/jsdk/jdk到底分别是什么东西
  4. Java:如何创建特定父类型的集合而不是其子类型?
  5. 线程“main”中的异常java.lang.RuntimeException:无法编译的源代
  6. 了解数组类型和使用java.util.Arrays类
  7. Tinking in java枚举类型的自动贩售机
  8. 【读书笔记】JavaScript权威指南 第6版 (三)类型、值和变量
  9. RabbitMQ四种Exchange类型之Headers(Java)

随机推荐

  1. 搞定Mall项目中的权限管理功能,弄懂这些问
  2. android 运用取消默认的window preview
  3. 还在从零开始搭建项目?手撸了款快速开发脚
  4. 居然有人想白嫖我的日志,赶紧开启安全保护
  5. SpringBoot官方支持任务调度框架,轻量级用
  6. vCenter给虚拟服务器加资源后服务器时间
  7. Nginx如何支持HTTPS?手把手教贼简单!
  8. 40K+Star!Mall电商实战项目开源回忆录!
  9. mall-swarm微服务电商系统如何部署?用Jenk
  10. Github标星 8K+,免费又好用的Redis客户端