当前位置: 首页>>代码示例>>C#>>正文


C# XmlReader.MoveToElement方法代码示例

本文整理汇总了C#中XmlReader.MoveToElement方法的典型用法代码示例。如果您正苦于以下问题:C# XmlReader.MoveToElement方法的具体用法?C# XmlReader.MoveToElement怎么用?C# XmlReader.MoveToElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在XmlReader的用法示例。


在下文中一共展示了XmlReader.MoveToElement方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DumpReader

	public void DumpReader (XmlReader xr, bool attValue)
	{
		Console.WriteLine ("NodeType: " + xr.NodeType);
		Console.WriteLine ("Prefix: " + xr.Prefix);
		Console.WriteLine ("Name: " + xr.Name);
		Console.WriteLine ("LocalName: " + xr.LocalName);
		Console.WriteLine ("NamespaceURI: " + xr.NamespaceURI);
		Console.WriteLine ("Value: " + xr.Value);
		Console.WriteLine ("Depth: " + xr.Depth);
		Console.WriteLine ("IsEmptyElement: " + xr.IsEmptyElement);

		if (xr.NodeType == XmlNodeType.Attribute) {
			Console.WriteLine ("Attribute Values::::");
			while (xr.ReadAttributeValue ())
				DumpReader (xr, true);
			Console.WriteLine (":::Attribute Values End");
		} else if (!attValue) {
			Console.WriteLine ("Attributes::::");
			Console.Write (xr.AttributeCount);
			if (xr.MoveToFirstAttribute ()) {
				do {
					DumpReader (xr, false);
				} while (xr.MoveToNextAttribute ());
				xr.MoveToElement ();
			}
			Console.WriteLine (":::Attributes End");
		}
	}
开发者ID:nobled,项目名称:mono,代码行数:28,代码来源:xrdump.cs

示例2: ReadData

    /// <summary>
    /// Reads a specific data tag from the xml document.
    /// </summary>
    /// <param name='reader'>
    /// Reader.
    /// </param>
    private void ReadData(XmlReader reader)
    {
        //If these values are not being set,
        //something is wrong.
        string key = "ERROR";

        string value = "ERROR";

        if (reader.HasAttributes)
        {
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "name")
                {
                    key = reader.Value;
                }
            }
        }

        //Move back to the element
        reader.MoveToElement();

        //Read the child nodes
        if (reader.ReadToDescendant("value"))
        {
            do
            {
                value = reader.ReadString();
            }
            while (reader.ReadToNextSibling("value"));
        }

        //Add the raw values to the dictionary
        textDataBase.Add(key, value);

        //Add the localized parsed values to the localizedObjectDataBase
        LocalizedObject newLocalizedObject = new LocalizedObject();
        newLocalizedObject.ObjectType = LocalizedObject.GetLocalizedObjectType(key);
        newLocalizedObject.TextValue = value;
        localizedObjectDataBase.Add(LocalizedObject.GetCleanKey(key,newLocalizedObject.ObjectType), newLocalizedObject);
    }
开发者ID:Gris87,项目名称:PingPong3D,代码行数:47,代码来源:LanguageManager.cs

示例3: ReadContentFrom

 internal void ReadContentFrom(XmlReader r, LoadOptions o)
 {
     if ((o & (LoadOptions.SetBaseUri | LoadOptions.SetLineInfo)) == 0)
     {
         ReadContentFrom(r);
         return;
     }
     if (r.ReadState != ReadState.Interactive) throw new InvalidOperationException(SR.InvalidOperation_ExpectedInteractive);
     XContainer c = this;
     XNode n = null;
     NamespaceCache eCache = new NamespaceCache();
     NamespaceCache aCache = new NamespaceCache();
     string baseUri = (o & LoadOptions.SetBaseUri) != 0 ? r.BaseURI : null;
     IXmlLineInfo li = (o & LoadOptions.SetLineInfo) != 0 ? r as IXmlLineInfo : null;
     do
     {
         string uri = r.BaseURI;
         switch (r.NodeType)
         {
             case XmlNodeType.Element:
                 {
                     XElement e = new XElement(eCache.Get(r.NamespaceURI).GetName(r.LocalName));
                     if (baseUri != null && baseUri != uri)
                     {
                         e.SetBaseUri(uri);
                     }
                     if (li != null && li.HasLineInfo())
                     {
                         e.SetLineInfo(li.LineNumber, li.LinePosition);
                     }
                     if (r.MoveToFirstAttribute())
                     {
                         do
                         {
                             XAttribute a = new XAttribute(aCache.Get(r.Prefix.Length == 0 ? string.Empty : r.NamespaceURI).GetName(r.LocalName), r.Value);
                             if (li != null && li.HasLineInfo())
                             {
                                 a.SetLineInfo(li.LineNumber, li.LinePosition);
                             }
                             e.AppendAttributeSkipNotify(a);
                         } while (r.MoveToNextAttribute());
                         r.MoveToElement();
                     }
                     c.AddNodeSkipNotify(e);
                     if (!r.IsEmptyElement)
                     {
                         c = e;
                         if (baseUri != null)
                         {
                             baseUri = uri;
                         }
                     }
                     break;
                 }
             case XmlNodeType.EndElement:
                 {
                     if (c.content == null)
                     {
                         c.content = string.Empty;
                     }
                     // Store the line info of the end element tag.
                     // Note that since we've got EndElement the current container must be an XElement
                     XElement e = c as XElement;
                     Debug.Assert(e != null, "EndElement received but the current container is not an element.");
                     if (e != null && li != null && li.HasLineInfo())
                     {
                         e.SetEndElementLineInfo(li.LineNumber, li.LinePosition);
                     }
                     if (c == this) return;
                     if (baseUri != null && c.HasBaseUri)
                     {
                         baseUri = c.parent.BaseUri;
                     }
                     c = c.parent;
                     break;
                 }
             case XmlNodeType.Text:
             case XmlNodeType.SignificantWhitespace:
             case XmlNodeType.Whitespace:
                 if ((baseUri != null && baseUri != uri) ||
                     (li != null && li.HasLineInfo()))
                 {
                     n = new XText(r.Value);
                 }
                 else
                 {
                     c.AddStringSkipNotify(r.Value);
                 }
                 break;
             case XmlNodeType.CDATA:
                 n = new XCData(r.Value);
                 break;
             case XmlNodeType.Comment:
                 n = new XComment(r.Value);
                 break;
             case XmlNodeType.ProcessingInstruction:
                 n = new XProcessingInstruction(r.Name, r.Value);
                 break;
             case XmlNodeType.DocumentType:
                 n = new XDocumentType(r.LocalName, r.GetAttribute("PUBLIC"), r.GetAttribute("SYSTEM"), r.Value);
//.........这里部分代码省略.........
开发者ID:er0dr1guez,项目名称:corefx,代码行数:101,代码来源:XContainer.cs


注:本文中的XmlReader.MoveToElement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。