English 中文(简体)
xmlTextReader.ReadInnerXml()正在把我整个XML的理论带进一个变量。
原标题:xmlTextReader.ReadInnerXml() is pulling in my entire XML doc into one variable

我正在制作XML指数文档,供日后阅读。 我有不同的长度阵列,我写到一个档案中。

有一种问题,我认为它存在于读者守则中。 由于某种原因,时间序列和长篇元素被适当阅读成阵列,但衣帽和录像机元素被ski。 出于某种原因,读写者越晚。 不再重归。 阅读的()方法的唯一途径是采用TEXT node型,然后才显示神经中值,这对我来说是无用的。

下面的法典,如果你没有XML文件的例子,就应当完全适用。

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:UserskpennerDesktopVideo Dev1_1.wmv</VideoFile>
      </Marker>
      <Marker>
        <TimeStamp>2011-7-17 23:18:40</TimeStamp>
        <Lat>-122.260755</Lat>
        <Long>46.05878</Long>
        <VideoFile>C:UserskpennerDesktopVideo Dev1_1.wmv</VideoFile>
      </Marker>
    </Index>
最佳回答
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签