1

I tried to read a XML file but I don't receive content of nodes that have just space or tab or new line. Please tell me where I'm wrong.

The XML file:

<?xml version="1.0" encoding="UTF-8"?> <root> <paragraph> <sentence> <sequence> <word>aaa</word> <space> </space> </sequence> <sequence> <word>bbb</word> <space> </space> </sequence> <sequence> <word>ccc</word> <space>?!</space> </sequence> </sentence> </paragraph> </root> 

The code:

XmlDocument doc = new XmlDocument(); doc.Load("D:/Licenta/files/struct.xml"); XmlNodeList sentences = doc.DocumentElement.SelectNodes("/root/paragraph"); foreach (XmlNode sentence in sentences) { Console.WriteLine(sentence.InnerText); } Console.ReadLine(); 

The output: aaabbbccc?!

2
  • Have you represented space character as in this post stackoverflow.com/questions/514635/… ? Commented Nov 13, 2015 at 8:46
  • Now I tried this solution and it works perfectly. Thanks. Commented Nov 13, 2015 at 8:57

1 Answer 1

2

There's a property on XmlDocument called PreserveWhitespace which defaults to false causing the behaviour you're observing. You might want to consider switching it to true prior to loading your data into the document.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.