Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get entire XML except root element

Tags:

c#

xml

linq

<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>

is it possible to convert the following XML to the XML shown below using C#. I tried using remove function but it didn't work. I also tried to get the value of root node. Didn't work

  <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>
like image 930
StackOverflowVeryHelpful Avatar asked Apr 26 '26 14:04

StackOverflowVeryHelpful


1 Answers

If you just want to fetch the inner xml,you can use the XmlReader's ReadInnerXml.The innerXML is fetched as a string(skipping the root node).

var xmlReader = XElement.Load("data.xml").CreateReader();
xmlReader.MoveToContent();
string innerXml = xmlReader.ReadInnerXml();
like image 151
Prabhu Murthy Avatar answered Apr 29 '26 05:04

Prabhu Murthy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!