【问题标题】:XMLReader in silverlight <test /> type tag problemSilverlight中的XMLReader <test />类型标签问题
【发布时间】:2010-04-30 07:42:35
【问题描述】:

您好,我正在 Silverlight 中解析 XML,在我的 XML 中,我有一个标签就像

<test attribute1="123" />
<test1 attribute2="345">abc text</test1>

我正在使用 XMLReader 来解析 xml 之类的

    using (XmlReader reader = XmlReader.Create(new StringReader(xmlString)))
{

        // Parse the file and display each of the nodes.
        while (reader.Read())
        {
            switch (reader.NodeType)
            {
                case XmlNodeType.Element:
            //process start tag here
                    break;
                case XmlNodeType.Text:
            //process text here
                    break;
                case XmlNodeType.XmlDeclaration:
                case XmlNodeType.ProcessingInstruction:

                    break;
                case XmlNodeType.Comment:

                    break;
                case XmlNodeType.EndElement:
            //process end tag here
                    break;
            }
        }
}

但问题是测试标签没有收到 EndElement 吗?这使我的整个程序逻辑错误。 (对于 test1 标签一切正常)。请帮帮我。

【问题讨论】:

    标签: c# xml silverlight silverlight-3.0 xmlreader


    【解决方案1】:

    XmlNodeType.Element 的情况下,您可以使用reader.IsEmptyElement 属性测试它是否为空元素,这意味着该元素在同一迭代中打开和关闭。

    【讨论】:

    • 谢谢达林!你节省了我的时间。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-28
    • 2019-05-29
    • 2011-11-08
    • 1970-01-01
    相关资源
    最近更新 更多