c# - Xelement adds element value to itself twice -


in code iterate through xelement , have return value of each node within element e.g.

foreach(xelement n in xdocument.descedants("element_name)  {    console.writeline("searching: " n.value);  } 

my problem both <directory> elements returned in string

searching: c:\users\215358\onedrive\musicc:\users\215358\dropbox\music 

my xml file looks this:

<?xml version="1.0" encoding="utf-8"?> <directories>   <directory>c:\users\215358\onedrive\music</directory>   <directory>c:\users\215358\dropbox\music</directory> </directories> 

i expect output second line element in <directory> this:

c:\users\215358\dropbox\music 

why happening?

xelement.value gets concatenated text contents of element. includes text of child elements not helpful. if want text current element, can find text node in child nodes.

foreach(xelement n in xdocument.descedants("directory")) {     var text = n.nodes().where (x => x xtext).cast<xtext>().firstordefault ();     if(text!=null){         console.writeline("searching: " + text.value);     }else{         console.writeline("no text node found");     } } 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -