Ignore white space in xmlreader?

ITESSEPAK

New Member
I just want to know how the xml reader behaves when the ignorewhitespace is set to false or true.I have an xml in the following structure \[code\]<JOBDOCS> <JOBDOC/> <JOBDOC/> <JOBDOC/></JOBDOCS>\[/code\]I have a function which splits thi s xml file in to separate files each contains one JOBDOC. Following is the C# code im using to achive this\[code\]XmlWriterSettings settings = new XmlWriterSettings { Encoding = Encoding.UTF8, Indent = true, NewLineChars = Environment.NewLine, NewLineHandling = NewLineHandling.Replace, OmitXmlDeclaration = true }; XmlReaderSettings readerSettings = new XmlReaderSettings(); readerSettings.CheckCharacters = false; readerSettings.IgnoreWhitespace = true; XmlReader reader = XmlReader.Create("JOBS.xml",readerSettings); XmlDocument xDoc = new XmlDocument(); Int32 setCount = 5000; Int16 i = 1; int count = 0; while (reader.Read()) { if (setCount <= 0) { i++; setCount = 5000; } if (!Directory.Exists(bgXmlPath + "\\" + i)) { Directory.CreateDirectory(bgXmlPath + "\\" + i); } if (reader.Name.Equals("JOBDOC")) { if (reader.IsStartElement()) { count++; xDoc.InnerXml = reader.ReadOuterXml(); using (XmlWriter writer = XmlWriter.Create(bgXmlPath + "\\" + i + "\\" + xDoc.SelectSingleNode("//JOBDOC").Attributes["ID"].Value + ".xml", settings)) { xDoc.Save(writer); setCount--; } } } }\[/code\]If i have 10 JOBDOC nodes in JOBS.xml this code writes only 5 JOBDOC as result. But if i commented the line "readerSettings.IgnoreWhitespace = true;" then this codes writes 10 files as a result. Im not sure what is the reason for this. Thanks in advance!!
 
Back
Top