ReadSubtree() public méthode

public ReadSubtree ( ) : XmlReader
Résultat XmlReader
        private void AddPlatformVersionFilter(string platformId, string versionId, XPathNavigator platformNode, string file)
        {
            Dictionary<string, VersionFilter> platformFrameworks;
            if (!versionFilters.TryGetValue(platformId, out platformFrameworks))
            {
                platformFrameworks = new Dictionary<string, VersionFilter>();
                versionFilters.Add(platformId, platformFrameworks);
            }

            try
            {
                VersionFilter filter;
                XmlReader platformReader = platformNode.ReadSubtree();
                platformReader.MoveToContent();
                if (!platformFrameworks.TryGetValue(versionId, out filter))
                {
                    filter = new VersionFilter(platformReader, versionId, file);
                }
                else
                {
                    // if the platform already has a filter for this version, add the data from the current platform node
                    filter.AddPlatformNode(platformReader, file);
                }
                platformReader.Close();

                platformFrameworks.Remove(versionId);
                platformFrameworks.Add(versionId, filter);
            }
            catch (Exception e)
            {
                WriteMessage(MessageLevel.Error, e.Message);
            }
        }
        private bool CopyToUnsetValues(XPathNavigator sourceNavigator, RunSettings targetRunSettings)
        {
            if (sourceNavigator.MoveToChild(GoogleTestConstants.SettingsName, ""))
            {
                RunSettings sourceRunSettings = RunSettings.LoadFromXml(sourceNavigator.ReadSubtree());
                targetRunSettings.GetUnsetValuesFrom(sourceRunSettings);

                return true;
            }

            return false;
        }
		public bool ReadObject(XPathResult result, XPathNavigator node, out object value)
		{
			using (var reader = node.ReadSubtree())
			{
				reader.MoveToContent();
				if (typeof(IXmlSerializable).IsAssignableFrom(result.Type))
				{
					value = DeserializeCustom(reader, result, node);
				}
				else
				{
					value = Deserialize(reader, result, node);
				}
			}

			return (value != null);
		}
		public bool ReadObject(XPathResult result, XPathNavigator node, out object value)
		{
			var rootOverride = new XmlRootAttribute(node.LocalName)
			{
				Namespace = node.NamespaceURI
			};

			var serializer = new XmlSerializer(result.Type, rootOverride);

			using (var reader = node.ReadSubtree())
			{
				reader.MoveToContent();
				if (serializer.CanDeserialize(reader))
				{
					value = serializer.Deserialize(reader);
					return true;
				}				
			}

			value = null;
			return false;
		}
		void ReadSubtree1 (XPathNavigator nav, string label)
		{
			XmlReader r = nav.ReadSubtree ();

			XmlAssert.AssertNode (label + "#1", r,
				// NodeType, Depth, IsEmptyElement
				XmlNodeType.None, 0, false,
				// Name, Prefix, LocalName, NamespaceURI
				String.Empty, String.Empty, String.Empty, String.Empty,
				// Value, HasValue, AttributeCount, HasAttributes
				String.Empty, false, 0, false);

			Assert.IsTrue (r.Read (), label + "#2");
			XmlAssert.AssertNode (label + "#3", r,
				// NodeType, Depth, IsEmptyElement
				XmlNodeType.Element, 0, true,
				// Name, Prefix, LocalName, NamespaceURI
				"root", String.Empty, "root", String.Empty,
				// Value, HasValue, AttributeCount, HasAttributes
				String.Empty, false, 0, false);

			Assert.IsFalse (r.Read (), label + "#4");
		}
		public void ReadSubtreeNamespace ()
		{
			string xml = "<root xmlns='urn:foo' />";
			nav = GetXmlDocumentNavigator (xml);
			nav.MoveToFirstChild ();
			nav.MoveToFirstNamespace ();
			nav.ReadSubtree ();
		}
		public void ReadSubtreeAttribute ()
		{
			string xml = "<root a='b' />";
			nav = GetXmlDocumentNavigator (xml);
			nav.MoveToFirstChild ();
			nav.MoveToFirstAttribute ();
			nav.ReadSubtree ();
		}
		void MoveToFirstAttributeFromAttribute (XPathNavigator nav, string label)
		{
			XmlReader r = nav.ReadSubtree ();
			r.MoveToContent ();
			Assert.IsTrue (r.MoveToFirstAttribute (), label + "#1");
			Assert.IsTrue (r.MoveToFirstAttribute (), label + "#2");
			r.ReadAttributeValue ();
			Assert.IsTrue (r.MoveToFirstAttribute (), label + "#3");
			Assert.IsTrue (r.MoveToNextAttribute (), label + "#4");
			Assert.IsTrue (r.MoveToFirstAttribute (), label + "#5");
		}
		void MixedContentAndDepth (XPathNavigator nav, string label)
		{
			XmlReader r = nav.ReadSubtree ();
			r.Read ();
			XmlAssert.AssertNode (label + "#1", r,
				// NodeType, Depth, IsEmptyElement
				XmlNodeType.Element, 0, false,
				// Name, Prefix, LocalName, NamespaceURI
				"one", String.Empty, "one", String.Empty,
				// Value, HasValue, AttributeCount, HasAttributes
				String.Empty, false, 0, false);

			r.Read ();
			XmlAssert.AssertNode (label + "#2", r,
				// NodeType, Depth, IsEmptyElement
				XmlNodeType.Element, 1, false,
				// Name, Prefix, LocalName, NamespaceURI
				"two", String.Empty, "two", String.Empty,
				// Value, HasValue, AttributeCount, HasAttributes
				String.Empty, false, 0, false);

			r.Read ();
			XmlAssert.AssertNode (label + "#3", r,
				// NodeType, Depth, IsEmptyElement
				XmlNodeType.Text, 2, false,
				// Name, Prefix, LocalName, NamespaceURI
				String.Empty, String.Empty, String.Empty, String.Empty,
				// Value, HasValue, AttributeCount, HasAttributes
				"Some data.", true, 0, false);

			r.Read ();
			XmlAssert.AssertNode (label + "#4", r,
				// NodeType, Depth, IsEmptyElement
				XmlNodeType.Element, 2, false,
				// Name, Prefix, LocalName, NamespaceURI
				"three", String.Empty, "three", String.Empty,
				// Value, HasValue, AttributeCount, HasAttributes
				String.Empty, false, 0, false);

			r.Read ();
			XmlAssert.AssertNode (label + "#5", r,
				// NodeType, Depth, IsEmptyElement
				XmlNodeType.Text, 3, false,
				// Name, Prefix, LocalName, NamespaceURI
				String.Empty, String.Empty, String.Empty, String.Empty,
				// Value, HasValue, AttributeCount, HasAttributes
				"more", true, 0, false);

			r.Read ();
			XmlAssert.AssertNode (label + "#6", r,
				// NodeType, Depth, IsEmptyElement
				XmlNodeType.EndElement, 2, false,
				// Name, Prefix, LocalName, NamespaceURI
				"three", String.Empty, "three", String.Empty,
				// Value, HasValue, AttributeCount, HasAttributes
				String.Empty, false, 0, false);

			r.Read ();
			XmlAssert.AssertNode (label + "#7", r,
				// NodeType, Depth, IsEmptyElement
				XmlNodeType.Text, 2, false,
				// Name, Prefix, LocalName, NamespaceURI
				String.Empty, String.Empty, String.Empty, String.Empty,
				// Value, HasValue, AttributeCount, HasAttributes
				" done.", true, 0, false);

			r.Read ();
			XmlAssert.AssertNode (label + "#8", r,
				// NodeType, Depth, IsEmptyElement
				XmlNodeType.EndElement, 1, false,
				// Name, Prefix, LocalName, NamespaceURI
				"two", String.Empty, "two", String.Empty,
				// Value, HasValue, AttributeCount, HasAttributes
				String.Empty, false, 0, false);

			r.Read ();
			XmlAssert.AssertNode (label + "#9", r,
				// NodeType, Depth, IsEmptyElement
				XmlNodeType.EndElement, 0, false,
				// Name, Prefix, LocalName, NamespaceURI
				"one", String.Empty, "one", String.Empty,
				// Value, HasValue, AttributeCount, HasAttributes
				String.Empty, false, 0, false);

			Assert.IsFalse (r.Read (), label + "#10");
		}
 // Begin: GetNodeInfo
 private void GetNodeInfo(XPathNavigator nav1)
 {
   if (nav1 != null && nav1.Name != null && nav1.Name.ToString(CultureInfo.CurrentCulture).Equals("images", StringComparison.CurrentCulture))
   {
     using (var xmlReader = nav1.ReadSubtree())
     {
       var searchResults = new SearchResults();
       while (xmlReader.Read())
       {
         if (xmlReader.NodeType == XmlNodeType.Element)
         {
           switch (xmlReader.Name)
           {
             case "id":
               searchResults = new SearchResults();
               searchResults.Id = xmlReader.ReadString();
               continue;
             case "album":
               searchResults.Album = xmlReader.ReadString();
               continue;
             case "title":
               searchResults.Title = xmlReader.ReadString();
               continue;
             case "alias":
               searchResults.AddAlias(xmlReader.ReadString());
               continue;
             case "mbid":
               searchResults.MBID = xmlReader.ReadString();
               continue;
             case "votes":
               alSearchResults.Add(searchResults);
               continue;
             default:
               continue;
           }
         }
       }
     }
   }
   if (nav1 != null && nav1.HasChildren)
   {
     nav1.MoveToFirstChild();
     while (nav1.MoveToNext())
     {
       GetNodeInfo(nav1);
       nav1.MoveToParent();
     }
   }
   else
   {
     if (nav1 == null || !nav1.MoveToNext())
       return;
     GetNodeInfo(nav1);
   }
 }
		void DocElem_OpenClose_Attribute (XPathNavigator nav, string label)
		{
			XmlReader r = nav.ReadSubtree ();

			XmlAssert.AssertNode (label + "#1", r,
				// NodeType, Depth, IsEmptyElement
				XmlNodeType.None, 0, false,
				// Name, Prefix, LocalName, NamespaceURI
				String.Empty, String.Empty, String.Empty, String.Empty,
				// Value, HasValue, AttributeCount, HasAttributes
				String.Empty, false, 0, false);

			Assert.IsTrue (r.Read (), label + "#2");
			XmlAssert.AssertNode (label + "#3", r,
				// NodeType, Depth, IsEmptyElement
				XmlNodeType.Element, 0, false,
				// Name, Prefix, LocalName, NamespaceURI
				"root", String.Empty, "root", String.Empty,
				// Value, HasValue, AttributeCount, HasAttributes
				String.Empty, false, 1, true);

			Assert.IsTrue (r.MoveToFirstAttribute (), label + "#4");
			XmlAssert.AssertNode (label + "#5", r,
				// NodeType, Depth, IsEmptyElement
				XmlNodeType.Attribute, 1, false,
				// Name, Prefix, LocalName, NamespaceURI
				"attr", String.Empty, "attr", String.Empty,
				// Value, HasValue, AttributeCount, HasAttributes
				"value", true, 1, true);

			Assert.IsTrue (r.ReadAttributeValue (), label + "#6");
			XmlAssert.AssertNode (label + "#7", r,
				// NodeType, Depth, IsEmptyElement
				XmlNodeType.Text, 2, false,
				// Name, Prefix, LocalName, NamespaceURI
				String.Empty, String.Empty, String.Empty, String.Empty,
				// Value, HasValue, AttributeCount, HasAttributes
				"value", true, 1, true);

			Assert.IsFalse (r.ReadAttributeValue (), label + "#8");
			Assert.IsFalse (r.MoveToNextAttribute (), label + "#9");
			Assert.IsTrue (r.MoveToElement (), label + "#10");

			Assert.IsTrue (r.Read (), label + "#11");
			XmlAssert.AssertNode (label + "#12", r,
				// NodeType, Depth, IsEmptyElement
				XmlNodeType.EndElement, 0, false,
				// Name, Prefix, LocalName, NamespaceURI
				"root", String.Empty, "root", String.Empty,
				// Value, HasValue, AttributeCount, HasAttributes
				String.Empty, false, 0, false);

			Assert.IsFalse (r.Read (), label + "#13");
		}
 public static object Deserialize( Type type, XPathNavigator nav )
 {
     XmlSerializer serializer = new XmlSerializer( type );
     return serializer.Deserialize( nav.ReadSubtree() );
 }
 /// <summary>
 /// Reads the IO spec.
 /// </summary>
 /// <param name="nav">A cursor in the xml data</param>
 /// <returns></returns>
 internal static IOSpec ReadIOSpec(XPathNavigator nav)
 {
     IOSpec temporaryIOSpec = new IOSpec();
     if (nav != null)
     {
         var reader = nav.ReadSubtree();
         reader.Read();
         temporaryIOSpec.ReadXml(reader);
     }
     return temporaryIOSpec;
 }
        /// <summary>
        /// Constructs experiment node connection from given xml xpath navigator to the edge.
        /// </summary>
        /// <param name="reader">The reader with edge root.</param>
        /// <returns>experiment node connection</returns>
        public ExperimentNodeConnection EdgeFactory(XPathNavigator reader)
        {
            string id = reader.GetAttribute("id", String.Empty);
            string source = reader.GetAttribute("source", String.Empty);
            string target = reader.GetAttribute("target", String.Empty);
            
            //try read is fixed attribute
            string isFixedAttrib = reader.GetAttribute("isFixed", String.Empty);
            bool isFixed;
            if (!Boolean.TryParse(isFixedAttrib, out isFixed)) isFixed = false;

            //try read is visible attribute
            string isVisibleAttrib = reader.GetAttribute("isVisible", String.Empty);
            bool isVisible;
            if (!Boolean.TryParse(isVisibleAttrib, out isVisible)) isVisible = true;

            //validate
            if (m_vertices.ContainsKey(source) == false || m_vertices.ContainsKey(target) == false)
            {
                throw new TraceLab.Core.Exceptions.ExperimentLoadException("The experiment is corrupted and could not be loaded. Experiment xml contains edge that refers to non-existing nodes.");
            }
            ExperimentNode sourceVert = m_vertices[source];
            ExperimentNode targetVert = m_vertices[target];

            ExperimentNodeConnection edge = new ExperimentNodeConnection(id, sourceVert, targetVert, isFixed, isVisible);
            edge.IsModified = false;
            m_edges[id] = edge;

            //read in route points from xml
            edge.RoutePoints.ReadXml(reader.ReadSubtree());

            //perform fixes for scopes 
            ScopeNodeHelper.TryFixScopeDecisionEntryAndExitNodes(sourceVert, targetVert);
            
            return edge;
        }
		public void ReadSubtreeComment ()
		{
			string xml = "<!-- comment --><root xmlns='urn:foo' />";
			nav = GetXmlDocumentNavigator (xml);
			nav.MoveToFirstChild ();
			nav.ReadSubtree ();
		}
Exemple #16
0
        public XmlNode ToXmlNode(XPathNavigator nav)
        {
            IHasXmlNode hasNode = nav as IHasXmlNode;
            if (hasNode != null)
            {
                XmlNode node = hasNode.GetNode();
                if (node != null)
                {
                    if (node.OwnerDocument != _carrier)
                        node = _carrier.ImportNode(node, true);
                    return node;
                }
            }
            switch (nav.NodeType)
            {
                case XPathNodeType.Root:
                    {
                        XmlDocument doc = new XmlDocument(nav.NameTable);
                        doc.Load(nav.ReadSubtree());
                        doc.InsertBefore(doc.CreateXmlDeclaration("1.0", "utf-8", null),
                            doc.FirstChild);
                        return doc;
                    }

                case XPathNodeType.Element:
                    {
                        XmlElement tmp = _carrier.CreateElement("dummy");
                        XPathNavigator dest = tmp.CreateNavigator();
                        dest.AppendChild(nav.ReadSubtree());
                        return tmp.FirstChild;
                    }

                case XPathNodeType.Attribute:
                    {
                        XmlAttribute attr = _carrier.CreateAttribute(nav.Prefix, nav.LocalName, nav.NamespaceURI);
                        attr.Value = nav.Value;
                        return attr;
                    }

                case XPathNodeType.Namespace:
                    {
                        XmlAttribute ns;
                        if (nav.Name == "")
                            ns = _carrier.CreateAttribute(String.Empty, "xmlns", XmlReservedNs.NsXmlNs);
                        else
                            ns = _carrier.CreateAttribute("xmlns", nav.LocalName, XmlReservedNs.NsXmlNs);
                        ns.Value = nav.Value;
                        return ns;
                    }

                case XPathNodeType.Comment:
                    return _carrier.CreateComment(nav.Value);

                case XPathNodeType.Text:
                    return _carrier.CreateTextNode(nav.Value);

                case XPathNodeType.SignificantWhitespace:
                    return _carrier.CreateSignificantWhitespace(nav.Value);

                case XPathNodeType.Whitespace:
                    return _carrier.CreateWhitespace(nav.Value);

                case XPathNodeType.ProcessingInstruction:
                    return _carrier.CreateProcessingInstruction(nav.Name, nav.Value);

                default:
                    throw new ArgumentException("nav");                    
            }
        }
		void FromChildElement (XPathNavigator nav, string label)
		{
			XmlReader r = nav.ReadSubtree ();

			XmlAssert.AssertNode (label + "#1", r,
				// NodeType, Depth, IsEmptyElement
				XmlNodeType.None, 0, false,
				// Name, Prefix, LocalName, NamespaceURI
				String.Empty, String.Empty, String.Empty, String.Empty,
				// Value, HasValue, AttributeCount, HasAttributes
				String.Empty, false, 0, false);

			Assert.IsTrue (r.Read (), label + "#2");
			XmlAssert.AssertNode (label + "#3", r,
				// NodeType, Depth, IsEmptyElement
				XmlNodeType.Element, 0, false,
				// Name, Prefix, LocalName, NamespaceURI
				"foo", String.Empty, "foo", String.Empty,
				// Value, HasValue, AttributeCount, HasAttributes
				String.Empty, false, 1, true);

			Assert.IsTrue (r.Read (), label + "#4");
			XmlAssert.AssertNode (label + "#5", r,
				// NodeType, Depth, IsEmptyElement
				XmlNodeType.Text, 1, false,
				// Name, Prefix, LocalName, NamespaceURI
				String.Empty, String.Empty, String.Empty, String.Empty,
				// Value, HasValue, AttributeCount, HasAttributes
				"test", true, 0, false);

			Assert.IsTrue (r.Read (), label + "#6");
			XmlAssert.AssertNode (label + "#7", r,
				// NodeType, Depth, IsEmptyElement
				XmlNodeType.EndElement, 0, false,
				// Name, Prefix, LocalName, NamespaceURI
				"foo", String.Empty, "foo", String.Empty,
				// Value, HasValue, AttributeCount, HasAttributes
				String.Empty, false, 0, false);

			// end at </foo>, without moving toward <bar>.
			Assert.IsFalse (r.Read (), label + "#8");
		}
 internal static ConfigWrapper ReadConfig(XPathNavigator nav)
 {
     ConfigWrapper tmpConfigWrapper = new ConfigWrapper();
     tmpConfigWrapper.ReadXml(nav.ReadSubtree());
     return tmpConfigWrapper;
 }
		void AttributesAndNamespaces (XPathNavigator nav, string label)
		{
			XmlReader r = nav.ReadSubtree ();

			XmlAssert.AssertNode (label + "#1", r,
				// NodeType, Depth, IsEmptyElement
				XmlNodeType.None, 0, false,
				// Name, Prefix, LocalName, NamespaceURI
				String.Empty, String.Empty, String.Empty, String.Empty,
				// Value, HasValue, AttributeCount, HasAttributes
				String.Empty, false, 0, false);

			Assert.IsTrue (r.Read (), label + "#2");
			XmlAssert.AssertNode (label + "#3", r,
				// NodeType, Depth, IsEmptyElement
				XmlNodeType.Element, 0, false,
				// Name, Prefix, LocalName, NamespaceURI
				"root", String.Empty, "root", "urn:default",
				// Value, HasValue, AttributeCount, HasAttributes
				String.Empty, false, 4, true);

			// Namespaces

			Assert.IsTrue (r.MoveToAttribute ("xmlns:x"), label + "#4");
			XmlAssert.AssertNode (label + "#5", r,
				// NodeType, Depth, IsEmptyElement
				XmlNodeType.Attribute, 1, false,
				// Name, Prefix, LocalName, NamespaceURI
				"xmlns:x", "xmlns", "x",
				"http://www.w3.org/2000/xmlns/",
				// Value, HasValue, AttributeCount, HasAttributes
				"urn:foo", true, 4, true);

			Assert.IsTrue (r.ReadAttributeValue (), label + "#6");
///* MS.NET has a bug here
			XmlAssert.AssertNode (label + "#7", r,
				// NodeType, Depth, IsEmptyElement
				XmlNodeType.Text, 2, false,
				// Name, Prefix, LocalName, NamespaceURI
				String.Empty, String.Empty, String.Empty, String.Empty,
				// Value, HasValue, AttributeCount, HasAttributes
				"urn:foo", true, 4, true);
//*/

			Assert.IsFalse (r.ReadAttributeValue (), label + "#8");

			Assert.IsTrue (r.MoveToAttribute ("xmlns"), label + "#9");
			XmlAssert.AssertNode (label + "#10", r,
				// NodeType, Depth, IsEmptyElement
				XmlNodeType.Attribute, 1, false,
				// Name, Prefix, LocalName, NamespaceURI
				"xmlns", String.Empty, "xmlns",
				"http://www.w3.org/2000/xmlns/",
				// Value, HasValue, AttributeCount, HasAttributes
				"urn:default", true, 4, true);

			Assert.IsTrue (r.ReadAttributeValue (), label + "#11");
///* MS.NET has a bug here
			XmlAssert.AssertNode (label + "#12", r,
				// NodeType, Depth, IsEmptyElement
				XmlNodeType.Text, 2, false,
				// Name, Prefix, LocalName, NamespaceURI
				String.Empty, String.Empty, String.Empty, String.Empty,
				// Value, HasValue, AttributeCount, HasAttributes
				"urn:default", true, 4, true);
//*/

			Assert.IsFalse (r.ReadAttributeValue (), label + "#13");

			// Attributes

			Assert.IsTrue (r.MoveToAttribute ("attr"), label + "#14");
			XmlAssert.AssertNode (label + "#15", r,
				// NodeType, Depth, IsEmptyElement
				XmlNodeType.Attribute, 1, false,
				// Name, Prefix, LocalName, NamespaceURI
				"attr", String.Empty, "attr", String.Empty,
				// Value, HasValue, AttributeCount, HasAttributes
				"value", true, 4, true);

			Assert.IsTrue (r.ReadAttributeValue (), label + "#16");
			XmlAssert.AssertNode (label + "#17", r,
				// NodeType, Depth, IsEmptyElement
				XmlNodeType.Text, 2, false,
				// Name, Prefix, LocalName, NamespaceURI
				String.Empty, String.Empty, String.Empty, String.Empty,
				// Value, HasValue, AttributeCount, HasAttributes
				"value", true, 4, true);

			Assert.IsFalse (r.ReadAttributeValue (), label + "#18");

			Assert.IsTrue (r.MoveToAttribute ("x:a2"), label + "#19");
			XmlAssert.AssertNode (label + "#20", r,
				// NodeType, Depth, IsEmptyElement
				XmlNodeType.Attribute, 1, false,
				// Name, Prefix, LocalName, NamespaceURI
				"x:a2", "x", "a2", "urn:foo",
				// Value, HasValue, AttributeCount, HasAttributes
				"v2", true, 4, true);

			Assert.IsTrue (r.ReadAttributeValue (), label + "#21");
			XmlAssert.AssertNode (label + "#22", r,
				// NodeType, Depth, IsEmptyElement
				XmlNodeType.Text, 2, false,
				// Name, Prefix, LocalName, NamespaceURI
				String.Empty, String.Empty, String.Empty, String.Empty,
				// Value, HasValue, AttributeCount, HasAttributes
				"v2", true, 4, true);

			Assert.IsTrue (r.MoveToElement (), label + "#24");

			Assert.IsTrue (r.Read (), label + "#25");
			XmlAssert.AssertNode (label + "#26", r,
				// NodeType, Depth, IsEmptyElement
				XmlNodeType.EndElement, 0, false,
				// Name, Prefix, LocalName, NamespaceURI
				"root", String.Empty, "root", "urn:default",
				// Value, HasValue, AttributeCount, HasAttributes
				String.Empty, false, 0, false);

			Assert.IsFalse (r.Read (), label + "#27");
		}