コード例 #1
0
        private XObject nextMatch (XObject root, string name, XObject startAfter = null)
        {
            var scan = startAfter == null ? root.FirstChild() : startAfter.NextChild();
        
            while(scan != null)
            {
                XName scanName;

                if (scan.NodeType == XmlNodeType.Element && scan is XElement element)
                    scanName = element.Name;
                else if (scan.NodeType == XmlNodeType.Attribute && scan is XAttribute attr && !isReservedAttribute(attr))
                    scanName = attr.Name;
コード例 #2
0
 public static string GetValue(this XObject current)
 {
     if (current.AtXhtmlDiv())
     {
         return(((XElement)current).ToString(SaveOptions.DisableFormatting));
     }
     if (current.FirstChild() is XText)
     {
         return(current.Value());
     }
     return(current is XElement xelem?
            xelem.Attribute("value")?.Value.Trim() : current.Value());
 }
コード例 #3
0
        public bool MoveToFirstChild()
        {
            // don't move into xhtml
            if (isXhtmlDiv(_current))
            {
                return(false);
            }

            var scan = _current.FirstChild();

            // Make this into a "move to the first child that's an element or attribute"
            while (scan != null)
            {
                if (scan.NodeType == XmlNodeType.Element)
                {
                    var element = (XElement)scan;
                    _parentPath = Location;

                    // If this is a nested resource, move one level deeper
                    if (isResourceNameElement(element.Name))
                    {
                        scan = element.FirstNode;
                    }

                    _current   = scan;
                    _nameIndex = 0;
                    return(true);
                }
                else if (scan.NodeType == XmlNodeType.Attribute && !isReservedAttribute((XAttribute)scan))
                {
                    _parentPath = Location;
                    _current    = scan;
                    _nameIndex  = 0;
                    return(true);
                }

                scan = scan.NextChild();
            }

            return(false);
        }
コード例 #4
0
        public static XObject FirstChildElementOrAttribute(this XObject current)
        {
            var scan = current.FirstChild();

            return(scanToNextRelevantNode(scan));
        }