我不得不从Web服务中提取信息。 这里有一个响应的例子:
<myServices>
<myService name="A" serviceId="a" type="rest" version="1.0">
<entryPoints/>
</myService>
<myService name="B" serviceId="b" type="rest" version="1.0">
<entryPoints/>
</myService>
<myService name="C" serviceId="C" type="rest" version="1">
<entryPoints>
<entryPoint realm="external" wadl="http://myURL.com/1/app.wadl>http://myURL.com/1</entryPoint>
</entryPoints>
</myService>
<myService name="D" serviceId="d" type="rest" version="1.0">
<entryPoints/>
</myService>
</myServices>
这里是我的xsd:
<?xml version="1.0" encoding="windows-1252" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.nisoars.myservices.1.com"
targetNamespace="http://www.nisoars.myservices.1.com"
elementFormDefault="qualified">
<xsd:element name="myServices">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="myService" type="ServiceType" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="ServiceType">
<xsd:sequence>
<xsd:element name="entryPoints">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="entryPoint" type="EntryPointType" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required"/>
<xsd:attribute name="serviceId" type="xsd:string" use="required"/>
<xsd:attribute name="type" type="ServiceTypeEnum" use="required"/>
<xsd:attribute name="version" type="xsd:string" use="required"/>
</xsd:complexType>
<!-- <entryPoint wadl="myWadl" realm="external">myURL</entryPoint> -->
<xsd:complexType name="EntryPointType">
<xsd:simpleContent>
<xsd:extension base="xsd:anyURI">
<xsd:attribute name="realm" type="RealmEnum" use="required"/>
<xsd:attribute name="wadl" use="optional" type="xsd:anyURI"/> <!-- Required for REST endpoints, but not for SOAP -->
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
<xsd:simpleType name="RealmEnum">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="internal"/>
<xsd:enumeration value="external"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="ServiceTypeEnum">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="rest"/>
<xsd:enumeration value="soap"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
我得到的错误是这个:
意想不到的元素(URI: “”,当地 “myServices”)。 预期元素是<{ http://www.nisoars.myservices.1.com } myServices>
因为我需要它为其他对象,我不能从XSD删除的命名空间。 我使用的是javax.bind.xml.Unmarshaller。
有任何想法吗?