I’ve built a very simple table that displays 4 columns and 4 rows. When the following code is executed it displays every other element in the .xml file. It does not discriminate per table row. It reads through without any problem and I have run xml validators so it not a syntax issue.
public partial class lblXmlOutput : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
XmlReaderSettings settings = new XmlReaderSettings();
settings.ConformanceLevel = ConformanceLevel.Document;
settings.IgnoreWhitespace = true;
settings.IgnoreComments = true;
XmlReader reader = XmlReader.Create(Server.MapPath("Part2XMLex.xml"), settings);
string result = "";
while (reader.Read())
{
if (reader.IsStartElement("td"))
result += reader.ReadElementContentAsString();
txtOutput.Text = result;
}
}
}
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Because both .Read() and .ReadElementContentAsString() (the parameterless overload) move the reader to the next node.
Change your while condition to:
while (!reader.EOF)
Then add:
else reader.Read();
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0