将模型数据保存到XML

时间:2015-05-26 10:56:15

标签: c# xml

我的xml是:

<Texts>
  <Text group="Front0" audio="Front0_1.wav"  datetime="">blank</Text>
  <Text group="Keys0" audio="Keys0_2.wav"  datetime="">blank</Text>
  <Text group="Bedroom0" section="Ceiling" audio="Bedroom0_1.wav"  datetime="26-05-2015 03:57">[[Ceiling]] </Text>
  <Text group="Bedroom0" section="Ceiling" audio="Bedroom0_1.wav" datetime="26-05-2015 03:57">[[Ceiling]] </Text>
</Texts>

我想检查部分名称n音频路径是否相等 我的代码是:

public Boolean setSectionContent(decimal Trans_ID, decimal Job_ID, string SectionName, string Content, string audioPath)
{
    string data;
    GroupData p = new GroupData();
    try
    {
        var gp = (from Trans_Mast in r2ge.Transcription_Master where Trans_Mast.Transcription_Id == Trans_ID && Trans_Mast.Entity_Id == Job_ID select Trans_Mast).Distinct();
        foreach (var g in gp)
        {
            p.text = g.Text_xml.ToString();

            XDocument doc = XDocument.Parse(p.text);

            var txt = doc.Descendants("Text")
                  .Where(e => (string)e.Attribute("section") == SectionName)
                  .Select(e => new Text
                  {
                      LastModifiedOn = (string)e.Attribute("datetime"),
                      Content = (string)e.Value
                  }).Distinct().ToList();
            foreach (var item in txt)
            {
                item.Content = Content;
                item.LastModifiedOn = DateTime.Now.ToString("dd-MM-yyyy hh:mm");
            }

            data = doc.ToString();

.. doc仍与以前相同..数据保存在模型中..我想将该数据保存为XML ..

1 个答案:

答案 0 :(得分:0)

如果您想修改XML,为什么不简单地返回mymacro s而不是XElement个对象:

Text