<Employees>
<Product_Name>
<hello1>product1</hello1>
<hello2>product2</hello2>
<hello3>product3</hello3>
<hello4>product4</hello4>
</Product_Name>
<product_Price>
<hello1>111</hello1>
<hello2>222</hello2>
<hello3>333</hello3>
<hello4>444</hello4>
</product_Price>
</Employees>
是否可以使用 C# 将以下 XML 转换为如下所示的 XML。我尝试使用删除功能,但没有用。我还尝试获取根节点的值。没用
<Product_Name>
<hello1>product1</hello1>
<hello2>product2</hello2>
<hello3>product3</hello3>
<hello4>product4</hello4>
</Product_Name>
<product_Price>
<hello1>111</hello1>
<hello2>222</hello2>
<hello3>333</hello3>
<hello4>444</hello4>
</product_Price>
最佳答案
如果您只想获取内部 xml,可以使用 XmlReader 的 ReadInnerXml
。innerXML 作为字符串获取(跳过根节点)。
var xmlReader = XElement.Load("data.xml").CreateReader();
xmlReader.MoveToContent();
string innerXml = xmlReader.ReadInnerXml();
关于c# - 获取除根元素之外的整个 XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13353799/