2009-03-18 2 views
4

요청 및 응답을위한 일부 계층 적 데이터를 계층 적 XML의 단일 문자열로 압축하는 일부 고대 웹 서비스에 연결해야하는 프로젝트 작업 중입니다.XSD 스키마에서 C# 코드를 생성 할 때 배열에 "항목"이외의 이름을 갖게하려면 어떻게해야합니까?

필자는 xsd.exe를 사용하여 샘플 요청 및 응답 XML 조각에서 XSD를 생성하고 가능한 경우 최상의 정의가되도록 수정했으며 xsd.exe를 다시 사용하여 C# 개체를 생성했습니다. 그런 다음 웹 서비스를 호출하는 관리자는 강력하게 유형이 지정된 요청 객체를 매개 변수로 가져 와서 문자열로 직렬화하여 호출을 만들고 응답을 문자열로 다시 가져온 다음 강력한 형식의 응답 객체로 역 직렬화하여 반환합니다.

문자열리스트가있는 경우 xs : string 요소의 무제한 xs : 선택의 복잡한 유형으로 간주하는 유효한 XSD를 가질 수 있으며 문자열 배열로 간단히 deserialize됩니다. 멋지게 처리하기 쉽습니다. 성가신 문제는 어떤 이유로 든 문자열 배열을 "Items"이외의 다른 것으로 호출하는 방법이없는 것 같습니다. 상관 없음 무엇 스키마에 추가하면 xsd.exe에 다른 이름을 쓸 수 없습니다.

<?xml version="1.0" encoding="utf-8"?> 
<xs:schema id="AccountStatusRequest" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> 
    <xs:element name="AccountStatusRequest"> 
     <xs:complexType> 
      <xs:choice minOccurs="0" maxOccurs="unbounded" id="AccountRowIDs"> 
       <xs:element nillable="true" type="xs:string" id="AccountRowID" name="AccountRowID"/> 
      </xs:choice> 
     </xs:complexType> 
    </xs:element> 
</xs:schema> 

그리고 그 결과 클래스 :

public partial class AccountStatusRequest { 

    private string[] itemsField; 

    [System.Xml.Serialization.XmlElementAttribute("AccountRowID", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=true)] 
    public string[] Items { 
     get { 
      return this.itemsField; 
     } 
     set { 
      this.itemsField = value; 
     } 
    } 
} 

나는 거의 모든 MSDATA를 추가 시도했다 : 여기

는 예를 들어 XSD 스키마의 선택과 내부 요소 모두에 인텔리의 속성 아무 것도 차이를 만들지 않습니다. 그냥 인수를 위해서

, 나는 그 문자열 배열의 이름을 사용하도록 강제 있는지, 그 복합 타입에 몇 가지 추가 유사한 선택을 추가, 대신 그것은 Items1 항목, 준 , Items2 ...

정말 그것은 단지 문자열을 보유하고 자신의 형의 배열하고 싶지 않지만, 나는 또한 정말 "항목라고 떠나고 싶지 않아 "(xsd에 THOSE를 추가하는 방법을 아는 사람이 xml 주석을 쓰지 않고?), 더 구체적인 이름이 있어야합니다. 그리고 웹 서비스 스키마가 변경 될 때마다 XSD를 변경 한 다음 클래스를 다시 생성하는 것이므로 원하는 워크 플로로 수동으로 변경할 수 없습니다.

이것은 xsd.exe가 지원해야하는 것들 중 하나와 같습니다. 내가 빠진 것이 있습니까? 어떻게 든 다른 접근 방식을 취해야합니까? 아니면 내가 대신 사용할 수있는 대안적인 도구가 덜 절름발이입니까?

답변

-1

편집 순서로 선택을 변경 시도하고/최대가 AccountRowID 요소에서 발생하는 분을 넣어 : 죄송 어떻게 든 이전의 대답을 놓친 - 그것은 나를 위해 일한 - 여기 내가 사용 스키마와이야 결과. 저의 원래 답변도 적절할 수 있습니다.

<?xml version="1.0" encoding="utf-8"?> 
<xs:schema id="AccountStatusRequest" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> 
    <xs:element name="AccountStatusRequest" msdata:ColumnName="AccountList"> 
     <xs:complexType> 
      <xs:sequence minOccurs="0" maxOccurs="unbounded" id="AccountRowIDs"> 
       <xs:element nillable="true" type="xs:string" id="AccountRowID" name="AccountRowID"/> 
      </xs:sequence> 
     </xs:complexType> 
    </xs:element> 
</xs:schema> 

public partial class AccountStatusRequest { 

    private string[] accountRowIDField; 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute("AccountRowID", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=true)] 
    public string[] AccountRowID { 
     get { 
      return this.accountRowIDField; 
     } 
     set { 
      this.accountRowIDField = value; 
     } 
    } 
} 

안녕하세요이, I 형 simpleType는 원하는 출력 (a라는 문자열 배열)를 생성하는 속성에 의해 감싸 목록 선택 치환 다소 스키마를 변경. 그러나 변경된 스키마가 현재 수행중인 작업에 적합한 지 여부는 확실하지 않습니다.

<?xml version="1.0" encoding="utf-8"?> 
<xs:schema id="AccountStatusRequest" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> 
    <xs:element name="AccountStatusRequest" msdata:ColumnName="AccountList"> 
     <xs:complexType> 
      <xs:attribute name="AccountRowIDs"> 
      <xs:simpleType id="AccountRowID" > 
       <xs:list itemType="xs:string">     
       </xs:list> 
      </xs:simpleType>  
      </xs:attribute> 
     </xs:complexType> 
    </xs:element> 
</xs:schema> 

.. 그리고 xsd.exe으로 실행 후 출력 : 여기에

수정 된 스키마의

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

    private string[] accountRowIDsField; 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute()] 
    public string[] AccountRowIDs { 
     get { 
      return this.accountRowIDsField; 
     } 
     set { 
      this.accountRowIDsField = value; 
     } 
    } 
} 
0

저는 이것이 xsd.exe의 한계라고 확신합니다. 당신은 다른 방향 (class => xml/xsd)으로 커스텀 결과를 얻을 수있다. 그러나 그것은 당신에게별로 도움이되지 않는다. 죄송합니다.

7

...

+1

나는이 대답을 놓친 방법을 잘 모르는 죄송합니다 - 그것은 나를 일을 위해 일 – RobS

관련 문제