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


C# XmlElement.GetType方法代码示例

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


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

示例1: WriteElementTo

 // This method is copied from System.Xml.Linq.ElementWriter.WriteElement but adapted to DOM
 private static void WriteElementTo(XmlWriter writer, XmlElement e)
 {
     XmlNode root = e;
     XmlNode n = e;
     while (true)
     {
         e = n as XmlElement;
         // Only use the inlined write logic for XmlElement, not for derived classes
         if (e != null && e.GetType() == typeof(XmlElement))
         {
             // Write the element
             e.WriteStartElement(writer);
             // Write the element's content
             if (e.IsEmpty)
             {
                 // No content; use a short end element <a />
                 writer.WriteEndElement();
             }
             else if (e._lastChild == null)
             {
                 // No actual content; use a full end element <a></a>
                 writer.WriteFullEndElement();
             }
             else
             {
                 // There are child node(s); move to first child
                 n = e.FirstChild;
                 Debug.Assert(n != null);
                 continue;
             }
         }
         else
         {
             // Use virtual dispatch (might recurse)
             n.WriteTo(writer);
         }
         // Go back to the parent after writing the last child
         while (n != root && n == n.ParentNode.LastChild)
         {
             n = n.ParentNode;
             Debug.Assert(n != null);
             writer.WriteFullEndElement();
         }
         if (n == root)
             break;
         n = n.NextSibling;
         Debug.Assert(n != null);
     }
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:50,代码来源:XmlElement.cs

示例2: ShowValue

        /// <summary>
        /// Shows an XML element in the control.
        /// </summary>
        private void ShowValue(ref int index, ref bool overwrite, XmlElement value, int childIndex)
        {        
            // ignore children that are not elements.
            XmlElement child = value.ChildNodes[childIndex] as XmlElement;

            if (child == null)
            {
                return;
            }
            
            // get the name of the element.
            string name = Utils.Format("{0}", child.Name);
            
            // get the type name.
            string type = value.GetType().Name;
                        
            // update the list view.
            UpdateList(
                ref index,
                ref overwrite,
                value,
                child,
                childIndex,
                name,
                type);
        }        
开发者ID:yuriik83,项目名称:UA-.NET,代码行数:29,代码来源:DataListCtrl.cs

示例3: bestEffortSetIDAttr

        /*
        ****************************************************************************
        * bestEffortSetIDAttr()
        ****************************************************************************
        */
        /**
        * Makes a best effort at setting the ID attribute so that it can be looked
        * up using XmlDocument::getElementsById
        */
        public static void bestEffortSetIDAttr(
        XmlElement oElem, string sNS, string sAttr)
        {
            // do nothing if there is nothing to do
            if ((oElem == null) || (sAttr == null))
            {
            return;
            }

            // if we are using DOM3, use the setIdAttributeNode API
            if (hasDOM3Support())
            {
            Attr oAttr = oElem.getAttributeNodeNS(sNS, sAttr);

            // compiler-friendly way of doing setId as follows:
            // oElem.setIdAttributeNode(oAttr, true);
            try {
                oElem.GetType().getMethod("setIdAttributeNode", new Class[] { oAttr.GetType(), Boolean.TYPE })
                    .invoke(oElem, new Object[] { oAttr, true });
            }
            /*
            catch (IllegalArgumentException e) { }
            catch (SecurityException e) { }
            catch (IllegalAccessException e) { }
            catch (InvocationTargetException e) { }
            catch (NoSuchMethodException e) { }
            */
            catch (Exception e) {
                throw new RuntimeException("Exception caught while calling setIdAttributeNode: " + e);
            }

            if (!oAttr.isId()) {
                throw new RuntimeException("attribute node is not of type Id even after calling setIdAttributeNode!");
            }
            return;
            }

            // if it is an XmlDocument, use the putIdentifier method
            if (isXercesDocument(oElem.getOwnerDocument()))
            {
            string sAttrVal = oElem.getAttributeNS(sNS, sAttr);
            ((XmlDocument) oElem.getOwnerDocument()).putIdentifier(
                sAttrVal, oElem);
            return;
            }

            throw new RuntimeException(
            "No known method to set a signable ID attribute. " +
            "Try using a DOM3-compliant Parser or a DOM2 Xerces XmlDocument.");
        }
开发者ID:AArnott,项目名称:dotnetxri,代码行数:59,代码来源:DOM3Utils.cs


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