-2

次のような XML があります。

<?xml version="1.0" standalone="yes"?>
<DocumentElement>
<Session>
<bIsImages>False</bIsImages>
<bIsPlayMedia>False</bIsPlayMedia>
<bIsSubject>False</bIsSubject>
<bIsVideo>False</bIsVideo>
<dtCreDate>2012-07-23</dtCreDate>
<dtSes_Date1>2001-01-01</dtSes_Date1>
<dtSes_Date2>2001-01-01</dtSes_Date2>
<dtSes_Date3>2001-01-01</dtSes_Date3>
<nClient_ID>32</nClient_ID>
<nDelay>32</nDelay>
<nImage_ID>32</nImage_ID>
<nOperator_ID>32</nOperator_ID>
<nSession_ID>32</nSession_ID>
<nVitality>32</nVitality>
<strDescr>qi stagnatie abq</strDescr>
<strMediaPath></strMediaPath>
<strName>qi stagnatie abq</strName>
<strPrimCause></strPrimCause>
<strSubjectPath>IDF_Eric duBosc.JPG</strSubjectPath>
</Session>
<SessionProgramData>
</SessionProgramData><SessionSubProgramData>
</SessionSubProgramData><SessionTuningData>

  <SessionTuning>
    <SessionTuning_ID>717</SessionTuning_ID>
    <Session_ID>70</Session_ID>
    <Tuning>8285-100</Tuning>
    <TuningDescr>Disturbance by Qistagnatie in general</TuningDescr>
    <TuningIsNegative>true</TuningIsNegative>
    <TuningAddInfo>70</TuningAddInfo>
    <Amp>2.2</Amp>
    <Amp2 />
    <Amp3>0.1</Amp3>
    <Amp4>5.1</Amp4>
    <Amp5>1.0</Amp5>
    <Amp6 />
    <TunFreq>8285-100</TunFreq>
    <TunFreq2 />
    <TunFreq3>8285-100</TunFreq3>
    <TunFreq4 />
    <TunFreq5 />
    <TunFreq6 />
    <Revision2>false</Revision2>
    <Revision3>false</Revision3>
    <Revision4>false</Revision4>
    <Revision5>false</Revision5>
    <Revision6>false</Revision6>
    <AlreadyBalanced>false</AlreadyBalanced>
    <ImagePath />
    <Amp7 />
    <TunFreq7 />
    <Revision7>0</Revision7>
    <Description />
  </SessionTuning>

  ....So on

</SessionTuningData>
<Client>
<nClient_ID>32</nClient_ID>
<strAddress></strAddress>
<strCity></strCity>
<strCountry></strCountry>
<strFirstName>Eric</strFirstName>
<strImage>IDF_Eric duBosc.JPG</strImage>
<strLastName>Bosc</strLastName>
<strMI>du</strMI>
<strNote>ikke</strNote>
<strPhoneNum></strPhoneNum>
<strPostalCode></strPostalCode>
<strState></strState>
<strWorkPhone></strWorkPhone>
</Client>
<SE-5 />
</DocumentElement>

そして、以下のクラス:

    public class clsSessionTuningData
    {
        public int nSessionTuning_ID;
        public int nSession_ID;
        public int nTuning_ID;
        public string strTuning;
        public string strTuningDescr;
        public string Description;
        public bool bTuningIsNegative;
        public int nTuningAddInfo;
        public string strAmp;
        public string strAmp2;
        public string strAmp3;
        public string strAmp4;
        public string strAmp5;
        public string strAmp6;
        public string strAmp7;

        public DateTime strRevDate;
        public DateTime strRevDate2;
        public DateTime strRevDate3;
        public DateTime strRevDate4;
        public DateTime strRevDate5;
        public DateTime strRevDate6;
        public DateTime strRevDate7;

        public string strTunFreq;
        public string strTunFreq2;
        public string strTunFreq3;
        public string strTunFreq4;
        public string strTunFreq5;
        public string strTunFreq6;
        public string strTunFreq7;
        public bool bRevision2;
        public bool bRevision3;
        public bool bRevision4;
        public bool bRevision5;
        public bool bRevision6;
        public bool bRevision7;
        public bool bAlreadyBalanced;
        public string strImagePath;
    }

<SessionTuningData>では、オブジェクトの配列内の各タグの値を取得するにはどうすればよいclsSessionTuningDataですか?

4

3 に答える 3

1

You need to mark your class as serializable.

I would have expected some [XmlElement] attributes at least to appear in the code of anyone who had read any tutorial.

Like this one

public class Movie
{
  [XmlElement("MovieName")]
  public string Title
  { get; set; }

  [XmlElement("MovieRating")]
  public float Rating
  { get; set; }

  [XmlElement("MovieReleaseDate")]
  public DateTime ReleaseDate
  { get; set; }
}
于 2013-03-01T10:06:08.940 に答える
0

You can use a tool like xsd.exe to create a xsd file and from here you can serialise using

http://snipplr.com/view/2660/

it might not create the exact same xml but it will be close...

As an aside its probably easier to serialise to json instead of xml using newtonsoft json

于 2013-03-01T10:06:52.373 に答える
0

これを行うには多くの方法があります。

  1. クラス プロパティを xml 属性で装飾します (例: XmlElement、XmlAttribute) ( http://www.codeproject.com/Articles/14064/Using-the-XmlSerializer-Attributes )

  2. IXmlSerializable を実装する ( http://www.codeproject.com/Articles/43237/How-to-Implement-IXmlSerializable-Correctly )

  3. または DataContractSerializer を使用する ( http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.aspx )

于 2013-03-01T10:10:20.233 に答える