问题:我们有几种服务可以通过XSLT生成大量的XML.我们没有任何XSD.我花时间创建了XSD,并想确认它们是正确的.目前我正在尝试验证XSD和XML是否正确验证.
问题:我有一个导入所有xsd的xsd(common.xsd).它还没有公开托管,所以直到最近我才发现将common.xsd的完整路径放在AccountList.xsd中我才得以进一步发展.我现在收到以下内容:
org.xml.sax.SAXParseException; lineNumber:9; columnNumber:70; s4s-att-invalid-value:元素'element'中'type'的属性值无效.记录原因:UndeclaredPrefix:无法将'common:response'解析为QName:未声明前缀'common'.
我很茫然.我找不到在论坛中提出的示例或获得成功的源代码片段.我很感激有助于成功验证我的xml.
common.xsd
<xs:schema version="1.0" elementFormDefault="qualified" attributeFormDefault="unqualified"
xmlns="http://www.myorg.com/xsd/gen_fin"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.myorg.com/xsd/gen_fin">
<xs:complexType name="response">
<xs:sequence>
<xs:element name="code" type="xs:string"/>
<xs:element name="description" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
AccountList.xsd
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xs:schema version="1.0" elementFormDefault="qualified" attributeFormDefault="unqualified"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.myorg.com/xsd/accList"
targetNamespace="http://www.myorg.com/xsd/accList"
xmlns:common="http://www.myorg.com/xsd/gen_fin">
<xs:import namespace="http://www.myorg.com/xsd/gen_fin"
schemaLocation="/home/me/dev/projects/svn/myorg/xsd/src/main/resources/bg/gen_resp/common.xsd"/>
<xs:element name="fundamo">
<xs:complexType>
<xs:sequence>
<xs:element name="response" type="common:response" minOccurs="1" maxOccurs="1"/>
<xs:element name="transaction" type="tns:transaction" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="transaction">
<xs:sequence>
<xs:element name="transactionRef" type="xs:string"/>
<xs:element name="dateTime" type="xs:string"/>
<xs:element name="userName" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
Test.java
final InputStream commonXsdStream …Run Code Online (Sandbox Code Playgroud)