简体   繁体   English

用名称空间反序列化xml数组

[英]deserialize xml array with namespace

I need to deserialize this xml 我需要反序列化此xml

<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <SOAP-ENV:Body>
        <ns1:estraiListaAttiFascicoloResponse xmlns:ns1="urn:BEAFascicoloInformatico-distr">
            <return xmlns:ns2="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:Array" ns2:arrayType="ns1:BEADocumentoFascicoloVO[2]">
                <item xsi:type="ns1:BEADocumentoFascicoloVO">
                    <annoFascicolo xsi:type="xsd:string">1998</annoFascicolo>
                </item>
                <item xsi:type="ns1:BEADocumentoFascicoloVO">
                    <annoFascicolo xsi:type="xsd:string">1998</annoFascicolo>
                </item>
            </return>
        </ns1:estraiListaAttiFascicoloResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

i have tried with this classes: 我已经尝试过此类:

[XmlType(AnonymousType = true, Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
[XmlRoot(Namespace = "http://schemas.xmlsoap.org/soap/envelope/", IsNullable = false)]
public class Envelope
{
    public EnvelopeBody Body { get; set; }

    [XmlAttribute(Form = XmlSchemaForm.Qualified)]
    public string encodingStyle { get; set; }
}

[XmlType(AnonymousType = true, Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public class EnvelopeBody
{
    [XmlElement(Namespace = "urn:BEAFascicoloInformatico-distr")]
    public estraiListaAttiFascicoloResponse estraiListaAttiFascicoloResponse { get; set; }
}

/// <remarks/>
[XmlType(AnonymousType = true, Namespace = "urn:BEAFascicoloInformatico-distr")]
[XmlRoot(Namespace = "urn:BEAFascicoloInformatico-distr", IsNullable = false)]
public class estraiListaAttiFascicoloResponse
{
    [XmlElement(Namespace = "")]
    public @return @return { get; set; }
}

[XmlType(AnonymousType = true)]
[XmlRoot(Namespace = "", IsNullable = false)]
public class @return
{
    [XmlElement("item")]
    public returnItem[] item { get; set; }

    [XmlAttribute(Form = XmlSchemaForm.Qualified, Namespace = "http://schemas.xmlsoap.org/soap/encoding/")]
    public string arrayType { get; set; }
}

[XmlType(AnonymousType = true)]
public class returnItem
{
    public ushort annoFascicolo { get; set; }
}

and this code 和这段代码

var serializer = new XmlSerializer(typeof(Envelope));

var sw = new StringReader(xmlText);

using (var xmlTextReader = XmlReader.Create(sw))
{
   var converted = serializer.Deserialize(xmlTextReader);
}

but i receive this error at runtime 但我在运行时收到此错误

Additional information: There is an error in XML document (5, 5). 附加信息:XML文档(5、5)中有错误。

and the inner exception in this 和内部异常

The specified type was not recognized: name='Array', Namespace=' http://schemas.xmlsoap.org/soap/encoding/ ', at . 无法识别指定的类型:name ='Array',Namespace =' http://schemas.xmlsoap.org/soap/encoding/ ',位于。

but if i add the namespace " http://schemas.xmlsoap.org/soap/encoding/ " to @return property of estraiListaAttiFascicoloResponse class the exception disappears but don't deserialize array items anyway 但是,如果我在estraiListaAttiFascicoloResponse类的@return属性中添加名称空间“ http://schemas.xmlsoap.org/soap/encoding/ ”,则该异常消失,但无论如何都不反序列化数组项

Can someone help me? 有人能帮我吗?

Thanks 谢谢

I do not see a resolve for namespace ns1 . 我看不到名称空间ns1的解决方案。

You could also check xml validity using the great free and open source tool XML Notepad , to be downloaded from Microsoft. 您还可以使用免费的开放源代码工具XML Notepad检查xml的有效性,该工具可从Microsoft下载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM