gpt4 book ai didi

xml - 使用XPath从WSDL文件中的导入(“xsd:import”)模式获取XML元素声明

转载 作者:行者123 更新时间:2023-12-03 16:40:26 25 4
gpt4 key购买 nike

我有一个问题困扰了我一个星期。

我使用Netbeans 7.2.1将虚拟Web服务编程为无状态EJB:

@WebService(serviceName = "WSPersonLookup")
@Stateless()
public class WSPersonData {

@PersistenceContext(unitName="PUWSPersonData")
private EntityManager em;

/**
* Web service operation
*/
@WebMethod(operationName = "getPersonData")
public Person getPersonData(@WebParam(name = "personId") final String personId) {
return em.find(Person.class, personId);
}
}


类“ Person”只是映射到此表的JPA实体(我将PostgreSQL用作DBMS):

CREATE TABLE person
(
id character varying(10) NOT NULL DEFAULT ''::character varying,
nit text NOT NULL DEFAULT ''::text,
name text NOT NULL DEFAULT ''::text,
address text NOT NULL DEFAULT ''::text,
phone integer NOT NULL DEFAULT 0,
creation_date timestamp with time zone NOT NULL DEFAULT now(),
CONSTRAINT pk_person PRIMARY KEY (id)
)


产生的WSDL是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ws.i2b.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws.i2b.com/" name="WSPersonLookup">
<types>
<xsd:schema>
<xsd:import namespace="http://ws.i2b.com/" schemaLocation="http://pc-i2b:8080/WSPersonLookup/WSPersonData?xsd=1" />
</xsd:schema>
</types>
<message name="getPersonData">
<part name="parameters" element="tns:getPersonData" />
</message>
<message name="getPersonDataResponse">
<part name="parameters" element="tns:getPersonDataResponse" />
</message>
<portType name="WSPersonData">
<operation name="getPersonData">
<input wsam:Action="http://ws.i2b.com/WSPersonData/getPersonDataRequest" message="tns:getPersonData" />
<output wsam:Action="http://ws.i2b.com/WSPersonData/getPersonDataResponse" message="tns:getPersonDataResponse" />
</operation>
</portType>
<binding name="WSPersonDataPortBinding" type="tns:WSPersonData">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
<operation name="getPersonData">
<soap:operation soapAction="" />
<input>
<soap:body use="literal" />
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
</binding>
<service name="WSPersonLookup">
<port name="WSPersonDataPort" binding="tns:WSPersonDataPortBinding">
<soap:address location="http://pc-i2b:8080/WSPersonLookup/WSPersonData" />
</port>
</service>
</definitions>


XSD声明:

<?xml version='1.0' encoding='UTF-8'?>
<xs:schema xmlns:tns="http://ws.i2b.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0" targetNamespace="http://ws.i2b.com/">
<xs:element name="getPersonData" type="tns:getPersonData"/>
<xs:element name="getPersonDataResponse" type="tns:getPersonDataResponse"/>
<xs:element name="person" type="tns:person"/>
<xs:complexType name="getPersonData">
<xs:sequence>
<xs:element name="personId" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="getPersonDataResponse">
<xs:sequence>
<xs:element name="return" type="tns:person" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="person">
<xs:sequence>
<xs:element name="address" type="xs:string" minOccurs="0"/>
<xs:element name="creationDate" type="xs:dateTime" minOccurs="0"/>
<xs:element name="id" type="xs:string" minOccurs="0"/>
<xs:element name="name" type="xs:string" minOccurs="0"/>
<xs:element name="nit" type="xs:string" minOccurs="0"/>
<xs:element name="phone" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:schema>


问题是:我需要访问上面在WSDL中导入的模式声明:

 <types>
<xsd:schema>
<xsd:import namespace="http://ws.i2b.com/" schemaLocation="http://pc-i2b:8080/WSPersonLookup/WSPersonData?xsd=1" />
</xsd:schema>
</types>


通过使用XPath。我不允许直接访问架构。

有没有办法做到这一点?如果不是,是否有人知道解决方法?

亲切的问候。

最佳答案

您不能仅使用XPath来获取主XML文档(WSDL)所引用的辅助XML文档(在这种情况下为架构)。

使用XSLT,您可以使用document()函数:

<xsl:variable name="schema" select="document(/soap:definitions/soap:types/xsd:schema/xsd:import/@schemaLocation)"/>


另外,与其尝试获取导入的架构,不如获取WSDL内的架构片段-使用类似 /soap:definitions/soap:types/xsd:schema的XPath。这是一个有效的架构,将其导入 http://pc-i2b:8080/WSPersonLookup/WSPersonData?xsd=1-您应该可以直接使用它。

关于xml - 使用XPath从WSDL文件中的导入(“xsd:import”)模式获取XML元素声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14224777/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com