gpt4 book ai didi

java - 无法解析与前缀 'diffgr' 关联的命名空间。在 Castor 中

转载 作者:行者123 更新时间:2023-12-01 04:56:24 26 4
gpt4 key购买 nike

我正在获取以下 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)

请帮我解决这个问题

最佳答案

这个 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 与默认命名空间相同。或者这是您的 XML 中的错误?

关于java - 无法解析与前缀 'diffgr' 关联的命名空间。在 Castor 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14059411/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com