EDN Admin
Well-known member
All,<br/><br/>I have a large unformatted document which needs to processed and populated into DB.<br/><br/>For this, I was using an XMLTextReader to get valid IDs, and then doing something like this:<br/><br/> newRdr = xRdr.ReadSubtree();<br/> while (newRdr.Read())<br/> {<br/> if (newRdr.NodeType == XmlNodeType.Element)<br/> {<br/> switch (newRdr.LocalName)<br/> {<br/> case "A":<br/> case "Y":<br/> case "Z": <br/>OutputXml.Append(newRdr.ReadOuterXml() + Environment.NewLine);<br/> break;
}<br/> }<br/>OutputXml is a stringbuilder which will get passed to DB.<br/>This worked fine.<br/><br/>Now I need to do additional validation on the subtree and write passed and failed subtrees to different locations.<br/>I tried having 2 separate XMLReader, one getting the data from the nodes and another for actually writing the outputs based on pass/fail, but the second reader is also at the EndElement and hence empty.<br/><br/>newRdr = xRdr.ReadSubtree();<br/> validationRdr = newRdr;//xRdr.ReadSubtree();
while (validationRdr.Read())<br/> {<br/> Data = validationRdr.ReadOuterXml();<br/> Val1 = Data.Substring(...<br/> Val2= DateTime.Parse(Data.Substring(....<br/> <br/> }<br/><br/>if Val1> 0 && Val2> 0)<br/> while (newRdr.Read())<br/> {<br/> if (newRdr.NodeType == XmlNodeType.Element)<br/> {<br/>//same switch statemtn<br/>}}}<br/><br/>So it basically never hits the NodeType = Element line above.<br/><br/>Hope I have explained the problem clearly.<br/><br/>How do I validate and then read the data anyways?<br/>Thanks,<br/>Ben<br/>
View the full article
}<br/> }<br/>OutputXml is a stringbuilder which will get passed to DB.<br/>This worked fine.<br/><br/>Now I need to do additional validation on the subtree and write passed and failed subtrees to different locations.<br/>I tried having 2 separate XMLReader, one getting the data from the nodes and another for actually writing the outputs based on pass/fail, but the second reader is also at the EndElement and hence empty.<br/><br/>newRdr = xRdr.ReadSubtree();<br/> validationRdr = newRdr;//xRdr.ReadSubtree();
while (validationRdr.Read())<br/> {<br/> Data = validationRdr.ReadOuterXml();<br/> Val1 = Data.Substring(...<br/> Val2= DateTime.Parse(Data.Substring(....<br/> <br/> }<br/><br/>if Val1> 0 && Val2> 0)<br/> while (newRdr.Read())<br/> {<br/> if (newRdr.NodeType == XmlNodeType.Element)<br/> {<br/>//same switch statemtn<br/>}}}<br/><br/>So it basically never hits the NodeType = Element line above.<br/><br/>Hope I have explained the problem clearly.<br/><br/>How do I validate and then read the data anyways?<br/>Thanks,<br/>Ben<br/>
View the full article