1
我期望通過使用xml-path來跳過需要忽略的元素,但它似乎並沒有這樣做。我錯過了什麼嗎?eclipselink moxy xml-path綁定文件跳過元素
應該忽略嵌套元素 「responseHeader」
錯誤:
Caused by: org.xml.sax.SAXParseException: unexpected element (uri:"", local:"responseHeader"). Expected elements are <{}response>
at org.eclipse.persistence.internal.oxm.record.UnmarshalRecordImpl.startUnmappedElement(UnmarshalRecordImpl.java:957)
at org.eclipse.persistence.internal.oxm.record.UnmarshalRecordImpl.startElement(UnmarshalRecordImpl.java:814)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:501)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:400)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2756)
這裏的XML輸入
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="/admin/tabular.xsl"?>
<response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://atomics.aol.com/cnet-search/response.xsd">
<responseHeader>
<status>0</status>
<sql>select * from csource_WEEKBOX LIMIT 0,20</sql>
<numFields>15</numFields>
<numRecords>10</numRecords>
<QTime>0</QTime>
</responseHeader>
<responseBody>
<record>
<field type="integer">
<name>rank</name>
<value>1</value>
</field>
<field type="integer">
<name>movieid</name>
<value>143966</value>
</field>
<field type="integer">
<name>mf_mid</name>
<value>58759</value>
</field>
<field type="string">
<name>movietitle</name>
<value>Prisoners</value>
</field>
<field type="integer">
<name>previous</name>
<value>0</value>
</field>
<field type="integer">
<name>gross</name>
<value>21430000</value>
</field>
<field type="integer">
<name>grosschange</name>
<value>0</value>
</field>
<field type="integer">
<name>number</name>
<value>3260</value>
</field>
<field type="integer">
<name>numberchange</name>
<value>0</value>
</field>
<field type="integer">
<name>average</name>
<value>6574</value>
</field>
<field type="integer">
<name>cume</name>
<value>21430000</value>
</field>
<field type="integer">
<name>weeks</name>
<value>1</value>
</field>
<field type="integer">
<name>batchNumber</name>
<value>104323</value>
</field>
<field type="string">
<name>rowStatus</name>
<value>I</value>
</field>
<field type="date">
<name>updateDateTime</name>
<value>2013-09-24 11:08:34</value>
</field>
</record>
<record>
...
綁定文件:
<?xml version="1.0"?>
<xml-bindings
xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
version="2.1" package-name="com.dao">
<java-types>
<java-type name="DaoResult">
<xml-root-element name="response"/>
<xml-type prop-order="results"/>
<java-attributes>
<xml-element java-attribute="results" xml-path="responseBody/record" type="com.aol.pxy.movies.model.WeekBox" container-type="java.util.List"/>
<xml-transient java-attribute="totalCount"/>
<xml-transient java-attribute="cachedTime"/>
<xml-transient java-attribute="firstResult"/>
<xml-transient java-attribute="inputQuery"/>
<xml-transient java-attribute="paginationHandle"/>
</java-attributes>
</java-type>
</java-types>
</xml-bindings>
C型姑娘:
public class DaoResult<T> extends AbstractModel implements Serializable {
private static final long serialVersionUID = -6369563906973225250L;
@XmlTransient
private String inputQuery;
@Deprecated
private Integer count = -1;
private Integer totalCount;
private List<T> results;
private String paginationHandle;
private Date cachedTime = new Date();