public void BasicTest() { XmlTextReader r = new XmlBaseAwareXmlTextReader( Globals.GetResource( this.GetType().Namespace + ".test.xml")); while (r.Read()) { if (r.NodeType == XmlNodeType.Element) { switch (r.Name) { case "catalog": Assert.IsTrue(r.BaseURI == ""); break; case "files": Assert.IsTrue(r.BaseURI == "file:///d:/Files/"); break; case "file": Assert.IsTrue(r.BaseURI == "file:///d:/Files/"); break; case "a": Assert.IsTrue(r.BaseURI == ""); break; case "b": Assert.IsTrue(r.BaseURI == "file:///d:/Files/a/"); break; case "c": Assert.IsTrue(r.BaseURI == "file:///d:/Files/c/"); break; case "e": Assert.IsTrue(r.BaseURI == "file:///d:/Files/c/"); break; case "d": Assert.IsTrue(r.BaseURI == "file:///d:/Files/a/"); break; } } else if (r.NodeType == XmlNodeType.Text && r.Value.Trim() != "") { Assert.IsTrue(r.BaseURI == "file:///d:/Files/c/"); } else if (r.NodeType == XmlNodeType.Comment) { Assert.IsTrue(r.BaseURI == "file:///d:/Files/a/"); } else if (r.NodeType == XmlNodeType.ProcessingInstruction) { Assert.IsTrue(r.BaseURI == "file:///d:/Files/"); } } r.Close(); }
public void BasicTest() { XmlTextReader r = new XmlBaseAwareXmlTextReader("../../Common/XmlBaseAwareXmlTextReaderTests/test.xml"); while (r.Read()) { if (r.NodeType == XmlNodeType.Element) { switch (r.Name) { case "catalog": Assert.IsTrue(r.BaseURI.EndsWith("XmlBaseAwareXmlTextReaderTests/test.xml")); break; case "files": Assert.IsTrue(r.BaseURI == "file:///d:/Files/"); break; case "file": Assert.IsTrue(r.BaseURI == "file:///d:/Files/"); break; case "a": Assert.IsTrue(r.BaseURI.EndsWith("XmlBaseAwareXmlTextReaderTests/test.xml")); break; case "b": Assert.IsTrue(r.BaseURI == "file:///d:/Files/a/"); break; case "c": Assert.IsTrue(r.BaseURI == "file:///d:/Files/c/"); break; case "e": Assert.IsTrue(r.BaseURI == "file:///d:/Files/c/"); break; case "d": Assert.IsTrue(r.BaseURI == "file:///d:/Files/a/"); break; } } else if (r.NodeType == XmlNodeType.Text && r.Value.Trim() != "") { Assert.IsTrue(r.BaseURI == "file:///d:/Files/c/"); } else if (r.NodeType == XmlNodeType.Comment) { Assert.IsTrue(r.BaseURI == "file:///d:/Files/a/"); } else if (r.NodeType == XmlNodeType.ProcessingInstruction) { Assert.IsTrue(r.BaseURI == "file:///d:/Files/"); } } r.Close(); }
public void ReaderWithPath() { XmlTextReader r = new XmlBaseAwareXmlTextReader("../../Common/XmlBaseAwareXmlTextReaderTests/relativeTest.xml"); r.WhitespaceHandling = WhitespaceHandling.None; XPathDocument doc = new XPathDocument(r); XPathNavigator nav = doc.CreateNavigator(); XPathNodeIterator ni = nav.Select("/catalog"); ni.MoveNext(); Assert.IsTrue(ni.Current.BaseURI.EndsWith("/XmlBaseAwareXmlTextReaderTests/relativeTest.xml")); ni = nav.Select("/catalog/relative/relativenode"); ni.MoveNext(); Console.WriteLine(ni.Current.BaseURI); Assert.IsTrue(ni.Current.BaseURI.IndexOf("/XmlBaseAwareXmlTextReaderTests/") != -1); }
/// <summary> /// Creates <c>XPointerReader</c> instance with given /// document's URI and content. /// </summary> /// <param name="uri">XML document's base URI</param> /// <param name="content">XML document's content</param> /// <param name="xpointer">XPointer pointer</param> public XPointerReader(string uri, string content, string xpointer) { XPathDocument doc = null; if (_cache == null) { _cache = new Dictionary <string, WeakReference>(); } WeakReference wr; if (_cache.TryGetValue(uri, out wr) && wr.IsAlive) { doc = (XPathDocument)wr.Target; } else { //Not cached or GCollected XmlReader r = new XmlBaseAwareXmlTextReader(uri, new StringReader(content)); doc = CreateAndCacheDocument(r); } Init(doc.CreateNavigator(), xpointer); }