-3

下記の形式のxmlを持つシリアル化可能なクラスを作成する必要があります。このリンクのxmlとExtendedAttribute要素を確認してください。

http://telligent.com/community/developers/w/developer6/update-a-user.aspx

次のタグはキーと値のペアとして形成され、オブジェクトはありません

私のExtendedAtributeクラスは固定クラスではありませんが、動的に増減する可能性のあるKeyValue型オブジェクトです。

4

1 に答える 1

1

縮小されたXMLファイルの場合:-

<ExtendedAttributes>
  <EnableDisplayName>True</EnableDisplayName>
  <EditorType>Enhanced</EditorType>
  <EnableConversationNotifications>True</EnableConversationNotifications>
  <EnableUserSignatures>True</EnableUserSignatures>
  <CPPageSize>10</CPPageSize>
  <EnableActivityMessageNewUserAvatar>True</EnableActivityMessageNewUserAvatar>
  <EnableActivityMessageThirdPartyMessageType>True</EnableActivityMessageThirdPartyMessageType>
  <EnableStartConversations>1</EnableStartConversations>
  <avatarUrl>~/cfs-file.ashx/__key/communityserver-components-selectableavatars/03b2c875-fbfb-4d26-8000-ef001b9f4728/avatar.png</avatarUrl>
  <EnableActivityMessageNewProfileComment>False</EnableActivityMessageNewProfileComment>
  <EnableActivityMessageStatus>True</EnableActivityMessageStatus>
</ExtendedAttributes>

あなたはそれを解析することができます:-

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

  [XmlRoot("ExtendedAttributes")]
  public class SerialisableDictionary : Dictionary<string, string>, IXmlSerializable
  {
    #region IXmlSerializable Members
    public System.Xml.Schema.XmlSchema GetSchema()
    {
      return null;
    }

    public void ReadXml(System.Xml.XmlReader reader)
    {
      reader.Read();
      while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
      {
        string key = reader.Name;
        this.Add(key, reader.ReadElementContentAsString());
        reader.MoveToElement();
      }
      reader.ReadEndElement();
    }

    public void WriteXml(System.Xml.XmlWriter writer)
    {
      // TODO
    }
    #endregion
  }

  class Program
  {
    static void Main(string[] args)
    {
      SerialisableDictionary sd = new SerialisableDictionary();
      XmlSerializer x = new XmlSerializer(sd.GetType());
      using (StreamReader sr = new StreamReader(@"XMLFile1.xml"))
      {
        sd = (SerialisableDictionary)x.Deserialize(sr);
      }
      foreach(var kvp in sd)
      {
        Console.WriteLine(kvp.Key + " = " + kvp.Value);
      }
      Console.WriteLine("Done.");
      Console.ReadKey();
    }
  }

これにより、Dictionary<string, string>ほぼ確実にtrue / false / string / number値を解析することができますが、これは別の問題です。

これは完璧ではないことを感謝しますが、それで十分です。残念ながら、それはかなり複雑になり、私にはあまり時間がありません。

すべて、 Dictionaryメンバーを含むSerializeClassの回答に大きく基づいています

于 2012-05-14T11:30:57.730 に答える