2010-12-27 8 views
0

I 다음 스키마 있습니다는 복합 유형 요소가 null 인 역 직렬화

<?xml version="1.0"?> 
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tipos="http://www.ginfes.com.br/tipos_v03.xsd" targetNamespace="http://www.ginfes.com.br/servico_consultar_situacao_lote_rps_resposta_v03.xsd" 
      xmlns="http://www.ginfes.com.br/servico_consultar_situacao_lote_rps_resposta_v03.xsd" attributeFormDefault="unqualified" elementFormDefault="qualified"> 
<xsd:import schemaLocation="tipos_v03.xsd" namespace="http://www.ginfes.com.br/tipos_v03.xsd" /> 
<xsd:element name="ConsultarSituacaoLoteRpsResposta"> 
    <xsd:complexType> 
    <xsd:choice> 
    <xsd:sequence> 
    <xsd:element name="NumeroLote" type="tipos:tsNumeroLote" minOccurs="1" maxOccurs="1"/> 
    <xsd:element name="Situacao" type="tipos:tsSituacaoLoteRps" minOccurs="1" maxOccurs="1"/> 
    </xsd:sequence> 
    <xsd:element ref="tipos:ListaMensagemRetorno" minOccurs="1" maxOccurs="1"/> 
    </xsd:choice> 
    </xsd:complexType> 
</xsd:element> 
</xsd:schema> 

및 다음 클래스 :

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://www.ginfes.com.br/servico_consultar_situacao_lote_rps_envio_v03.xsd")] 
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://www.ginfes.com.br/servico_consultar_situacao_lote_rps_envio_v03.xsd", IsNullable = false)] 
public partial class ConsultarSituacaoLoteRpsEnvio 
{ 
    [System.Xml.Serialization.XmlElementAttribute(Order = 0)] 
    public tcIdentificacaoPrestador Prestador { get; set; } 

    [System.Xml.Serialization.XmlElementAttribute(Order = 1)] 
    public string Protocolo { get; set; } 
} 

사용하여 다음 코드 객체 직렬화하기 :

XmlSerializer respSerializer = new XmlSerializer(typeof(ConsultarSituacaoLoteRpsResposta)); 
StringReader reader = new StringReader(resp); 
ConsultarSituacaoLoteRpsResposta respModel = (ConsultarSituacaoLoteRpsResposta)respSerializer.Deserialize(reader); 

오류가 발생하지 않지만 개체의 속성이 null이면 아무도 어떤 일이 발생했는지 알 수 있습니까?

답변

1

글쎄, 난 네가 XML 네임 스페이스를 무시하고있을 수도 있다고 생각한다.

<xsd:schema 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:tipos="http://www.ginfes.com.br/tipos_v03.xsd" 
    targetNamespace="http://www.ginfes.com.br/servico_consultar_situacao_lote_rps_resposta_v03.xsd" 
    xmlns="http://www.ginfes.com.br/servico_consultar_situacao_lote_rps_resposta_v03.xsd" 
    attributeFormDefault="unqualified" elementFormDefault="qualified"> 

xmlns="http://www.ginfes.com.br/servico_consultar_situacao_lote_rps_resposta_v03.xsd" 속성을 참조 : XSD에서는 기본 XML 네임 스페이스를 정의? 이는 기본 XML 네임 스페이스를 정의합니다. 당신이 당신의 데이터를 역 직렬화에 갈 때

그래서, 당신은 또한 디시리얼라이저에 그 기본 XML 네임 스페이스를 제공해야합니다 :

XmlSerializer respSerializer = new 
    XmlSerializer(typeof(ConsultarSituacaoLoteRpsResposta), 
       "http://www.ginfes.com.br/servico_consultar_situacao_lote_rps_resposta_v03.xsd"); 
StringReader reader = new StringReader(resp); 
ConsultarSituacaoLoteRpsResposta respModel = 
    (ConsultarSituacaoLoteRpsResposta)respSerializer.Deserialize(reader); 

는 XML의 기본 네임 스페이스를 포함하여 그 일을합니까?

+0

나는 스키마에 대한 지배권을 가지고 있으며, XML 만 수신하고 처리한다. 네임 스페이스를 제거하려고 노력할 것이다. 감사합니다. – Jean

+0

괜찮습니다. 클래스, tks에 네임 스페이스가 없음 – Jean

1

ConsultarSituacaoLoteRpsResposta! = ConsultarSituacaoLoteRpsEnvio

당신은 쉽게 이름을 사용할 수도

, 그것은 (XmlReaderSettings 그것을 설정 지원) 즉시 문제를 식별 할 자리에 :

또한 XML 유효성 검사를 사용한다 힘들었다. 그리고 여기에 불일치가 있기 때문에 코드가 XSD에서 직접 생성되었는지 확인하십시오.

+0

그는 [ConsultarSituacaoLoteRpsResposta] 유형으로 비 직렬화하려고합니다. **는 ** XML 스키마에 정의 된 **이라고 말하고 싶습니다. –

+1

흠, 당신 말이 맞을지도 모릅니다. 어쨌든, 그는 다른 것을위한 스키마를 게시했기 때문에 완전히 엉망입니다. – fejesjoco