我有一个方法,我在该方法中接收 XmlObject 作为参数,现在我想将其转换为 java 相应的 java 对象,我必须在其他 Web 服务中传递该对象。
我已经尝试了所有可能的方法,但无法得到它。
代码:
public static boolean updateAddress_V2(XmlObject xmlObject) throws XmlException{
AlarsDataService dataService=new AlarsDataService();
CustomerV2 customerV2=CustomerV2.Factory.parse(xmlObject.toString());
com.alars.osb.java.customer.CustomerV2.Customer customerXML=customerV2.getCustomer();
}
但是当我检查 customerXML 时,它为空。
这是 XMLObject 字符串值:
<Customer_V2 xmlns="http://www.alars.com/osb/java/Customer">
<Customer>
<customerId>4</customerId>
<driverLicense>XBRT245</driverLicense>
<firstName>ALEX</firstName>
<lastName>CINTRA</lastName>
<dob>21-11-1986</dob>
<addressLine1>10 Florence St</addressLine1>
<city>BOSTON</city>
<zipCode>02148</zipCode>
</Customer>
</Customer_V2>
客户 XSD:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.alars.com/osb/java/Customer"
xmlns:tns="http://www.alars.com/osb/java/Citation" elementFormDefault="qualified">
<complexType name="Customer">
<sequence>
<element name="customerId" type="long"></element>
<element name="driverLicense" type="string"></element>
<element name="firstName" type="string"></element>
<element name="lastName" type="string"></element>
<element name="dob" type="date"></element>
<element name="addressLine1" type="string"></element>
<element name="city" type="string"></element>
<element name="zipCode" type="string"></element>
</sequence>
</complexType>
<complexType name="Customer_V2">
<sequence>
<element name="Customer">
<complexType>
<sequence>
<element name="customerId" type="long"></element>
<element name="driverLicense" type="string"></element>
<element name="firstName" type="string"></element>
<element name="lastName" type="string"></element>
<element name="dob" type="date"></element>
<element name="addressLine1" type="string"></element>
<element name="city" type="string"></element>
<element name="zipCode" type="string"></element>
</sequence>
</complexType>
</element>
</sequence>
</complexType>
</schema>
大家有什么建议吗..如何实现这一目标?
最佳答案
由于我们不知道前面的类型,因此您将 XmlObject 的架构类型更改为所需的 CustomerV2,如下所示。
CustomerV2 customerV2 = (CustomerV2)
xmlObject.changeType(CustomerV2.type);
要根据所需的 CustomerV2 架构类型检查架构类型,您可以执行以下操作。
xmlObject.schemaType().isAssignableFrom(CustomerV2 .type);
关于java - 如何将 org.apache.xmlbeans.XmlObject 转换为我的 customJavaObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20554639/