2016-04-11 4 views
0

私はXMLから逆シリアル化してクラスの競合の問題に遭遇しています。XMLクラスの競合を逆シリアル化する

すでに私のコードで

、私はContentType実際Microsoft.SharePoint.Client.ContentTypeに住んでいるクラスまたはMicrosoft.SharePoint.Client.WebWebクラスの生活への参照を作ることでしょう。私のXMLで

例えば

var parentCtType = (from c in rootWeb.ContentTypes 
             where c.Name.ToLower().Trim() == ctParent.ToLower().Trim() 
             select c).FirstOrDefault(); 

それは次のような読み:私のクラスで

<ContentTypes> 
      <ContentType Name="D Base Document Set" Parent="Document Set" Group="*D"> 
       <ContentTypeSiteColumns> 
        <Sitecolumn DisplayName="Security" StaticName="SecurityClassification" Group="*DIAColumn" Type="TaxonomyFieldType" TermStore="D" TermSet="Security Classification" DefaultValue="UNCLASSIFIED" Required="TRUE" /> 
        <Sitecolumn DisplayName="Enterprise" StaticName="Tax" Group="Enterprise Keywords Group" Type="TaxonomyFieldTypeMulti" TermStore="D" TermSet="N/A" /> 
       </ContentTypeSiteColumns> 
      </ContentType> 
      <ContentType Name="D Base Document" Parent="Document" Description="The content type from which all other document content types will inherit." Group="*D"> 
       <ContentTypeSiteColumns> 
        <Sitecolumn DisplayName="Security Classification" StaticName="SecurityClassification" Group="*D" Type="TaxonomyFieldType" TermStore="D" TermSet="Security" DefaultValue="UNCLASSIFIED" Required="TRUE" /> 
        <Sitecolumn DisplayName="Enterprise" StaticName="Tax" Group="Enterprise" Type="TaxonomyFieldTypeMulti" TermStore="D" TermSet="N/A" /> 
        <Sitecolumn DisplayName="Notes" StaticName="Notess" Description="For notes giving context to the document. Additional information can include URL link to another document." Group="*D" Type="Note" Required="FALSE" /> 
       </ContentTypeSiteColumns> 
      </ContentType> 

を私はデシリアライズよ、私はそれはしているかなり確信して(ContentTypeをし、Webと呼ばれるクラスを持っていますこの名前は、そのXMLの名前から要素を除いてデシリアライズしています)。

public class ContentType 
    { 
     [XmlAttribute] 
     public string Name; 

     [XmlAttribute] 
     public string Parent; 

     public List<Sitecolumn> ContentTypeSiteColumns; 

    } 

上記のクラスはContentType(?)と呼ばれる必要があります。これはXMLから逆シリアル化しているためです。

私は ContentTypeZのように、別の何かにデシリアライズしていますが、その後デシリアライズのプロセスが動作しないクラスを呼び出す場合消える
Error 4 'testebby.ContentType' does not contain a definition for 'FieldLinks' and no extension method 'FieldLinks' accepting a first argument of type 'testebby.ContentType' could be found (are you missing a using directive or an assembly reference?) 

私が手にエラーが似ています。

どうすれば対処できますか?それが理にかなったことを望みます。

+0

あなたの問題が解決されたことを願っています。そうでない場合は、おそらくあなたの質問を更新すると思う.... http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235 – Monty

答えて

0

あなたは、これは私はそれを行うだろうかであるXMLをデシリアライズするために探している場合....

Usings .....

using System; 
using System.Collections.Generic; 
using System.IO; 
using System.Text; 
using System.Xml; 
using System.Xml.Serialization; 

クラス.....

[XmlRoot(ElementName = "Sitecolumn")] 
public class Sitecolumn 
{ 
    [XmlAttribute(AttributeName = "DisplayName")] 
    public string DisplayName { get; set; } 
    [XmlAttribute(AttributeName = "StaticName")] 
    public string StaticName { get; set; } 
    [XmlAttribute(AttributeName = "Group")] 
    public string Group { get; set; } 
    [XmlAttribute(AttributeName = "Type")] 
    public string Type { get; set; } 
    [XmlAttribute(AttributeName = "TermStore")] 
    public string TermStore { get; set; } 
    [XmlAttribute(AttributeName = "TermSet")] 
    public string TermSet { get; set; } 
    [XmlAttribute(AttributeName = "DefaultValue")] 
    public string DefaultValue { get; set; } 
    [XmlAttribute(AttributeName = "Required")] 
    public string Required { get; set; } 
    [XmlAttribute(AttributeName = "Description")] 
    public string Description { get; set; } 
} 

[XmlRoot(ElementName = "ContentTypeSiteColumns")] 
public class ContentTypeSiteColumns 
{ 
    [XmlElement(ElementName = "Sitecolumn")] 
    public List<Sitecolumn> Sitecolumn { get; set; } 
} 

[XmlRoot(ElementName = "ContentType")] 
public class ContentType 
{ 
    [XmlElement(ElementName = "ContentTypeSiteColumns")] 
    public ContentTypeSiteColumns ContentTypeSiteColumns { get; set; } 
    [XmlAttribute(AttributeName = "Name")] 
    public string Name { get; set; } 
    [XmlAttribute(AttributeName = "Parent")] 
    public string Parent { get; set; } 
    [XmlAttribute(AttributeName = "Group")] 
    public string Group { get; set; } 
    [XmlAttribute(AttributeName = "Description")] 
    public string Description { get; set; } 
} 

[XmlRoot(ElementName = "ContentTypes")] 
public class ContentTypes 
{ 
    [XmlElement(ElementName = "ContentType")] 
    public List<ContentType> ContentType { get; set; } 
} 

コード.....

class Program 
{ 
    static void Main(string[] args) 
    { 
     string strXML = File.ReadAllText("xml.xml"); 
     byte[] bufXML = ASCIIEncoding.UTF8.GetBytes(strXML); 
     MemoryStream ms1 = new MemoryStream(bufXML); 

     // Deserialize to object 
     XmlSerializer serializer = new XmlSerializer(typeof(ContentTypes)); 
     try 
     { 
      using (XmlReader reader = new XmlTextReader(ms1)) 
      { 
       ContentTypes deserializedXML = (ContentTypes)serializer.Deserialize(reader); 

      }// put a break point here and mouse-over deserializedXML…. 
     } 
     catch (Exception ex) 
     { 
      throw; 
     } 

    } 
} 

UPDAT E 1

このXML

<ContentTypes> 
      <ContentType Name="D Base Document Set" Parent="Document Set" Group="*D"> 
       <ContentTypeSiteColumns> 
        <Sitecolumn DisplayName="Security" StaticName="SecurityClassification" Group="*DIAColumn" Type="TaxonomyFieldType" TermStore="D" TermSet="Security Classification" DefaultValue="UNCLASSIFIED" Required="TRUE" /> 
        <Sitecolumn DisplayName="Enterprise" StaticName="Tax" Group="Enterprise Keywords Group" Type="TaxonomyFieldTypeMulti" TermStore="D" TermSet="N/A" /> 
       </ContentTypeSiteColumns> 
      </ContentType> 
      <ContentType Name="D Base Document" Parent="Document" Description="The content type from which all other document content types will inherit." Group="*D"> 
       <ContentTypeSiteColumns> 
        <Sitecolumn DisplayName="Security Classification" StaticName="SecurityClassification" Group="*D" Type="TaxonomyFieldType" TermStore="D" TermSet="Security" DefaultValue="UNCLASSIFIED" Required="TRUE" /> 
        <Sitecolumn DisplayName="Enterprise" StaticName="Tax" Group="Enterprise" Type="TaxonomyFieldTypeMulti" TermStore="D" TermSet="N/A" /> 
        <Sitecolumn DisplayName="Notes" StaticName="Notess" Description="For notes giving context to the document. Additional information can include URL link to another document." Group="*D" Type="Note" Required="FALSE" /> 
       </ContentTypeSiteColumns> 
      </ContentType> 
</ContentTypes> 

私はxml.xmlと呼ばれるアプリケーションのビルドフォルダ内のファイルから文字列へのあなたのXMLを読んでいている...あなたはからXML文字列を取得する必要があります別の場所に置くか、xml.xmlファイルを作成して上記のコードをXMLに保存してください。

+0

私はまだ同じ問題。ここにもう1つのクラスがContentTypeと呼ばれています – user3519261

+0

あなたのXML(あなたが投稿したもの)が不完全で、終了タグが見つからない、それが意図的かどうかわかりません....私は自分の答えを更新しましたタグを含むXMLですべてが機能していれば、XML全体がデシリアライズされたXMLにデシリアライズされます。 – Monty

+0

そこにあることが意図されていました。私はこのクラスのContentTypeとMicrosoft.Sharepoint.Clientの間でクラスの競合が発生しています。ContentType – user3519261

関連する問題