private static void Traverse(TextWriter writer, XPathNavigator nav, int depth = 0) { var leadIn = new string(Constants.Tab, depth); if (nav.NodeType == XPathNodeType.Root) nav.MoveToFirstChild(); do { switch (nav.NodeType) { case XPathNodeType.Element: WriteElement(writer, nav, depth, leadIn); break; case XPathNodeType.Text: WriteTextData(writer, nav, leadIn); break; case XPathNodeType.Comment: WriteComment(writer, nav, leadIn); break; default: throw new InvalidDataException("Encountered unsupported node type of " + nav.NodeType); } } while (nav.MoveToNext()); }
public void LoadFromXPath(XPathNavigator nav) { nav.MoveToFirstChild(); do { if (nav.Name == "Path") Path = XmlDecode(nav.Value); else if (nav.Name == "Open") Open = nav.ValueAsBoolean; else if (nav.Name == "ManualAdd") ManualAdd = nav.ValueAsBoolean; } while (nav.MoveToNext()); }
public static IEnumerable<XPathNavigator> EnumerateChildren(XPathNavigator navigator) { if (navigator.MoveToFirstChild()) { do { yield return navigator; } while (navigator.MoveToNext()); navigator.MoveToParent(); } }
internal static string ExtractFromNavigator(XPathNavigator nav) { nav.MoveToRoot(); if (nav.MoveToFirstChild()) { string namespaceURI = nav.NamespaceURI; if (!(nav.LocalName != "Envelope") && (!(namespaceURI != "http://schemas.xmlsoap.org/soap/envelope/") || !(namespaceURI != "http://www.w3.org/2003/05/soap-envelope"))) { return namespaceURI; } } return string.Empty; }
public void ReadXml(XPathNavigator node) { if (node.MoveToFirstAttribute()) { do { if (String.IsNullOrEmpty(node.NamespaceURI)) { switch (node.LocalName) { case "method": switch (node.Value) { case "xml": this.Method = XmlSerializationOptions.Methods.Xml; break; case "html": this.Method = XmlSerializationOptions.Methods.Html; break; case "xhtml": this.Method = XmlSerializationOptions.Methods.XHtml; break; case "text": this.Method = XmlSerializationOptions.Methods.Text; break; } break; default: break; } } } while (node.MoveToNextAttribute()); node.MoveToParent(); } if (node.MoveToFirstChild()) { do { if (node.NodeType == XPathNodeType.Element || node.NodeType == XPathNodeType.Text) { this.Content = node.Clone(); break; } } while (node.MoveToNext()); node.MoveToParent(); } }
public Tweet GetTweet(XPathNavigator nav) { Tweet tweet = new Tweet(); nav.MoveToFirstChild(); tweet.createdAt = nav.Value; nav.MoveToNext(); tweet.from = nav.Value; nav.MoveToNext(); tweet.id = nav.Value; nav.MoveToNext(); tweet.Latitude = nav.Value; nav.MoveToNext(); tweet.Longitude = nav.Value; nav.MoveToNext(); nav.MoveToNext(); nav.MoveToNext(); nav.MoveToNext(); tweet.SourceText = nav.Value; nav.MoveToNext(); tweet.Text = nav.Value; nav.MoveToNext(); nav.MoveToNext(); tweet.userName = nav.Value; return tweet; }
internal static bool MoveToBody(XPathNavigator nav) { nav.MoveToRoot(); if (nav.MoveToFirstChild()) { string namespaceURI = nav.NamespaceURI; if ((nav.LocalName != "Envelope") || ((namespaceURI != "http://schemas.xmlsoap.org/soap/envelope/") && (namespaceURI != "http://www.w3.org/2003/05/soap-envelope"))) { return false; } if (nav.MoveToFirstChild()) { do { if ((nav.LocalName == "Body") && (nav.NamespaceURI == namespaceURI)) { return true; } } while (nav.MoveToNext()); } } return false; }
internal static string ExtractFromNavigator(XPathNavigator nav) { string attribute = nav.GetAttribute(XPathMessageContext.Actor11A, "http://schemas.xmlsoap.org/soap/envelope/"); string str2 = nav.GetAttribute(XPathMessageContext.Actor12A, "http://www.w3.org/2003/05/soap-envelope"); nav.MoveToRoot(); nav.MoveToFirstChild(); if ((nav.LocalName == "Envelope") && (nav.NamespaceURI == "http://schemas.xmlsoap.org/soap/envelope/")) { return attribute; } if ((nav.LocalName == "Envelope") && (nav.NamespaceURI == "http://www.w3.org/2003/05/soap-envelope")) { return str2; } return string.Empty; }
//creates a dictionary of values found in XML private static Dictionary<string, string> ResourceDataToDictionary(XPathNavigator xPathNavigator) { Dictionary<string, string> dict = new Dictionary<string, string>(); if (xPathNavigator.MoveToFirstChild()) //children { dict.Add(xPathNavigator.Name, xPathNavigator.Value); while (xPathNavigator.MoveToNext()) { dict.Add(xPathNavigator.Name, xPathNavigator.Value); } } xPathNavigator.MoveToParent(); return dict; }
internal static bool ExtractFromNavigator(XPathNavigator nav) { string str = XPathMessageFunctionActor.ExtractFromNavigator(nav); nav.MoveToRoot(); if (nav.MoveToFirstChild() && (nav.LocalName == "Envelope")) { if (nav.NamespaceURI == "http://schemas.xmlsoap.org/soap/envelope/") { return (str == S11UltRec); } if (nav.NamespaceURI == "http://www.w3.org/2003/05/soap-envelope") { return (str == S12UltRec); } } return false; }
/// <summary> /// Walks the XPathNavigator tree recursively /// </summary> /// <param name="myXPathNavigator"></param> public static void DisplayTree(XPathNavigator myXPathNavigator) { if (myXPathNavigator.HasChildren) { myXPathNavigator.MoveToFirstChild(); Format(myXPathNavigator); DisplayTree(myXPathNavigator); myXPathNavigator.MoveToParent(); } while (myXPathNavigator.MoveToNext()) { Format(myXPathNavigator); DisplayTree(myXPathNavigator); } }
public void ReadSubtree1 () { string xml = "<root/>"; nav = GetXmlDocumentNavigator (xml); ReadSubtree1 (nav, "#1."); nav.MoveToRoot (); nav.MoveToFirstChild (); ReadSubtree1 (nav, "#2."); nav = GetXPathDocumentNavigator (document); ReadSubtree1 (nav, "#3."); nav.MoveToRoot (); nav.MoveToFirstChild (); ReadSubtree1 (nav, "#4."); }
internal static bool MoveToAddressingHeader(XPathNavigator nav, string name) { if (MoveToHeader(nav)) { if (!nav.MoveToFirstChild()) { return false; } do { if ((nav.LocalName == name) && (((nav.NamespaceURI == "http://www.w3.org/2005/08/addressing") || (nav.NamespaceURI == "http://schemas.xmlsoap.org/ws/2004/08/addressing")) || (nav.NamespaceURI == "http://schemas.microsoft.com/ws/2005/05/addressing/none"))) { return true; } } while (nav.MoveToNext()); } return false; }
/// <summary> /// WebDav Property. /// </summary> /// <param name="property"></param> public DavProperty(XPathNavigator property) { if (property == null) throw new ArgumentNullException("property", InternalFunctions.GetResourceString("ArgumentNullException", "Property")); else if (property.NodeType != XPathNodeType.Element) throw new ArgumentException(InternalFunctions.GetResourceString("XPathNavigatorElementArgumentException", "Property"), "property"); base.Name = property.LocalName; base.Namespace = property.NamespaceURI; if (property.HasAttributes) { //TODO: Support element attributes //string _here = ""; //Add the attributes first // foreach (XmlAttribute _xmlAttribute in property.Attributes) // Attributes.Add(new DavPropertyAttribute(_xmlAttribute)); } if (property.MoveToFirstChild()) { if (property.NodeType == XPathNodeType.Element) { NestedProperties.Add(new DavProperty(property.Clone())); while (property.MoveToNext()) { if (property.NodeType == XPathNodeType.Element) NestedProperties.Add(new DavProperty(property.Clone())); } } else if (property.NodeType == XPathNodeType.Text) { base.Value = property.Value; property.MoveToParent(); } } }
public CreateLine(System.Xml.XPath.XPathNavigator navigator, GEMSSingle parent) : base(navigator, parent) { navigator.MoveToChild("Positions", string.Empty); navigator.MoveToFirstChild(); //Start Point of line startPoint = new Vector3WithUnit(); startPoint.X = new Length(navigator.GetAttribute("x", string.Empty), navigator.GetAttribute("ux", string.Empty)); startPoint.Y = new Length(navigator.GetAttribute("y", string.Empty), navigator.GetAttribute("uy", string.Empty)); startPoint.Z = new Length(navigator.GetAttribute("z", string.Empty), navigator.GetAttribute("uz", string.Empty)); //End Point of line navigator.MoveToNext(); endPoint = new Vector3WithUnit(); endPoint.X = new Length(navigator.GetAttribute("x", string.Empty), navigator.GetAttribute("ux", string.Empty)); endPoint.Y = new Length(navigator.GetAttribute("y", string.Empty), navigator.GetAttribute("uy", string.Empty)); endPoint.Z = new Length(navigator.GetAttribute("z", string.Empty), navigator.GetAttribute("uz", string.Empty)); navigator.MoveToParent(); navigator.MoveToParent(); }
/// <summary> /// Updates all of the <c>Torrent</c> object's properties. /// </summary> /// <param name="node">Torrent XML node</param> public void update(XPathNavigator node) { node.MoveToFirstChild(); hash = node.Value; node.MoveToNext(); status = Convert.ToInt64(node.Value); node.MoveToNext(); name = node.Value; node.MoveToNext(); size = Convert.ToInt64(node.Value); node.MoveToNext(); percent_progress = Convert.ToInt64(node.Value); // skip a tonne of properties for (int i = 0; i < 17; i++) node.MoveToNext(); status_message = node.Value; calculateStatus(); last_modified = DateTime.Now; // be kind, rewind node.MoveToParent(); }
public void RecursiveWalkThroughXpath(XPathNavigator navigator) { switch (navigator.NodeType) { case XPathNodeType.Root: //TODO: do this better ie parse xml or html decelration if (IncludeDocType) { textWriter.Write("!!!"); textWriter.Write(Environment.NewLine); } break; case XPathNodeType.Element: ProcessElement(navigator); break; case XPathNodeType.Text: ProcessText(navigator); break; } if (navigator.MoveToFirstChild()) { do { RecursiveWalkThroughXpath(navigator); } while (navigator.MoveToNext()); navigator.MoveToParent(); CheckUnIndent(navigator); } else { CheckUnIndent(navigator); } }
private void XmlNamespaceNode (XPathNavigator nav) { string xhtml = "http://www.w3.org/1999/xhtml"; string xmlNS = "http://www.w3.org/XML/1998/namespace"; nav.MoveToFirstChild (); AssertNavigator ("#1", nav, XPathNodeType.Element, "", "html", xhtml, "html", "test.", false, true, false); Assert.IsTrue (nav.MoveToFirstNamespace (XPathNamespaceScope.Local)); AssertNavigator ("#2", nav, XPathNodeType.Namespace, "", "", "", "", xhtml, false, false, false); // Test difference between Local, ExcludeXml and All. Assert.IsTrue (!nav.MoveToNextNamespace (XPathNamespaceScope.Local)); Assert.IsTrue (!nav.MoveToNextNamespace (XPathNamespaceScope.ExcludeXml)); // LAMESPEC: MS.NET 1.0 XmlDocument seems to have some bugs around here. // see http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q316808 #if true Assert.IsTrue (nav.MoveToNextNamespace (XPathNamespaceScope.All)); AssertNavigator ("#3", nav, XPathNodeType.Namespace, "", "xml", "", "xml", xmlNS, false, false, false); Assert.IsTrue (!nav.MoveToNextNamespace (XPathNamespaceScope.All)); #endif // Test to check if MoveToRoot() resets Namespace node status. nav.MoveToRoot (); AssertNavigator ("#4", nav, XPathNodeType.Root, "", "", "", "", "test.", false, true, false); nav.MoveToFirstChild (); // Test without XPathNamespaceScope argument. Assert.IsTrue (nav.MoveToFirstNamespace ()); Assert.IsTrue (nav.MoveToNextNamespace ()); AssertNavigator ("#5", nav, XPathNodeType.Namespace, "", "xml", "", "xml", xmlNS, false, false, false); // Test MoveToParent() Assert.IsTrue (nav.MoveToParent ()); AssertNavigator ("#6", nav, XPathNodeType.Element, "", "html", xhtml, "html", "test.", false, true, false); nav.MoveToFirstChild (); // body // Test difference between Local and ExcludeXml Assert.IsTrue (!nav.MoveToFirstNamespace (XPathNamespaceScope.Local), "Local should fail"); Assert.IsTrue (nav.MoveToFirstNamespace (XPathNamespaceScope.ExcludeXml), "ExcludeXml should succeed"); AssertNavigator ("#7", nav, XPathNodeType.Namespace, "", "", "", "", xhtml, false, false, false); Assert.IsTrue (nav.MoveToNextNamespace (XPathNamespaceScope.All)); AssertNavigator ("#8", nav, XPathNodeType.Namespace, "", "xml", "", "xml", xmlNS, false, false, false); Assert.IsTrue (nav.MoveToParent ()); AssertNavigator ("#9", nav, XPathNodeType.Element, "", "body", xhtml, "body", "test.", false, true, false); nav.MoveToRoot (); AssertNavigator ("#10", nav, XPathNodeType.Root, "", "", "", "", "test.", false, true, false); }
/// <summary> /// Move to the next reader state. Return false if that is ReaderState.Closed. /// </summary> public override bool Read() { _attrCount = -1; switch (_state) { case State.Error: case State.Closed: case State.EOF: return false; case State.Initial: // Starting state depends on the navigator's item type _nav = _navToRead; _state = State.Content; if (XPathNodeType.Root == _nav.NodeType) { if (!_nav.MoveToFirstChild()) { SetEOF(); return false; } _readEntireDocument = true; } else if (XPathNodeType.Attribute == _nav.NodeType) { _state = State.Attribute; } _nodeType = ToXmlNodeType(_nav.NodeType); break; case State.Content: if (_nav.MoveToFirstChild()) { _nodeType = ToXmlNodeType(_nav.NodeType); _depth++; _state = State.Content; } else if (_nodeType == XmlNodeType.Element && !_nav.IsEmptyElement) { _nodeType = XmlNodeType.EndElement; _state = State.EndElement; } else goto case State.EndElement; break; case State.EndElement: if (0 == _depth && !_readEntireDocument) { SetEOF(); return false; } else if (_nav.MoveToNext()) { _nodeType = ToXmlNodeType(_nav.NodeType); _state = State.Content; } else if (_depth > 0 && _nav.MoveToParent()) { Debug.Assert(_nav.NodeType == XPathNodeType.Element, _nav.NodeType.ToString() + " == XPathNodeType.Element"); _nodeType = XmlNodeType.EndElement; _state = State.EndElement; _depth--; } else { SetEOF(); return false; } break; case State.Attribute: case State.AttrVal: if (!_nav.MoveToParent()) { SetEOF(); return false; } _nodeType = ToXmlNodeType(_nav.NodeType); _depth--; if (_state == State.AttrVal) _depth--; goto case State.Content; case State.InReadBinary: _state = _savedState; _readBinaryHelper.Finish(); return Read(); } return true; }
/// <summary> /// Move to the next reader state. Return false if that is ReaderState.Closed. /// </summary> public override bool Read() { _attrCount = -1; switch (_state) { case State.Error: case State.Closed: case State.EOF: return(false); case State.Initial: // Starting state depends on the navigator's item type _nav = _navToRead; _state = State.Content; if (XPathNodeType.Root == _nav.NodeType) { if (!_nav.MoveToFirstChild()) { SetEOF(); return(false); } _readEntireDocument = true; } else if (XPathNodeType.Attribute == _nav.NodeType) { _state = State.Attribute; } _nodeType = ToXmlNodeType(_nav.NodeType); break; case State.Content: if (_nav.MoveToFirstChild()) { _nodeType = ToXmlNodeType(_nav.NodeType); _depth++; _state = State.Content; } else if (_nodeType == XmlNodeType.Element && !_nav.IsEmptyElement) { _nodeType = XmlNodeType.EndElement; _state = State.EndElement; } else { goto case State.EndElement; } break; case State.EndElement: if (0 == _depth && !_readEntireDocument) { SetEOF(); return(false); } else if (_nav.MoveToNext()) { _nodeType = ToXmlNodeType(_nav.NodeType); _state = State.Content; } else if (_depth > 0 && _nav.MoveToParent()) { Debug.Assert(_nav.NodeType == XPathNodeType.Element, $"{_nav.NodeType} == XPathNodeType.Element"); _nodeType = XmlNodeType.EndElement; _state = State.EndElement; _depth--; } else { SetEOF(); return(false); } break; case State.Attribute: case State.AttrVal: if (!_nav.MoveToParent()) { SetEOF(); return(false); } _nodeType = ToXmlNodeType(_nav.NodeType); _depth--; if (_state == State.AttrVal) { _depth--; } goto case State.Content; case State.InReadBinary: _state = _savedState; _readBinaryHelper !.Finish(); return(Read()); } return(true); }
/// <summary> /// Move to the next reader state. Return false if that is ReaderState.Closed. /// </summary> public override bool Read() { this.attrCount = -1; switch (this.state) { case State.Error: case State.Closed: case State.EOF: return false; case State.Initial: // Starting state depends on the navigator's item type this.nav = this.navToRead; this.state = State.Content; if ( XPathNodeType.Root == this.nav.NodeType ) { if( !nav.MoveToFirstChild() ) { SetEOF(); return false; } this.readEntireDocument = true; } else if ( XPathNodeType.Attribute == this.nav.NodeType ) { this.state = State.Attribute; } this.nodeType = ToXmlNodeType( this.nav.NodeType ); break; case State.Content: if ( this.nav.MoveToFirstChild() ) { this.nodeType = ToXmlNodeType( this.nav.NodeType ); this.depth++; this.state = State.Content; } else if ( this.nodeType == XmlNodeType.Element && !this.nav.IsEmptyElement ) { this.nodeType = XmlNodeType.EndElement; this.state = State.EndElement; } else goto case State.EndElement; break; case State.EndElement: if ( 0 == depth && !this.readEntireDocument ) { SetEOF(); return false; } else if ( this.nav.MoveToNext() ) { this.nodeType = ToXmlNodeType( this.nav.NodeType ); this.state = State.Content; } else if ( depth > 0 && this.nav.MoveToParent() ) { Debug.Assert( this.nav.NodeType == XPathNodeType.Element, this.nav.NodeType.ToString() + " == XPathNodeType.Element" ); this.nodeType = XmlNodeType.EndElement; this.state = State.EndElement; depth--; } else { SetEOF(); return false; } break; case State.Attribute: case State.AttrVal: if ( !this.nav.MoveToParent() ) { SetEOF(); return false; } this.nodeType = ToXmlNodeType( this.nav.NodeType ); this.depth--; if (state == State.AttrVal) this.depth--; goto case State.Content; case State.InReadBinary: state = savedState; readBinaryHelper.Finish(); return Read(); } return true; }
/// <summary> /// Reference: https://support.microsoft.com/en-us/kb/308343 /// </summary> /// <param name="xNav"></param> public void TraverseChildren(XPathNavigator xNav) { xNav.MoveToFirstChild(); do { //Find the first element. if (xNav.NodeType == XPathNodeType.Element) { //Determine whether children exist. if (xNav.HasChildren == true) { //Console.Write("The XML string for this child "); //Console.WriteLine("is {0} = {1}", xNav.Name, xNav.Value); switch (xNav.Name) { case "timestamp_format" : Config.TimestampFormat = xNav.Value; break; case "output_file_path": Config.OutputFilePath = xNav.Value; break; case "screenshots_folder": Config.ScreenshotsFolder = xNav.Value; break; case "screenshot_on_every_message": Config.ScreenshotOnEveryMessage = Convert.ToBoolean(xNav.Value); break; case "screenshot_on_every_pass": Config.ScreenshotOnEveryPass = Convert.ToBoolean(xNav.Value); break; case "screenshot_on_every_fail": Config.ScreenshotOnEveryFail = Convert.ToBoolean(xNav.Value); break; case "screenshot_on_every_error": Config.ScreenshotOnEveryError = Convert.ToBoolean(xNav.Value); break; case "force_throw_exception_on_assert_fail": Config.ScreenshotOnEveryFail = Convert.ToBoolean(xNav.Value); break; case "on_click_event": _ParentNode = "OnClick"; break; case "log_function_start": if (_ParentNode == "OnClick") Config.OnClick_LogFunctionStart = Convert.ToBoolean(xNav.Value); break; case "log_function_end": if (_ParentNode == "OnClick") Config.OnClick_LogFunctionEnd = Convert.ToBoolean(xNav.Value); break; case "screenshot_on_start": if (_ParentNode == "OnClick") Config.OnClick_ScreenshotOnStart = Convert.ToBoolean(xNav.Value); break; case "screenshot_on_end": if (_ParentNode == "OnClick") Config.OnClick_ScreenshotOnEnd = Convert.ToBoolean(xNav.Value); break; default: break; } // end switch TraverseChildren(xNav); xNav.MoveToParent(); } } } while (xNav.MoveToNext()); }
public void DocumentWithProcessingInstruction (XPathNavigator nav) { Assert.IsTrue (nav.MoveToFirstChild ()); AssertNavigator ("#1", nav, XPathNodeType.ProcessingInstruction, "", "xml-stylesheet", "", "xml-stylesheet", "href='foo.xsl' type='text/xsl' ", false, false, false); Assert.IsTrue (!nav.MoveToFirstChild ()); }
public void DocumentWithXmlDeclaration (XPathNavigator nav) { nav.MoveToFirstChild (); AssertNavigator ("#1", nav, XPathNodeType.Element, "", "foo", "", "foo", "bar", false, true, false); }
private void GetNamespaceConsistentTree (XPathNavigator nav) { nav.MoveToFirstChild (); nav.MoveToFirstChild (); nav.MoveToNext (); Assert.AreEqual ("ns1", nav.GetNamespace (""), "#1." + nav.GetType ()); nav.MoveToNext (); nav.MoveToNext (); Assert.AreEqual ("", nav.GetNamespace (""), "#2." + nav.GetType ()); }
protected XPathNavigator MatchNode(XPathNavigator current, IQuery query) { XPathNavigator context; if (current != null) { context = query.MatchNode(current); if (context != null) { if (_opnd.ReturnType() == XPathResultType.Number) { if (_opnd.getName() == Querytype.Constant) { XPathNavigator result = current.Clone(); int i = 0; if (query.getName() == Querytype.Child) { result.MoveToParent(); result.MoveToFirstChild(); while (true) { if (((ChildrenQuery)query).matches(result)) { i++; if (current.IsSamePosition(result)) { if (XmlConvert.ToXPathDouble(_opnd.getValue(current, null)) == i) { return(context); } else { return(null); } } } if (!result.MoveToNext()) { return(null); } } } if (query.getName() == Querytype.Attribute) { result.MoveToParent(); result.MoveToFirstAttribute(); while (true) { if (((AttributeQuery)query).matches(result)) { i++; } if (current.IsSamePosition(result)) { if (XmlConvert.ToXPathDouble(_opnd.getValue(current, null)) == i) { return(context); } else { return(null); } } if (!result.MoveToNextAttribute()) { return(null); } } } } else { setContext(context.Clone()); XPathNavigator result = advance(); while (result != null) { if (result.IsSamePosition(current)) { return(context); } result = advance(); } } } if (_opnd.ReturnType() == XPathResultType.NodeSet) { _opnd.setContext(current); if (_opnd.advance() != null) { return(context); } else { return(null); } } if (_opnd.ReturnType() == XPathResultType.Boolean) { if (noPosition) { if ((bool)_opnd.getValue(current, null)) { return(context); } return(null); } setContext(context.Clone()); XPathNavigator result = advance(); while (result != null) { if (result.IsSamePosition(current)) { return(context); } result = advance(); } return(null); } if (_opnd.ReturnType() == XPathResultType.String) { if (_opnd.getValue(context, null).ToString().Length > 0) { return(context); } else { return(null); } } } else { return(null); } } return(null); }
/// <summary> /// Reads a configuration using the specified XPathNavigator /// </summary> /// <param name="navigator"></param> /// <returns></returns> private XmlConfiguration ReadConfiguration(XPathNavigator navigator, XmlConfiguration configuration) { if (navigator.MoveToFirstChild()) { if (string.Compare(navigator.Name, @"Configuration", true) == 0) { // does the cateogry have attributes, it should! if (navigator.HasAttributes) { // break off yet another clone to navigate the attributes of this element XPathNavigator attributesNavigator = navigator.Clone(); if (attributesNavigator.MoveToFirstAttribute()) { configuration.ElementName = attributesNavigator.Value; while(attributesNavigator.MoveToNextAttribute()) { switch(attributesNavigator.Name) { case @"HasChanges": configuration.HasChanges = XmlConvert.ToBoolean(attributesNavigator.Value); break; case @"Category": configuration.Category = attributesNavigator.Value; break; case @"Description": configuration.Description = attributesNavigator.Value; break; case @"DisplayName": configuration.DisplayName = attributesNavigator.Value; break; case @"Hidden": configuration.Hidden = XmlConvert.ToBoolean(attributesNavigator.Value); break; }; } } } } } // recursively read the categories within this configuration file this.ReadCategories(navigator, configuration.Categories); return configuration; }
static IEnumerable EnumerateChildren (XPathNavigator n, XPathNodeType type) { if (!n.MoveToFirstChild ()) yield break; n.MoveToParent (); XPathNavigator nav = n.Clone (); nav.MoveToFirstChild (); XPathNavigator nav2 = null; do { if (type == XPathNodeType.All || nav.NodeType == type) { if (nav2 == null) nav2 = nav.Clone (); else nav2.MoveTo (nav); yield return nav2; } } while (nav.MoveToNext ()); }
private void XmlElementWithAttributes (XPathNavigator nav) { nav.MoveToFirstChild (); AssertNavigator ("#1", nav, XPathNodeType.Element, "", "img", "", "img", "", true, false, true); Assert.IsTrue (!nav.MoveToNext ()); Assert.IsTrue (!nav.MoveToPrevious ()); Assert.IsTrue (nav.MoveToFirstAttribute ()); AssertNavigator ("#2", nav, XPathNodeType.Attribute, "", "src", "", "src", "foo.png", false, false, false); Assert.IsTrue (!nav.MoveToFirstAttribute ()); // On attributes, it fails. Assert.IsTrue (nav.MoveToNextAttribute ()); AssertNavigator ("#3", nav, XPathNodeType.Attribute, "", "alt", "", "alt", "image Fooooooo!", false, false, false); Assert.IsTrue (!nav.MoveToNextAttribute ()); Assert.IsTrue (nav.MoveToParent ()); AssertNavigator ("#4", nav, XPathNodeType.Element, "", "img", "", "img", "", true, false, true); Assert.IsTrue (nav.MoveToAttribute ("alt", "")); AssertNavigator ("#5", nav, XPathNodeType.Attribute, "", "alt", "", "alt", "image Fooooooo!", false, false, false); Assert.IsTrue (!nav.MoveToAttribute ("src", "")); // On attributes, it fails. Assert.IsTrue (nav.MoveToParent ()); Assert.IsTrue (nav.MoveToAttribute ("src", "")); AssertNavigator ("#6", nav, XPathNodeType.Attribute, "", "src", "", "src", "foo.png", false, false, false); nav.MoveToRoot (); AssertNavigator ("#7", nav, XPathNodeType.Root, "", "", "", "", "", false, true, false); }
bool IReflectorPersistance.Load(System.Xml.XPath.XPathNavigator r) { if (r.NodeType == XPathNodeType.Element) { osalot.AssemblyTracker tracker = new osalot.AssemblyTracker(); string location = null; switch (r.Name) { case "Plugins": bool everokay = false; bool okay; for (okay = r.MoveToFirstAttribute(); okay; okay = r.MoveToNextAttribute()) { everokay = true; switch (r.Name) { case "Location": location = r.Value; break; } } if (everokay) { r.MoveToParent(); } everokay = false; for (okay = r.MoveToFirstChild(); okay; okay = r.MoveToNext()) { everokay = true; switch (r.Name) { case "System Mask": tracker.allow_on_system.Add(r.Value); break; } } if (everokay) { r.MoveToParent(); } if (tracker.allow_on_system.Count == 0) { core_common.LoadAssembly(location, tracker); } else { foreach (String s in tracker.allow_on_system) { Match m = Regex.Match(SystemInformation.ComputerName, s); if (m.Success) { core_common.LoadAssembly(location, tracker); break; } } } return(true); } return(false); } return(false); }
public static void WriteNode(this XmlWriter writer, XPathNavigator navigator, bool defattr) { if (navigator == null) { throw new ArgumentNullException("navigator"); } int iLevel = 0; navigator = navigator.Clone(); while (true) { bool mayHaveChildren = false; XPathNodeType nodeType = navigator.NodeType; switch (nodeType) { case XPathNodeType.Element: writer.WriteStartElement(navigator.Prefix, navigator.LocalName, navigator.NamespaceURI); // Copy attributes if (navigator.MoveToFirstAttribute()) { do { writer.WriteStartAttribute(navigator.Prefix, navigator.LocalName, navigator.NamespaceURI); // copy string value to writer writer.WriteString(navigator.Value); writer.WriteEndAttribute(); } while (navigator.MoveToNextAttribute()); navigator.MoveToParent(); } // Copy namespaces if (navigator.MoveToFirstNamespace(XPathNamespaceScope.Local)) { writer.WriteLocalNamespaces(navigator); navigator.MoveToParent(); } mayHaveChildren = true; break; case XPathNodeType.Attribute: // do nothing on root level attribute break; case XPathNodeType.Text: writer.WriteString(navigator.Value); break; case XPathNodeType.SignificantWhitespace: case XPathNodeType.Whitespace: writer.WriteWhitespace(navigator.Value); break; case XPathNodeType.Root: mayHaveChildren = true; break; case XPathNodeType.Comment: writer.WriteComment(navigator.Value); break; case XPathNodeType.ProcessingInstruction: writer.WriteProcessingInstruction(navigator.LocalName, navigator.Value); break; case XPathNodeType.Namespace: // do nothing on root level namespace break; default: Debug.Fail("Unmatched state in switch"); break; } if (mayHaveChildren) { // If children exist, move down to next level if (navigator.MoveToFirstChild()) { iLevel++; continue; } else { // EndElement if (navigator.NodeType == XPathNodeType.Element) { if (navigator.IsEmptyElement) { writer.WriteEndElement(); } else { writer.WriteFullEndElement(); } } } } // No children while (true) { if (iLevel == 0) { // The entire subtree has been copied return; } if (navigator.MoveToNext()) { // Found a sibling, so break to outer loop break; } // No siblings, so move up to previous level iLevel--; navigator.MoveToParent(); // EndElement if (navigator.NodeType == XPathNodeType.Element) { writer.WriteFullEndElement(); } } } }
/// <summary> /// Move to the next reader state. Return false if that is ReaderState.Closed. /// </summary> public override bool Read() { this.attrCount = -1; switch (this.state) { case State.Error: case State.Closed: case State.EOF: return(false); case State.Initial: // Starting state depends on the navigator's item type this.nav = this.navToRead; this.state = State.Content; if (XPathNodeType.Root == this.nav.NodeType) { if (!nav.MoveToFirstChild()) { SetEOF(); return(false); } this.readEntireDocument = true; } else if (XPathNodeType.Attribute == this.nav.NodeType) { this.state = State.Attribute; } this.nodeType = ToXmlNodeType(this.nav.NodeType); break; case State.Content: if (this.nav.MoveToFirstChild()) { this.nodeType = ToXmlNodeType(this.nav.NodeType); this.depth++; this.state = State.Content; } else if (this.nodeType == XmlNodeType.Element && !this.nav.IsEmptyElement) { this.nodeType = XmlNodeType.EndElement; this.state = State.EndElement; } else { goto case State.EndElement; } break; case State.EndElement: if (0 == depth && !this.readEntireDocument) { SetEOF(); return(false); } else if (this.nav.MoveToNext()) { this.nodeType = ToXmlNodeType(this.nav.NodeType); this.state = State.Content; } else if (depth > 0 && this.nav.MoveToParent()) { Debug.Assert(this.nav.NodeType == XPathNodeType.Element, this.nav.NodeType.ToString() + " == XPathNodeType.Element"); this.nodeType = XmlNodeType.EndElement; this.state = State.EndElement; depth--; } else { SetEOF(); return(false); } break; case State.Attribute: case State.AttrVal: if (!this.nav.MoveToParent()) { SetEOF(); return(false); } this.nodeType = ToXmlNodeType(this.nav.NodeType); this.depth--; if (state == State.AttrVal) { this.depth--; } goto case State.Content; case State.InReadBinary: state = savedState; readBinaryHelper.Finish(); return(Read()); } return(true); }
static IEnumerable EnumerateChildren (XPathNavigator n, string name, string ns) { if (!n.MoveToFirstChild ()) yield break; n.MoveToParent (); XPathNavigator nav = n.Clone (); nav.MoveToFirstChild (); XPathNavigator nav2 = nav.Clone (); do { if ((name == String.Empty || nav.LocalName == name) && (ns == String.Empty || nav.NamespaceURI == ns)) { nav2.MoveTo (nav); yield return nav2; } } while (nav.MoveToNext ()); }
private void LiterallySplittedText (XPathNavigator nav) { nav.MoveToFirstChild (); nav.MoveToFirstChild (); Assert.AreEqual (XPathNodeType.Text, nav.NodeType, "#1"); Assert.AreEqual ("test string", nav.Value, "#2"); }
/// <summary> /// Reads an XmlConfigurationCategoryCollection using the specified XPathNavigator /// </summary> /// <param name="navigator"></param> /// <returns></returns> private XmlConfigurationCategoryCollection ReadCategories(XPathNavigator navigator, XmlConfigurationCategoryCollection categories) { if (navigator.HasChildren) { if (navigator.MoveToFirstChild()) { // is this element a category node? if (string.Compare(navigator.Name, @"Category", true) == 0) { // so read it XmlConfigurationCategory category = new XmlConfigurationCategory(); category.BeginInit(); category.Parent = categories; this.ReadCategory(navigator, category); // and add it to the current collection of categories categories.Add(category); category.EndInit(); } } } while (navigator.MoveToNext()) { // is this element a category node? if (string.Compare(navigator.Name, @"Category", true) == 0) { // so read it XmlConfigurationCategory category = new XmlConfigurationCategory(); category.BeginInit(); category.Parent = categories; this.ReadCategory(navigator, category); // and add it to the current collection of categories categories.Add(category); category.EndInit(); } } return categories; }
private void SelectChildrenNS (XPathNavigator nav) { nav.MoveToFirstChild (); // root XPathNodeIterator iter = nav.SelectChildren ("foo", "urn:foo"); Assert.AreEqual (2, iter.Count, "#1"); }