我正在关注xml
<root xmlns="urn:schemas-microsoft-com:xml-diffgram-v1">
<FromCity xmlns="" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
diffgr:id="FromCity1" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
msdata:rowOrder="0">
<StateID>1073</StateID>
<State>Ahmedabad</State>
</FromCity>
<FromCity xmlns="" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
diffgr:id="FromCity2" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
msdata:rowOrder="1">
<StateID>1051</StateID>
<State>Amritsar</State>
</FromCity>
<FromCity xmlns="" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
diffgr:id="FromCity3" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
msdata:rowOrder="2">
<StateID>1024</StateID>
<State>Bangalore</State>
</FromCity>
<FromCity xmlns="" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
diffgr:id="FromCity4" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
msdata:rowOrder="3">
<StateID>1074</StateID>
<State>Bhopal</State>
</FromCity>
<FromCity xmlns="" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
diffgr:id="FromCity5" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
msdata:rowOrder="4">
<StateID>1034</StateID>
<State>Chandigarh</State>
</FromCity>
<FromCity xmlns="" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
diffgr:id="FromCity6" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
msdata:rowOrder="5">
<StateID>1025</StateID>
<State>Chennai</State>
</FromCity>
<FromCity xmlns="" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
diffgr:id="FromCity7" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
msdata:rowOrder="6">
<StateID>1075</StateID>
<State>Dehradun</State>
</FromCity>
<FromCity xmlns="" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
diffgr:id="FromCity8" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
msdata:rowOrder="7">
<StateID>1001</StateID>
<State>Delhi / NCR</State>
</FromCity>
<FromCity xmlns="" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
diffgr:id="FromCity9" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
msdata:rowOrder="8">
<StateID>1062</StateID>
<State>Gwalior</State>
</FromCity>
<FromCity xmlns="" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
diffgr:id="FromCity10" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
msdata:rowOrder="9">
<StateID>1011</StateID>
<State>Hyderabad</State>
</FromCity>
<FromCity xmlns="" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
diffgr:id="FromCity11" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
msdata:rowOrder="10">
<StateID>1035</StateID>
<State>Jaipur</State>
</FromCity>
<FromCity xmlns="" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
diffgr:id="FromCity12" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
msdata:rowOrder="11">
<StateID>1063</StateID>
<State>Jhansi</State>
</FromCity>
<FromCity xmlns="" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
diffgr:id="FromCity13" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
msdata:rowOrder="12">
<StateID>1036</StateID>
<State>Jodhpur</State>
</FromCity>
<FromCity xmlns="" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
diffgr:id="FromCity14" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
msdata:rowOrder="13">
<StateID>1064</StateID>
<State>Khajuraho</State>
</FromCity>
<FromCity xmlns="" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
diffgr:id="FromCity15" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
msdata:rowOrder="14">
<StateID>1026</StateID>
<State>Kolkata</State>
</FromCity>
<FromCity xmlns="" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
diffgr:id="FromCity16" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
msdata:rowOrder="15">
<StateID>1072</StateID>
<State>Ludhiana</State>
</FromCity>
<FromCity xmlns="" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
diffgr:id="FromCity17" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
msdata:rowOrder="16">
<StateID>1010</StateID>
<State>Mumbai</State>
</FromCity>
<FromCity xmlns="" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
diffgr:id="FromCity18" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
msdata:rowOrder="17">
<StateID>1065</StateID>
<State>Orchha</State>
</FromCity>
<FromCity xmlns="" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
diffgr:id="FromCity19" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
msdata:rowOrder="18">
<StateID>1016</StateID>
<State>Pune</State>
</FromCity>
<FromCity xmlns="" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
diffgr:id="FromCity20" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
msdata:rowOrder="19">
<StateID>1037</StateID>
<State>Udaipur</State>
</FromCity>
</root>
以下是我的映射
<class name="pkg.SourceCityWheelzResponse">
<description xmlns="">Default mapping for class
GhraPayOrderRequest
</description>
<map-to xml="root" ns-prefix="diffgr"
ns-uri="urn:schemas-microsoft-com:xml-diffgram-v1" />
<field name="fromCities" type="pkg.FromCity" collection="arraylist">
<bind-xml name="root:FromCity" node="element"
xmlns:root="urn:schemas-microsoft-com:xml-diffgram-v1" />
</field>
</class>
<class name="pkg.FromCity">
<description xmlns="">Default mapping for class
GhraPayOrderRequest
</description>
<map-to xml="FromCity" ns-prefix="diffgr"
ns-uri="urn:schemas-microsoft-com:xml-diffgram-v1" />
<field name="stateId" type="java.lang.String">
<bind-xml name="FromCity:StateID" node="element"
xmlns:FromCity="urn:schemas-microsoft-com:xml-diffgram-v1" />
</field>
<field name="state" type="java.lang.String">
<bind-xml name="FromCity:State" node="element"
xmlns:FromCity="urn:schemas-microsoft-com:xml-diffgram-v1" />
</field>
</class>
但我收到了以下错误
org.springframework.oxm.UnmarshallingFailureException: Castor unmarshalling exception; nested exception is org.exolab.castor.xml.MarshalException: The namespace associated with the prefix 'diffgr' could not be resolved.
at org.springframework.oxm.castor.CastorMarshaller.convertCastorException(CastorMarshaller.java:675)
at org.springframework.oxm.castor.CastorMarshaller.unmarshalDomNode(CastorMarshaller.java:554)
at org.springframework.oxm.support.AbstractMarshaller.unmarshalDomSource(AbstractMarshaller.java:307)
at org.springframework.oxm.support.AbstractMarshaller.unmarshal(AbstractMarshaller.java:125)
请帮我解决这个问题
答案 0 :(得分:0)
这个XML最多是奇怪的...你是否尝试过将名称空间声明移动到根元素,如下所示:
<root xmlns="urn:schemas-microsoft-com:xml-diffgram-v1" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<FromCity diffgr:id="FromCity1" msdata:rowOrder="0">
<StateID>1073</StateID>
<State>Ahmedabad</State>
</FromCity>
</root>
实际上,您甚至不需要额外的diffgr
命名空间,因为它的URN
与默认命名空间的{{1}}相同。或者这是你的XML中的错误吗?
答案 1 :(得分:0)
您需要在根标记中指定命名空间模式:
<root xmlns:sql="urn:schemas-microsoft-com:xml-sql" sql:mapping-schema="DiffGramSchema.xml">
有关XML的示例,请参阅DiffGram Examples。