Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7920741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:19:41+00:00 2026-06-03T16:19:41+00:00

I am creating XML index files to be read in a later step. I

  • 0

I am creating XML index files to be read in a later step. I have variable length arrays, and I am writing them to one file.

There is a problem, I think its inside the reader code. For some reason the TimeStamp and Long elements are read into arrays properly, but the Lat and VideoFile elements are skipped. For some reason, thier reader.nodetype is never returned. The only way the read() method picks them up is in a TEXT nodetype, and then it only shows the innerxml value, which is useless to me.

The code below should be fully runnable once you save an example of the XML file.

Once again, thank-you stack users.

Creation

    using System.Xml;        
    XmlTextWriter xmlwriter = new XmlTextWriter(file, null);
    xmlwriter.Formatting = Formatting.Indented;
    //xmlwriter.Indentation = 4;
    xmlwriter.WriteStartDocument();
    xmlwriter.WriteStartElement("Index");

    for (int i = 0; i < malLat.Count; i++)
    {
        xmlwriter.WriteStartElement("Marker");

        xmlwriter.WriteStartElement("TimeStamp");
        xmlwriter.WriteString(malTimes[i].ToString());
        xmlwriter.WriteEndElement();

        xmlwriter.WriteStartElement("Lat");
        xmlwriter.WriteString(malLat[i].ToString());
        xmlwriter.WriteEndElement();

        xmlwriter.WriteStartElement("Long");
        xmlwriter.WriteString(malLong[i].ToString());
        xmlwriter.WriteEndElement();

        xmlwriter.WriteStartElement("VideoFile");
        xmlwriter.WriteString(malVideoTitle[i].ToString());
        xmlwriter.WriteEndElement();

        xmlwriter.WriteEndElement();
    }
    xmlwriter.WriteEndElement();
    xmlwriter.WriteEndDocument();
    xmlwriter.Close();

Reading

using System.Xml;  
XmlTextReader lxmlReader = new XmlTextReader(mstrIndexFile + ".xml");
lxmlReader.WhitespaceHandling = WhitespaceHandling.None;

while (lxmlReader.Read())
{
    if (lxmlReader.NodeType == XmlNodeType.Element)
    {
        if (lxmlReader.Name == "TimeStamp")
        {
            malTimes.Add(lxmlReader.ReadInnerXml().ToString());
        }
        else if (lxmlReader.Name == "Lat")
        {
            malLat.Add(lxmlReader.ReadInnerXml().ToString());
        }
        else if (lxmlReader.Name == "Long")
        {
            malLong.Add(lxmlReader.ReadInnerXml().ToString());
        }
        else if (lxmlReader.Name == "VideoFile")
        {
            malVideoTitle.Add(lxmlReader.ReadInnerXml().ToString());
        }
    }
}

lxmlReader.Close();

XML Doc Sample

    <Index>
      <Marker>
        <TimeStamp>2011-7-17 23:18:39</TimeStamp>
        <Lat>-121.261953323166</Lat>
        <Long>43.0594755392741</Long>
        <VideoFile>C:\Users\kpenner\Desktop\Video Dev\1_1.wmv</VideoFile>
      </Marker>
      <Marker>
        <TimeStamp>2011-7-17 23:18:40</TimeStamp>
        <Lat>-122.260755</Lat>
        <Long>46.05878</Long>
        <VideoFile>C:\Users\kpenner\Desktop\Video Dev\1_1.wmv</VideoFile>
      </Marker>
    </Index>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T16:19:42+00:00Added an answer on June 3, 2026 at 4:19 pm

    The issue the XmlTextReader is a forward-only reader. When you perform the ReadInnerXml against the reader on a leaf node, it moves to the next element (see http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.readinnerxml.aspx). So in this case, when you hit TimeStamp and perform a ReadInnerXml, the reader then moves the to the Lat Element type because these 4 elements are leaf nodes. Then you read again in your while loop which moves the reader to the Text element of Lat. Since you are only checking for Element types, it works itself out until you hit Long which then breaks VideoFile for the same reasons.

    Here is a link to another SO question with an answer which may help with your solution: XMLTextReader not reading an element content.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating xml-like mark-up language using System.Xml.XmTextWriter that will be read by a third
I'm creating a xml file with the DOMDocument class in php. I want to
I'm creating an XML file using Perl and XML::Simple module. I successfully create the
I am creating an xml file on the fly. When a user generates this
Am creating an xml file using xmlwriter,i thought it works fine but when i
I am creating an xml file. I need to check first if the file
I am creating XML files in my GAE web application and I would like
I am creating serialized XML for a LINQ to SQL project using the DataContractSerializer
I'm creating an XML document. I got it to indent using TransformerFactory.setAttribute(indent-number, new Integer(2));
I am creating an XML document on the fly. and I need to know

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.