我们可以在c#中编写一个xml文档 [英] who we can write a xml document in c#

查看:44
本文介绍了我们可以在c#中编写一个xml文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我 有了XML数据,我必须在c#的帮助下在我的代码中写入数据。如何在条件的帮助下完成该代码。请找到以下数据以及我们如何编写该数据。

Hi I  have XML data , I have to write that data in my code with the help of c# how can i do that code with the help of condition .Please find the below data and how we can write that data .

推荐答案

您好Gourav Narula,

Hi Gourav Narula,

感谢您发布此处。

对于您的问题,请尝试下面的代码。

For your question, please try the code below.

 XDocument xDoc = new XDocument(
                new XDeclaration("1.0", "UTF-16", ""),
                new XElement("Records", new XAttribute("count", 7),
                   new XElement("Metadata",
                      new XElement("FieldDefinitions",
                          new XElement("FieldDefinition", new XAttribute("alias", "Tracking_ID"), new XAttribute("name", "Tracking ID"), new XAttribute("guid", "2ba37d7a-e74f-49ad-9e20-aa2beb290695"), new XAttribute("id", "31371")),
                          new XElement("FieldDefinition", new XAttribute("alias", "Title"), new XAttribute("name", "Title"), new XAttribute("guid", "cf6183df-19c9-492a-b53a-cc4eb1dc8a16"), new XAttribute("id", "31374")),
                          new XElement("FieldDefinition", new XAttribute("alias", "Description"), new XAttribute("name", "Description"), new XAttribute("guid", "4220cccd-64f2-4db4-8ee6-6d2eb5a728c5"), new XAttribute("id", "31375"))
                                   )/*FieldDefinitions*/
                               ),/*Metadata*/
                   new XElement("LevelCounts",
                       new XElement("LevelCount",
                          new XAttribute("count", 7), new XAttribute("guid", "984facc4-3dbe-4bd7-b3e1-fcc370d06d1d"), new XAttribute("id", "4696"))
                               ),/* LevelCounts*/
                   new XElement("Record",
                       new XAttribute("parentId", 0), new XAttribute("moduleId", "4887"), new XAttribute("levelGuid", "984facc4-3dbe-4bd7-b3e1-fcc370d06d1d"), new XAttribute("levelId", "4696"), new XAttribute("contentId", "222486"),
                       new XElement("Field", new XAttribute("guid", "2ba37d7a-e74f-49ad-9e20-aa2beb290695"), new XAttribute("id", "31371"), new XAttribute("type", "6"), "222486"),
                       new XElement("Field", new XAttribute("guid", "cf6183df-19c9-492a-b53a-cc4eb1dc8a16"), new XAttribute("id", "31374"), new XAttribute("type", "1"), "ValueUpdateThroughApi"),
                       new XElement("Field", new XAttribute("guid", "4220cccd-64f2-4db4-8ee6-6d2eb5a728c5"), new XAttribute("id", "31375"), new XAttribute("type", "1"), "this is a update action")
                               ),//Record
                   new XElement("Record",
                       new XAttribute("parentId", 0), new XAttribute("moduleId", "4887"), new XAttribute("levelGuid", "984facc4-3dbe-4bd7-b3e1-fcc370d06d1d"), new XAttribute("levelId", "4696"), new XAttribute("contentId", "222487"),
                       new XElement("Field", new XAttribute("guid", "2ba37d7a-e74f-49ad-9e20-aa2beb290695"), new XAttribute("id", "31371"), new XAttribute("type", "6"), "222487"),
                       new XElement("Field", new XAttribute("guid", "cf6183df-19c9-492a-b53a-cc4eb1dc8a16"), new XAttribute("id", "31374"), new XAttribute("type", "1"), "test"),
                       new XElement("Field", new XAttribute("guid", "4220cccd-64f2-4db4-8ee6-6d2eb5a728c5"), new XAttribute("id", "31375"), new XAttribute("type", "1"), "this is a update action",
                          new XElement("p", "test"))//Field
                               ),//Record
                   new XElement("Record",
                       new XAttribute("parentId", 0), new XAttribute("moduleId", "4887"), new XAttribute("levelGuid", "984facc4-3dbe-4bd7-b3e1-fcc370d06d1d"), new XAttribute("levelId", "4696"), new XAttribute("contentId", "222490"),
                       new XElement("Field", new XAttribute("guid", "2ba37d7a-e74f-49ad-9e20-aa2beb290695"), new XAttribute("id", "31371"), new XAttribute("type", "6"), "222490"),
                       new XElement("Field", new XAttribute("guid", "cf6183df-19c9-492a-b53a-cc4eb1dc8a16"), new XAttribute("id", "31374"), new XAttribute("type", "1"), "ValueUpdateThroughApi"),
                       new XElement("Field", new XAttribute("guid", "4220cccd-64f2-4db4-8ee6-6d2eb5a728c5"), new XAttribute("id", "31375"), new XAttribute("type", "1"), "this takes soo less time")
                               ),//Record
                   new XElement("Record",
                       new XAttribute("parentId", 0), new XAttribute("moduleId", "4887"), new XAttribute("levelGuid", "984facc4-3dbe-4bd7-b3e1-fcc370d06d1d"), new XAttribute("levelId", "4696"), new XAttribute("contentId", "222492"),
                       new XElement("Field", new XAttribute("guid", "2ba37d7a-e74f-49ad-9e20-aa2beb290695"), new XAttribute("id", "31371"), new XAttribute("type", "6"), "222492"),
                       new XElement("Field", new XAttribute("guid", "cf6183df-19c9-492a-b53a-cc4eb1dc8a16"), new XAttribute("id", "31374"), new XAttribute("type", "1"), "ValueUpdateThroughApi"),
                       new XElement("Field", new XAttribute("guid", "4220cccd-64f2-4db4-8ee6-6d2eb5a728c5"), new XAttribute("id", "31375"), new XAttribute("type", "1"), "this is a update action")
                               ),//Record
                   new XElement("Record",
                       new XAttribute("parentId", 0), new XAttribute("moduleId", "4887"), new XAttribute("levelGuid", "984facc4-3dbe-4bd7-b3e1-fcc370d06d1d"), new XAttribute("levelId", "4696"), new XAttribute("contentId", "222493"),
                       new XElement("Field", new XAttribute("guid", "2ba37d7a-e74f-49ad-9e20-aa2beb290695"), new XAttribute("id", "31371"), new XAttribute("type", "6"), "222493"),
                       new XElement("Field", new XAttribute("guid", "cf6183df-19c9-492a-b53a-cc4eb1dc8a16"), new XAttribute("id", "31374"), new XAttribute("type", "1"), "ValueUpdateThroughApi"),
                       new XElement("Field", new XAttribute("guid", "4220cccd-64f2-4db4-8ee6-6d2eb5a728c5"), new XAttribute("id", "31375"), new XAttribute("type", "1"), "this is a update action")
                               ),//Record
                   new XElement("Record",
                       new XAttribute("parentId", 0), new XAttribute("moduleId", "4887"), new XAttribute("levelGuid", "984facc4-3dbe-4bd7-b3e1-fcc370d06d1d"), new XAttribute("levelId", "4696"), new XAttribute("contentId", "222494"),
                       new XElement("Field", new XAttribute("guid", "2ba37d7a-e74f-49ad-9e20-aa2beb290695"), new XAttribute("id", "31371"), new XAttribute("type", "6"), "222494"),
                       new XElement("Field", new XAttribute("guid", "cf6183df-19c9-492a-b53a-cc4eb1dc8a16"), new XAttribute("id", "31374"), new XAttribute("type", "1"), "dsgdfsgf"),
                       new XElement("Field", new XAttribute("guid", "4220cccd-64f2-4db4-8ee6-6d2eb5a728c5"), new XAttribute("id", "31375"), new XAttribute("type", "1"),
                          new XElement("p", "sdfgsdfgfdsg"))//Field
                               )//Record
                             )//records
                          );//xdoc
            xDoc.Save("xDoc.xml");

这是我创建的xml文件。

Here is the xml file I created.

<?xml version="1.0" encoding="utf-16"?>
<Records count="7">
  <Metadata>
    <FieldDefinitions>
      <FieldDefinition alias="Tracking_ID" name="Tracking ID" guid="2ba37d7a-e74f-49ad-9e20-aa2beb290695" id="31371" />
      <FieldDefinition alias="Title" name="Title" guid="cf6183df-19c9-492a-b53a-cc4eb1dc8a16" id="31374" />
      <FieldDefinition alias="Description" name="Description" guid="4220cccd-64f2-4db4-8ee6-6d2eb5a728c5" id="31375" />
    </FieldDefinitions>
  </Metadata>
  <LevelCounts>
    <LevelCount count="7" guid="984facc4-3dbe-4bd7-b3e1-fcc370d06d1d" id="4696" />
  </LevelCounts>
  <Record parentId="0" moduleId="4887" levelGuid="984facc4-3dbe-4bd7-b3e1-fcc370d06d1d" levelId="4696" contentId="222486">
    <Field guid="2ba37d7a-e74f-49ad-9e20-aa2beb290695" id="31371" type="6">222486</Field>
    <Field guid="cf6183df-19c9-492a-b53a-cc4eb1dc8a16" id="31374" type="1">ValueUpdateThroughApi</Field>
    <Field guid="4220cccd-64f2-4db4-8ee6-6d2eb5a728c5" id="31375" type="1">this is a update action</Field>
  </Record>
  <Record parentId="0" moduleId="4887" levelGuid="984facc4-3dbe-4bd7-b3e1-fcc370d06d1d" levelId="4696" contentId="222487">
    <Field guid="2ba37d7a-e74f-49ad-9e20-aa2beb290695" id="31371" type="6">222487</Field>
    <Field guid="cf6183df-19c9-492a-b53a-cc4eb1dc8a16" id="31374" type="1">test</Field>
    <Field guid="4220cccd-64f2-4db4-8ee6-6d2eb5a728c5" id="31375" type="1">this is a update action<p>test</p></Field>
  </Record>
  <Record parentId="0" moduleId="4887" levelGuid="984facc4-3dbe-4bd7-b3e1-fcc370d06d1d" levelId="4696" contentId="222490">
    <Field guid="2ba37d7a-e74f-49ad-9e20-aa2beb290695" id="31371" type="6">222490</Field>
    <Field guid="cf6183df-19c9-492a-b53a-cc4eb1dc8a16" id="31374" type="1">ValueUpdateThroughApi</Field>
    <Field guid="4220cccd-64f2-4db4-8ee6-6d2eb5a728c5" id="31375" type="1">this takes soo less time</Field>
  </Record>
  <Record parentId="0" moduleId="4887" levelGuid="984facc4-3dbe-4bd7-b3e1-fcc370d06d1d" levelId="4696" contentId="222492">
    <Field guid="2ba37d7a-e74f-49ad-9e20-aa2beb290695" id="31371" type="6">222492</Field>
    <Field guid="cf6183df-19c9-492a-b53a-cc4eb1dc8a16" id="31374" type="1">ValueUpdateThroughApi</Field>
    <Field guid="4220cccd-64f2-4db4-8ee6-6d2eb5a728c5" id="31375" type="1">this is a update action</Field>
  </Record>
  <Record parentId="0" moduleId="4887" levelGuid="984facc4-3dbe-4bd7-b3e1-fcc370d06d1d" levelId="4696" contentId="222493">
    <Field guid="2ba37d7a-e74f-49ad-9e20-aa2beb290695" id="31371" type="6">222493</Field>
    <Field guid="cf6183df-19c9-492a-b53a-cc4eb1dc8a16" id="31374" type="1">ValueUpdateThroughApi</Field>
    <Field guid="4220cccd-64f2-4db4-8ee6-6d2eb5a728c5" id="31375" type="1">this is a update action</Field>
  </Record>
  <Record parentId="0" moduleId="4887" levelGuid="984facc4-3dbe-4bd7-b3e1-fcc370d06d1d" levelId="4696" contentId="222494">
    <Field guid="2ba37d7a-e74f-49ad-9e20-aa2beb290695" id="31371" type="6">222494</Field>
    <Field guid="cf6183df-19c9-492a-b53a-cc4eb1dc8a16" id="31374" type="1">dsgdfsgf</Field>
    <Field guid="4220cccd-64f2-4db4-8ee6-6d2eb5a728c5" id="31375" type="1">
      <p>sdfgsdfgfdsg</p>
    </Field>
  </Record>
</Records>

最好的问候,

Wendy


这篇关于我们可以在c#中编写一个xml文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆