/// <summary> /// Creates acquired infoset. /// </summary> private string CreateAcquiredInfoset(Uri includeLocation) { if (_cache == null) _cache = new Dictionary<string, WeakReference>(); WeakReference wr; if (_cache.TryGetValue(includeLocation.AbsoluteUri, out wr) && wr.IsAlive) { return (string)wr.Target; } else { //Not cached or GCollected WebResponse wRes; Stream stream = GetResource(includeLocation.AbsoluteUri, _reader.GetAttribute(_keywords.Accept), _reader.GetAttribute(_keywords.AcceptLanguage), out wRes); XIncludingReader xir = new XIncludingReader(wRes.ResponseUri.AbsoluteUri, stream, _nameTable); xir.WhitespaceHandling = _whiteSpaceHandling; StringWriter sw = new StringWriter(); XmlTextWriter w = new XmlTextWriter(sw); try { while (xir.Read()) w.WriteNode(xir, false); } finally { if (xir != null) xir.Close(); if (w != null) w.Close(); } string content = sw.ToString(); lock (_cache) { if (!_cache.ContainsKey(includeLocation.AbsoluteUri)) _cache.Add(includeLocation.AbsoluteUri, new WeakReference(content)); } return content; } }
/// <summary> /// Creates acquired infoset. /// </summary> /// <param name="reader">Source reader</param> private string CreateAcquiredInfoset(XmlReader reader) { //TODO: Try to stream out this stuff XIncludingReader xir = new XIncludingReader(reader); xir.XmlResolver = this._xmlResolver; StringWriter sw = new StringWriter(); XmlTextWriter w = new XmlTextWriter(sw); try { while (xir.Read()) w.WriteNode(xir, false); } finally { if (xir != null) xir.Close(); if (w != null) w.Close(); } return sw.ToString(); }
public void ShouldPreserveCDATA() { string xml = "<HTML><![CDATA[<img src=\"/_layouts/images/\">]]></HTML>"; XIncludingReader xir = new XIncludingReader(new StringReader(xml)); xir.Read(); Assert.AreEqual("<HTML><![CDATA[<img src=\"/_layouts/images/\">]]></HTML>", xir.ReadOuterXml()); }
public void TestLineInfo() { XIncludingReader r = new XIncludingReader("../../XInclude/tests/document.xml"); IXmlLineInfo lineInfo = ((IXmlLineInfo)r); Assert.IsTrue(lineInfo.HasLineInfo()); r.Read(); Assert.AreEqual(1, lineInfo.LineNumber); Assert.AreEqual(3, lineInfo.LinePosition); r.Read(); Assert.AreEqual(1, lineInfo.LineNumber); Assert.AreEqual(22, lineInfo.LinePosition); r.Read(); Assert.AreEqual(2, lineInfo.LineNumber); Assert.AreEqual(2, lineInfo.LinePosition); r.Read(); Assert.AreEqual(2, lineInfo.LineNumber); Assert.AreEqual(54, lineInfo.LinePosition); r.Read(); Assert.AreEqual(3, lineInfo.LineNumber); Assert.AreEqual(6, lineInfo.LinePosition); r.Read(); Assert.AreEqual(3, lineInfo.LineNumber); Assert.AreEqual(8, lineInfo.LinePosition); r.Read(); Assert.AreEqual(3, lineInfo.LineNumber); Assert.AreEqual(54, lineInfo.LinePosition); r.Read(); Assert.AreEqual(3, lineInfo.LineNumber); Assert.AreEqual(56, lineInfo.LinePosition); r.Read(); Assert.AreEqual(1, lineInfo.LineNumber); Assert.AreEqual(22, lineInfo.LinePosition); r.Read(); Assert.AreEqual(2, lineInfo.LineNumber); Assert.AreEqual(5, lineInfo.LinePosition); r.Read(); Assert.AreEqual(2, lineInfo.LineNumber); Assert.AreEqual(17, lineInfo.LinePosition); r.Read(); Assert.AreEqual(3, lineInfo.LineNumber); Assert.AreEqual(3, lineInfo.LinePosition); r.Read(); Assert.AreEqual(3, lineInfo.LineNumber); Assert.AreEqual(12, lineInfo.LinePosition); r.Read(); Assert.AreEqual(4, lineInfo.LineNumber); Assert.AreEqual(2, lineInfo.LinePosition); r.Read(); Assert.AreEqual(4, lineInfo.LineNumber); Assert.AreEqual(13, lineInfo.LinePosition); r.Read(); Assert.AreEqual(5, lineInfo.LineNumber); Assert.AreEqual(4, lineInfo.LinePosition); r.Read(); Assert.AreEqual(5, lineInfo.LineNumber); Assert.AreEqual(6, lineInfo.LinePosition); r.Read(); Assert.AreEqual(7, lineInfo.LineNumber); Assert.AreEqual(18, lineInfo.LinePosition); r.Read(); Assert.AreEqual(7, lineInfo.LineNumber); Assert.AreEqual(20, lineInfo.LinePosition); r.Read(); Assert.AreEqual(8, lineInfo.LineNumber); Assert.AreEqual(3, lineInfo.LinePosition); r.Read(); Assert.AreEqual(4, lineInfo.LineNumber); Assert.AreEqual(75, lineInfo.LinePosition); r.Read(); Assert.AreEqual(6, lineInfo.LineNumber); Assert.AreEqual(3, lineInfo.LinePosition); r.Read(); Assert.AreEqual(6, lineInfo.LineNumber); Assert.AreEqual(12, lineInfo.LinePosition); }
public void GetAttributeTest3() { XIncludingReader xir = new XIncludingReader("../../XInclude/tests/document.xml"); while (xir.Read()) { if (xir.NodeType == XmlNodeType.Element && xir.Name == "disclaimer") { Assert.IsTrue(xir.AttributeCount == 1); xir.MoveToAttribute(0); Assert.IsTrue(xir.Name == "xml:base"); Assert.IsTrue(xir.Value.EndsWith("disclaimer.xml")); } } }
public void GetAttributeTest4() { XIncludingReader xir = new XIncludingReader("../../XInclude/tests/document2.xml"); xir.MakeRelativeBaseUri = false; while (xir.Read()) { if (xir.NodeType == XmlNodeType.Element && xir.Name == "disclaimer") { Assert.IsTrue(xir.AttributeCount == 1); xir.MoveToAttribute(0); Console.WriteLine(xir.Value); Assert.IsTrue(xir.Name == "xml:base"); Assert.IsTrue(xir.Value.EndsWith("tests/disclaimerWithXmlBase.xml")); } } }
public void DepthTest() { XIncludingReader xir = new XIncludingReader("../../XInclude/tests/document.xml"); StringBuilder sb = new StringBuilder(); while (xir.Read()) { Console.WriteLine("{0} | {1} | {2} | {3}", xir.NodeType, xir.Name, xir.Value, xir.Depth); sb.Append(xir.Depth); } string expected = "00011211111111223221100"; Assert.AreEqual(sb.ToString(), expected); }
public void NoBaseURITest() { StreamReader sr = new StreamReader("../../XInclude/tests/document.xml"); string xml = sr.ReadToEnd(); sr.Close(); XIncludingReader xir = new XIncludingReader(new StringReader(xml)); XmlWriter w = XmlWriter.Create(Console.Out); while (xir.Read()); }
public void TwoFallbacks() { XIncludingReader xir = new XIncludingReader("../../XInclude/tests/twofallbacks.xml"); while (xir.Read()); xir.Close(); }
public void UnknownParseAttribute() { XIncludingReader xir = new XIncludingReader("../../XInclude/tests/unknownparseattr.xml"); while (xir.Read()); xir.Close(); }
public void FallbackNotChildOfInclude() { XIncludingReader xir = new XIncludingReader("../../XInclude/tests/fallbacknotchildinclude.xml"); while (xir.Read()); xir.Close(); }
public void IncludeChildOfInclude() { XIncludingReader xir = new XIncludingReader("../../XInclude/tests/includechildofinclude.xml"); while (xir.Read()); xir.Close(); }
public void NoHrefAndNoXPointerAttributes() { XIncludingReader xir = new XIncludingReader("../../XInclude/tests/nohref.xml"); while (xir.Read()); xir.Close(); }