XML文档是否可以包含2个具有相同ID的元素?

时间:2018-07-19 02:27:58

标签: android xml soap ksoap2 ebxml

我正在尝试使用kSoap2将Android应用程序与SOAP Web服务集成。我设法发出一个请求并获取一些数据,但是当响应解析发生时,我有以下RuntimeException:

W/System.err: java.lang.RuntimeException: double ID
                  at org.ksoap2.serialization.SoapSerializationEnvelope.resolveReference(SoapSerializationEnvelope.java:462)
                  at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:439)
                  at com.easywsdl.exksoap2.serialization.ExSoapSerializationEnvelope.read(ExSoapSerializationEnvelope.java:86)
                  at org.ksoap2.serialization.SoapSerializationEnvelope.readUnknown(SoapSerializationEnvelope.java:304)
                  at com.easywsdl.exksoap2.serialization.ExSoapSerializationEnvelope.readUnknown(ExSoapSerializationEnvelope.java:93)
                  at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:434)
                  at com.easywsdl.exksoap2.serialization.ExSoapSerializationEnvelope.read(ExSoapSerializationEnvelope.java:86)
                  at org.ksoap2.serialization.SoapSerializationEnvelope.readUnknown(SoapSerializationEnvelope.java:304)
                  at com.easywsdl.exksoap2.serialization.ExSoapSerializationEnvelope.readUnknown(ExSoapSerializationEnvelope.java:93)
                  at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:434)
                  at com.easywsdl.exksoap2.serialization.ExSoapSerializationEnvelope.read(ExSoapSerializationEnvelope.java:86)
                  at org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(SoapSerializationEnvelope.java:146)
W/System.err:     at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:140)
                  at com.easywsdl.exksoap2.mtom.MTOMSoapSerializationEnvelope.parse(MTOMSoapSerializationEnvelope.java:70)
                  at org.ksoap2.transport.Transport.parseResponse(Transport.java:129)
                  at org.ksoap2.transport.HttpTransportSE.parseResponse(HttpTransportSE.java:304)
                  at com.easywsdl.exksoap2.transport.AdvancedHttpsTransportSE.parseResponse(AdvancedHttpsTransportSE.java:35)
                  at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:276)
                  at com.easywsdl.exksoap2.transport.AdvancedHttpsTransportSE.call(AdvancedHttpsTransportSE.java:51)
                  at be.brusafe.brusafeplus.xds.iti18.DocumentRegistry_Binding_Soap12.sendRequest(DocumentRegistry_Binding_Soap12.java:102)
                  at be.brusafe.brusafeplus.xds.iti18.DocumentRegistry_Binding_Soap12.execute(DocumentRegistry_Binding_Soap12.java:181)
                  at be.brusafe.brusafeplus.xds.iti18.DocumentRegistry_Binding_Soap12.DocumentRegistry_RegistryStoredQuery(DocumentRegistry_Binding_Soap12.java:147)
                  at be.brusafe.brusafeplus.xds.iti18.DocumentRegistry_Binding_Soap12$2.Func(DocumentRegistry_Binding_Soap12.java:168)
                  at be.brusafe.brusafeplus.xds.iti18.DocumentRegistry_Binding_Soap12$2.Func(DocumentRegistry_Binding_Soap12.java:166)
                  at be.brusafe.brusafeplus.xds.iti18.DocumentRegistry_Binding_Soap12$3.doInBackground(DocumentRegistry_Binding_Soap12.java:218)
                  at be.brusafe.brusafeplus.xds.iti18.DocumentRegistry_Binding_Soap12$3.doInBackground(DocumentRegistry_Binding_Soap12.java:207)
                  at android.os.AsyncTask$2.call(AsyncTask.java:333)
                  at java.util.concurrent.FutureTask.run(FutureTask.java:266)
                  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
                  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
                  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
                  at java.lang.Thread.run(Thread.java:764)

实际上,在响应中,我有2个元素,它们的类型不同,但其id属性的值相同。

<ExtrinsicObject home="urn:oid:1.3.6.1.4.1.48336.1" id="urn:uuid:3468543d-5033-4d6b-86a5-f8a52fd0070e"
    isOpaque="false"
    lid="urn:uuid:3468543d-5033-4d6b-86a5-f8a52fd0070e"
    mimeType="text/xml"
    objectType="urn:uuid:7edca82f-054d-47f2-a032-9b2a5b5186c1"
    status="urn:oasis:names:tc:ebxml-regrep:StatusType:Approved">

并且:

<ObjectRef home="urn:oid:1.3.6.1.4.1.48336.1"
    id="urn:uuid:3468543d-5033-4d6b-86a5-f8a52fd0070e" />

我不是自己开发SOAP Web服务,所以我告诉开发人员,我不知道那是不可能的,因为我认为XML规范本身说ID必须是唯一的。这就是他们的回答:

  

在这种情况下,可能是因为方言“ id”不是数据   类型为“ ID”,但数据类型为“ URN”。占卜者指的是   注册表中的唯一ID,它不是其自身元素的ID。   在此应用程序中,我们使用ebXML注册信息模型   默认为3.0版。您可以在以下位置找到更多信息和示例   绿洲文件:   https://docs.oasis-open.org/regrep/v3.0/specs/regrep-rim-3.0-os.pdf

现在我很困惑。那么在XML文档中是否可以有多个具有相同ID的元素?如果是的话,有没有一种方法可以配置kSOAP2使其忽略该双重ID?

1 个答案:

答案 0 :(得分:0)

具有重复ID值的XML文档格式正确,但无效。如果XML解析器作为非验证解析器运行,它将成功读取此类文档。

我不知道您要使用哪个库来进行解析,所以我不知道是否可以禁用验证或忽略验证错误。