Search code examples
c#xmlxdoc

Unable to convert string to XElement


I am creating a xml file, but am unable to convert the string in the tag <Nb>

 <Header>
 <Body>
 <Nb>13</Nb>    
 </Body>
 </Header>

How do I convert it to an XElement item? I want to avoid using Linq, XmlDoc if possible...


Solution

  • Try using the XElement.Parse like so

    private XElement XmlNumber()
    {    
       XElement nb = XElement.Parse("<Header><Body><Nb>13</Nb></Body></Header>");
    
       return nb;    
    }
    

    Examples here: How to convert from string to XElement object