我收到错误“无法找到元素soapenv:Envelope的声明”
与其他xml文件一起正常工作xsd..Issue与以下内容一起工作..
我的Xml文件是: -
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/
http://schemas.xmlsoap.org/soap/envelope/
/tmp/checkxsd.xsd">
<soapenv:Body>
<ns:getEntitiesByFilterResponse
xmlns:ns="http://services"
xmlns:ax21="http://objects.services/xsd">
<ns:return xsi:type="ax21:EntityObj">
<ax21:entityId>1065798192</ax21:entityId>
<ax21:entityTypeId>4</ax21:entityTypeId>
<ax21:methodValues xsi:type="ax21:ValuePair">
<ax21:elementValue>Project SoapUI 001</ax21:elementValue>
<ax21:id>436</ax21:id>
</ax21:methodValues>
<ax21:methodValues xsi:type="ax21:ValuePair">
<ax21:elementValue>Project SoapUI 001</ax21:elementValue>
<ax21:id>100461</ax21:id>
</ax21:methodValues>
<ax21:methodValues xsi:type="ax21:ValuePair">
<ax21:elementValue>Project SoapUI 001</ax21:elementValue>
<ax21:id>400015</ax21:id>
</ax21:methodValues>
</ns:return>
<ns:return xsi:type="ax21:EntityObj">
<ax21:entityId>1065835163</ax21:entityId>
<ax21:entityTypeId>4</ax21:entityTypeId>
<ax21:methodValues xsi:type="ax21:ValuePair">
<ax21:elementValue>Project SoapUI 002</ax21:elementValue>
<ax21:id>436</ax21:id>
</ax21:methodValues>
<ax21:methodValues xsi:type="ax21:ValuePair">
<ax21:elementValue>Project SoapUI 002</ax21:elementValue>
<ax21:id>100461</ax21:id>
</ax21:methodValues>
<ax21:methodValues xsi:type="ax21:ValuePair">
<ax21:elementValue>Project SoapUI 002</ax21:elementValue>
<ax21:id>400015</ax21:id>
</ax21:methodValues>
</ns:return>
<ns:return xsi:type="ax21:EntityObj">
<ax21:entityId>1317237376</ax21:entityId>
<ax21:entityTypeId>4</ax21:entityTypeId>
<ax21:methodValues xsi:type="ax21:ValuePair">
<ax21:elementValue>CopyTask_project_1448004605927</ax21:elementValue>
<ax21:id>436</ax21:id>
</ax21:methodValues>
<ax21:methodValues xsi:type="ax21:ValuePair">
<ax21:elementValue>CopyTask_project_1448004605927</ax21:elementValue>
<ax21:id>100461</ax21:id>
</ax21:methodValues>
<ax21:methodValues xsi:type="ax21:ValuePair">
<ax21:elementValue>CopyTask_project_1448004605927</ax21:elementValue>
<ax21:id>400015</ax21:id>
</ax21:methodValues>
</ns:return>
</ns:getEntitiesByFilterResponse></soapenv:Body></soapenv:Envelope>
请在下面找到XSD: -
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://objects.services/xsd">
<xs:element name="entityId">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:enumeration value="1065798192" />
<xs:enumeration value="1065835163" />
<xs:enumeration value="1317237376" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="entityTypeId" type="xs:byte" />
<xs:element name="methodValues">
<xs:complexType>
<xs:sequence>
<xs:element name="elementValue">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Project SoapUI 001" />
<xs:enumeration value="Project SoapUI 002" />
<xs:enumeration value="CopyTask_project_1448004605927" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="id">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:enumeration value="436" />
<xs:enumeration value="100461" />
<xs:enumeration value="400015" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
我对xml验证xsd的java代码如下: -
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = factory.newSchema(new File("/tmp/checkxsd.xsd"));
Validator validator = schema.newValidator();
validator.validate(new StreamSource(new File("/home/my-pc/MyXMLFile.xml"))
非常感谢任何帮助。我坚持这个。
答案 0 :(得分:1)
您看到的消息几乎总是意味着验证器未加载架构;反过来,这几乎总是因为找不到它;反过来,这几乎总是因为在指定要处理的模式文档的位置时出现了一些错误。
一旦你的例子中的超长行被破坏,并且可以方便地读取最外层元素的开始标记而不向右和向左滚动,问题的一个来源(不一定是唯一的)似乎很清楚。您认为属性值规范的含义是什么
xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/
http://schemas.xmlsoap.org/soap/envelope/
/tmp/checkxsd.xsd">
(在这一点上,我希望你有一个头脑经验或者在困惑中抬起眉毛。如果是后者,我建议你查阅一些文档。)