我是解组XML的新手,但我陷入了包含xmlns和xsd部分的xml。这是我的xml。
<?xml version="1.0" encoding="utf-8"?>
<RS xmlns="urn:schemas-microsoft-com:xml-analysis:rowset">
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:saw-sql="urn:saw-sql" targetNamespace="urn:schemas-microsoft-com:xml-analysis:rowset">
<xsd:complexType name="R">
<xsd:sequence>
<xsd:element name="C0" type="xsd:string" minOccurs="0" maxOccurs="1" saw-sql:type="varchar" />
<xsd:element name="C2" type="xsd:double" minOccurs="0" maxOccurs="1" saw-sql:type="double" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
<R>
<C0>Record 1</C0>
<C1>AUSTRALIA</C1>
<C2>2018</C2>
</R>
<R>
<C0>Record 2</C0>
<C1>AFRICA</C1>
<C2>2018</C2>
</R>
</RS>
当我尝试解组时,出现以下错误。
Message is unexpected element (uri:"http://www.w3.org/2001/XMLSchema", local:"schema"). Expected elements are <{}R>
Column is 247 at line number 1
Message is unexpected element (uri:"urn:schemas-microsoft-com:xml- analysis:rowset", local:"R"). Expected elements are <{}R>
Column is 548 at line number 1
Message is unexpected element (uri:"urn:schemas-microsoft-com:xml-analysis:rowset", local:"R"). Expected elements are <{}R>
Column is 611 at line number 1
如果我删除了命名空间和xsd部分,并相应地调整了批注,那么它将正常工作。
我带注释的对象:
@XmlRootElement(name = "R")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "R", propOrder = {
"c0",
"c1",
"c2"
})
public class MyElem {
@XmlElement(name = "C0")
protected String c0;
@XmlElement(name = "C1")
protected String c1;
@XmlElement(name = "C2")
protected Double c2;
...
}
@XmlRootElement(name = "RS", namespace = "urn:schemas-microsoft-com:xml-analysis:rowset" )
@XmlAccessorType(XmlAccessType.NONE)
public class CounterReportElementList implements Serializable {
private static final long serialVersionUID = -866371045985138665L;
@XmlElement(name = "R")
List<MyList> myList = new ArrayList<R>();
public List<MyList> getMyList() {
return myList;
}
public void setCounterReportElementList(List<CounterReportElement> counterReportElementList) {
this.counterReportElementList = counterReportElementList;
}
}
任何帮助我们都将不胜感激,因为它已经花了太长时间了!