2009-12-03 2 views
0

xsd 유틸리티를 사용하여 * .xsd 파일에서 * .cs 파일을 생성했습니다. 클래스의 인스턴스를 serialize하여 생성 된 클래스에서 xml을 생성하고 싶습니다. 직렬화되는 객체를 만들려면이 코드를 실행.net xml serialization

<header> 
    <br xsi:type="xsd:string" /> 
    <br xsi:type="xsd:string" /> 
    <br xsi:type="xsd:string" /> 
    <br xsi:type="xsd:string" /> 
</header> 

<header> 
    <br xsi:nil="true" /> 
    <br xsi:nil="true" /> 
    <br xsi:nil="true" /> 
    <br xsi:nil="true" /> 
</header> 

: 여기

<header> 
    <br/> 
    <br/> 
    <br/> 
    <br/> 
</header> 

내가 점점 오전없는 깨끗한 출력의 두 가지 예 :이 같은 '깨끗한'출력을 얻을 방법이 있나요 : 여기

KioskSchema.applicationScreens screenContainer = new KioskSchema.applicationScreens(); 
//screenContainer.header = new object[] { null, null, null, null };          //didn’t work 
//screenContainer.header = new string[] { "<br/>", "<br/>", "<br/>", "<br/>"};    //didn’t work 
screenContainer.header = new string[] { string.Empty, string.Empty, string.Empty, string.Empty };  //didn’t work 

은 XSD 유틸리티에서 생성 된 클래스

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)] 
public partial class applicationScreens 
{ 

     private object[] headerField; 

     private applicationScreensScreen[] screenField; 

     /// <remarks/> 
     [System.Xml.Serialization.XmlArrayItemAttribute("br", IsNullable = false)] 
     public object[] header 
     { 
       get 
       { 
        return this.headerField; 
       } 
       set 
       { 
        this.headerField = value; 
       } 
     } 
} 
,

답변

0

원하지 않는 경우 네임 스페이스가 추가 된 것처럼 보입니다. 생성 된 .cs 파일에

변경 XmlArrayItemAttribute는 - null의 네임 스페이스 = 또는 네임 스페이스 = String.Empty로를 추가 : 추가되는 기본 네임 스페이스를 오버라이드 (override) 할 필요가

[System.Xml.Serialization.XmlArrayItemAttribute("br", IsNullable = false, Namespace = string.Empty)] 

.

MSDN의 XmlArrayItemAttribute에 대한 자세한 내용을 읽어보십시오.

0

xsd 유틸리티는 헤더 propery의 유형을 설정하고 private 멤버를 object []로 변경할 수 있습니다. 문자열을 []로 수동 변경하면 문제가 해결되었습니다!

public partial class applicationScreens 
{ 

    private string[] headerField; 

    private applicationScreensScreen[] screenField; 

    /// <remarks/> 
    [System.Xml.Serialization.XmlArrayItemAttribute("br", Namespace="", IsNullable = false)] 
    public string[] header 
    { 
     get 
     { 
      return this.headerField; 
     } 
     set 
     { 
      this.headerField = value; 
     } 
    } 

실제 출력 :

<header> 
    <br /> 
    <br /> 
    <br /> 
    <br /> 
</header>