コード例 #1
0
ファイル: Tests.cs プロジェクト: zanyants/mvp.xml
 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();
 }   
コード例 #2
0
ファイル: Tests.cs プロジェクト: zanyants/mvp.xml
		public void ReaderWithPath() 
		{
			XmlTextReader r = new XmlBaseAwareXmlTextReader(@"..\..\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);
		}   
コード例 #3
0
ファイル: Tests.cs プロジェクト: zanyants/mvp.xml
        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();
        }   
コード例 #4
0
ファイル: XIncludingReader.cs プロジェクト: zanyants/mvp.xml
        /// <summary>
        /// Processes inter-document inclusion (xml mode).
        /// </summary>
        /// <param name="href">'href' attr value</param>
        /// <param name="xpointer">'xpointer attr value'</param>
        private bool ProcessInterDocXMLInclusion(string href, string xpointer) 
        {
            //Include document as XML                                
            Uri includeLocation = ResolveHref(href);                
            if (includeLocation.Fragment != String.Empty)
                throw new XIncludeSyntaxError(SR.FragmentIDInHref);
            CheckLoops(includeLocation, xpointer);            
            if (_xmlResolver == null) 
            {	
                //No custom resolver
                if (xpointer != null) 
                {
                    //Push current reader to the stack
                    _readers.Push(_reader);           
                    //XPointers should be resolved against the acquired infoset, 
                    //not the source infoset                                                                                          
                    _reader = new XPointerReader(includeLocation.AbsoluteUri, 
                        CreateAcquiredInfoset(includeLocation), 
                        xpointer);                    
                }
                else 
                {                
                    WebResponse wRes;
                    Stream stream =  GetResource(includeLocation.AbsoluteUri, 
                        _reader.GetAttribute(_keywords.Accept),						
                        _reader.GetAttribute(_keywords.AcceptLanguage), out wRes);                                                    
                    //Push current reader to the stack
                    _readers.Push(_reader);                
                    XmlTextReader r = new XmlBaseAwareXmlTextReader(wRes.ResponseUri.AbsoluteUri, stream, _nameTable);
                    r.Normalization = _normalization;
                    r.WhitespaceHandling = _whiteSpaceHandling;
                    r.XmlResolver = _xmlResolver;
                    _reader = r;                    
                }                                                           
                return Read();                
            } 
            else 
            {
                //Custom resolver provided, let's ask him
                object resource;
                try 
                {
                    resource = _xmlResolver.GetEntity(includeLocation, null, null);
                } 
                catch (Exception e) 
                {
                    throw new ResourceException(SR.CustomXmlResolverError, e);
                }
                if (resource == null)					
                    throw new ResourceException(SR.CustomXmlResolverReturnedNull);						                    

                //Push current reader to the stack
                _readers.Push(_reader);			

                //Ok, we accept Stream, TextReader and XmlReader only                    
                if (resource is Stream)
                    resource = new StreamReader((Stream)resource);
                if (xpointer != null) 
                {
                    if (resource is TextReader) 
                    {
                        //XPointers should be resolved against the acquired infoset, 
                        //not the source infoset                                     
                        _reader = new XPointerReader(includeLocation.AbsoluteUri,
                            CreateAcquiredInfoset(includeLocation, (TextReader)resource), 
                            xpointer);
                    }
                    else if (resource is XmlReader) 
                    {                        
                        XmlReader r = (XmlReader)resource;                        
                        _reader = new XPointerReader(r.BaseURI,
                            CreateAcquiredInfoset(r), xpointer);
                    }
                    else 
                    {
                        //Unsupported type
                        throw new ResourceException(SR.GetString(
                            "CustomXmlResolverReturnedUnsupportedType", 
                            resource.GetType().ToString()));										                    
                    }
                }
                else 
                {
                    //No XPointer   
                    if (resource is TextReader) 
                        _reader = new XmlBaseAwareXmlTextReader(includeLocation.AbsoluteUri, (TextReader)resource, _nameTable);                                                                    
                    else if (resource is XmlReader)                     
                        _reader = (XmlReader)resource;                                            
                    else 
                    {
                        //Unsupported type
                        throw new ResourceException(SR.GetString(
                            "CustomXmlResolverReturnedUnsupportedType", 
                            resource.GetType().ToString()));
                    }
                }                        
                    		                    			                                                        
                return Read();                                    
            }
        }
コード例 #5
0
ファイル: XPointerReader.cs プロジェクト: zanyants/mvp.xml
 /// <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);
 }