0

I am using XDocument to create and load the xml but when i call an an element to string the element tags get added with it. So far i have been using

string xmlVer = _xml.Root.Element("XMLVersion").Value.ToString().Replace("<XMLVersion>", "").Replace("</XMLVersion", ""); 

works fine just looking for code optimization.

Is there a way to call the "inner" text instead?

Im not having child-node linking problems.

Thanks.

VJ'
  • 35
  • 5
  • That's not what i asked nor did it answer my question but thanks. – VJ' Oct 25 '15 at 00:01
  • 4
    Can you show an example of the XML you are using? If I just do `var xmlVer = _xml.Root.Element("XMLVersion").Value` on a test case I made up, `""` is not included in the string. – dbc Oct 25 '15 at 00:30
  • `1.0.0.1` How are you calling it? – VJ' Oct 25 '15 at 11:12
  • For me the code `string xml = "1.0.0.1"; XDocument doc = XDocument.Parse(xml); Console.WriteLine(doc.Root.Element("XMLVersion").Value);` outputs `1.0.0.1`. – Martin Honnen Oct 25 '15 at 12:45
  • To illustrate @dbc's point, see [this fiddle](https://dotnetfiddle.net/wPECoE). Your problem doesn't seem to exist. – Charles Mager Oct 25 '15 at 18:00
  • 1
    What you *say*, however, is correct - calling `ToString` on the *element* will give you the tags. Calling `ToString` on `Value`, as your code does, will give you the 'inner text'. As an aside, `Value` is a string so there's no need to call `ToString` on it. – Charles Mager Oct 25 '15 at 18:10
  • @CharlesMager thanks that's working now – VJ' Oct 25 '15 at 18:36

0 Answers0