2016-04-11 12 views
0

XML'den seri hale getiriyorum ve bir sınıf çakışması sorunuyla karşılaşıyorum.XML sınıf çakışmalarını serpiştirme

örn. Zaten benim kodunda

, ben ContentType aslında Microsoft.SharePoint.Client.ContentType yaşayan sınıf veya Microsoft.SharePoint.Client.Web yılında Web sınıf yaşam atıfta yapacağız. Benim XML'de örn

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

bu gibi okur:

ben deserializing ediyorum benim sınıfta
<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> 

, ben ContentType ve Web (Olması sahiptir Oldukça emin adında bir sınıf var Bu ismi, bu XML'den, adı geçen elemanlarla seri hale getirdiğimden beri adlandırdı).

public class ContentType 
    { 
     [XmlAttribute] 
     public string Name; 

     [XmlAttribute] 
     public string Parent; 

     public List<Sitecolumn> ContentTypeSiteColumns; 

    } 

Yani yukarıda bu sınıf ben XML için deserializing ödüyorlar beri ContentType'ı (?) Çağrısı yapılmalıdır. Ben olsun

hataları gibidir: Ben ContentTypeZ gibi farklı bir şey, ama sonra deserializing işlemi çalışmıyor için deserializing ediyorum sınıfı ararsanız kaybolur

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?) 

.

Bu konuda nasıl çalışabilirim? Umarım mantıklıdır.

+0

Sorununuzun çözüldüğünü umuyoruz. Değilse, belki de sorunuzun güncellenmesini düşünün .... http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235 – Monty

cevap

0

senin bu i yapacağını nasıl ardından XML Deserialize isteyen varsa ....

usings .....

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

Sınıflar .....

[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; } 
} 

Kod .....

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

bu XML ben xml.xml denilen uygulama inşa klasöründe bir dosyadan bir dizeye da XML okuyorum

... Eğer XML dizesi almak gerekir

<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> 
olduğunu Başka bir yerde xml.xml dosyasını oluştur ve yukarıdaki kod için XML kodunu kaydet

+0

Hala aynı şeyleri alıyorum konu. Burada hala ContentType – user3519261

+0

olarak adlandırılan başka bir sınıf var. XML'iniz (gönderdikçe) eksik, son etiketi eksik, kasıtlı olup olmadığını bilmiyorum .... Cevabımı güncelledim etiketini içeren XML ile ve her şey çalışıyorsa, tüm XML, orada olması gereken eksik olan deserializedXML – Monty

+0

Yup'ye serileştirildi. Hala bu sınıf ContentType ve Microsoft.Sharepoint.Client arasında sınıf çakışması alıyorum.ContentType – user3519261

İlgili konular