2013-08-05 51 views
1

我有一個非常大的XML與許多嵌套標籤,我生成了一個Java類。JAXB xml標籤文件以數字開頭,可能嗎?

一個標籤與數<3DSecure></3DSecure>

我不得不手動設置只有這個標籤,在Java我映射到threeDSecure開始。

我知道這是違反XML約定,但可以重寫此檢查嗎?否則,我將不得不放棄JAXB並手動設置xml,因爲我不控制期望這個XML的API。

在解組/編組我得到的錯誤:

[org.xml.sax.SAXParseException: The content of elements must consist of well-formed character data or markup.] 
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:315) 
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.createUnmarshalException(UnmarshallerImpl.java:505) 
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:206) 
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:173) 
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:137) 
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:142) 
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:151) 
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:169) 

回答

0

綁定使用@XmlElement標註的屬性Java類財產

@XmlRootElement 
public class JAXBModel { 

    @XmlElement(name="3DSecure") 
    public String threeDSecure; 

    // ... 
} 
1

可以使用-nv標誌,不要禁用驗證從XML模式生成類時的XML模式。

XJC呼叫

xjc -nv schema.xsd 

XML架構(schema.xsd)

<?xml version="1.0" encoding="UTF-8"?> 
<schema 
    xmlns="http://www.w3.org/2001/XMLSchema" 
    targetNamespace="http://www.example.org/schema" 
    xmlns:tns="http://www.example.org/schema" 
    elementFormDefault="qualified"> 

    <complexType name="foo"> 
     <sequence> 
      <element name="3DSecure" type="string"/> 
     </sequence> 
    </complexType> 

</schema> 

生成的類(美孚)

package org.example.schema; 

import javax.xml.bind.annotation.*; 

@XmlAccessorType(XmlAccessType.FIELD) 
@XmlType(name = "foo", propOrder = {"_3DSecure"}) 
public class Foo { 

    @XmlElement(name = "3DSecure", required = true) 
    protected String _3DSecure; 

    public String get3DSecure() { 
     return _3DSecure; 
    } 

    public void set3DSecure(String value) { 
     this._3DSecure = value; 
    } 

} 
+0

感謝你的努力,我HAV e已經試過它沒有用。但絕不會導致API有一個過時的文檔,我不需要這個功能:) – braincell

+0

@braincell - 奇怪聽到它不適合你。很高興聽到它沒有阻止你。 –

相關問題