C# 如何复制XML文件
我想将(元素/属性)值从一个XML文件复制到另一个XML文件,但目前我不知道如何进行。我想将文件A中的值复制到文件B中。文件B或多或少具有相同的元素/属性,唯一的区别是为空。我之所以采用这种方法,是因为我没有这两个文件的模式 以下是文件A的内容:C# 如何复制XML文件,c#,xml,C#,Xml,我想将(元素/属性)值从一个XML文件复制到另一个XML文件,但目前我不知道如何进行。我想将文件A中的值复制到文件B中。文件B或多或少具有相同的元素/属性,唯一的区别是为空。我之所以采用这种方法,是因为我没有这两个文件的模式 以下是文件A的内容: <status>1</status> <arguments> <argument name="ZONE"> <value>ZONE 1</value> <
<status>1</status>
<arguments>
<argument name="ZONE">
<value>ZONE 1</value>
</argument>
<argument name="JOB_DATES">
<argument name="JOB_DATE">
<value>2014-01-20</value>
</argument>
</argument>
<argument name="PERSON">
<argument name="NAME_1">
<value>JOHN</value>
</argument>
<argument name="NAME_2">
<value>SMITH</value>
</argument>
</argument>
<argument name="FIRST_SCHEDULE_JOB">
<value>true</value>
</argument>
<argument name="EMPLOYEE">
<value>ABXX011</value>
</argument>
</arguments>
<place placeType="JOB_SITE">
<site>
<street>DUKE 2</street>
<house_name>TECH HOUSE</house_name>
<zip>QZ12324</zip>
<city>NYC</city>
<province>NY</province>
<country>USA</country>
</site>
<contact>
<Name>JOHN</Name>
<Name_1>SMITH</Name_1>
<address>
<street>DUKE 2</street>
<house_name>TECH HOUSE</house_name>
<zip>QZ12324</zip>
<city>NYC</city>
<province>NY</province>
<country>USA</country>
</address>
</contact>
非常感谢您的帮助
谢谢“LINQ到XML”使查询和写入XML文件变得非常容易。看看:
XElement root=XElement.Load(“fileA.xml”);
IEnumerable地址=
从根元素中的el(“地址”)
其中(字符串)el.属性(“类型”)=“账单”
选择el;
foreach(地址中的XElement el)
控制台写入线(el);
请在您的问题中包含您已经尝试过的内容-至少如果向人们展示了您正在使用哪些技术来阅读xml!那么问题出在哪里呢?如果您有自己的节点,只需将它们写入另一个文件。可能的重复也可能是重复的我尝试使用XMLTextReader
<status></status>
<arguments>
<argument name="ZONE">
<value></value>
</argument>
<argument name="JOB_DATES">
<argument name="JOB_DATE">
<value></value>
</argument>
</argument>
<argument name="PERSON">
<argument name="NAME_1">
<value></value>
</argument>
<argument name="NAME_2">
<value></value>
</argument>
</argument>
<argument name="FIRST_SCHEDULE_JOB">
<value></value>
</argument>
<argument name="EMPLOYEE">
<value></value>
</argument>
</arguments>
<place placeType="JOB_SITE">
<contact>
<Name></Name>
<Name_1></Name_1>
<address>
<street></street>
<house_name></house_name>
<zip></zip>
<city></city>
<province></province>
<country></country>
</address>
</contact>
<site>
<street></street>
<house_name></house_name>
<zip></zip>
<city></city>
<province></province>
<country></country>
</site>
</place>
while (emptyFile.Read())
{
switch (emptyFile.NodeType)
{
case XmlNodeType.Element: // The node is an element.
emptyFile.Name = sourceFile.Name;
........
}
}
XElement root = XElement.Load("fileA.xml");
IEnumerable<XElement> address =
from el in root.Elements("Address")
where (string)el.Attribute("Type") == "Billing"
select el;
foreach (XElement el in address)
Console.WriteLine(el);