dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/System.Xml XmlDocument.cs,1.8,1.9 Xm


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/System.Xml XmlDocument.cs,1.8,1.9 XmlTextReader.cs,1.12,1.13
Date: Wed, 08 Jan 2003 18:48:54 -0500

Update of /cvsroot/dotgnu-pnet/pnetlib/System.Xml
In directory subversions:/tmp/cvs-serv11490/System.Xml

Modified Files:
        XmlDocument.cs XmlTextReader.cs 
Log Message:


XML reader updates.


Index: XmlDocument.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Xml/XmlDocument.cs,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** XmlDocument.cs      9 Dec 2002 04:04:04 -0000       1.8
--- XmlDocument.cs      8 Jan 2003 23:48:52 -0000       1.9
***************
*** 645,652 ****
  
        // Load XML into this document from a string.
-       [TODO]
        public virtual void LoadXml(String xml)
                        {
!                               // TODO
                        }
  
--- 645,694 ----
  
        // Load XML into this document from a string.
        public virtual void LoadXml(String xml)
                        {
!                               if (xml == null || xml == String.Empty)
!                               {
!                                       throw(new XmlException("no Xml to 
parse", null));
!                                       return;
!                               }
!                               
!                               XmlTextReader reader = new XmlTextReader(xml, 
XmlNodeType.Element, null);
!                               BuildStructure(reader);
!                       }
! 
!       // Used by Load/LoadXml methods to do the DOM structure
!       private bool BuildStructure(XmlTextReader reader)
!                       {
!                               XmlNode parent = this;
!                               XmlNode current;
! 
!                               while (reader.Read())
!                               {
!                                       if (reader.IsStartElement() == true)
!                                       {
!                                               XmlElement elem = 
this.CreateElement(reader.Name);
!                                               parent.AppendChild(elem);
!                                               parent = elem;
!                                               current = elem;
!                                       }
!                                       else
!                                       {
!                                               parent = parent.ParentNode;
!                                       }
!                                       if (reader.NodeType == XmlNodeType.Text)
!                                       {
!                                               // If node has body text
!                                               current.InnerText = 
reader.Value;
!                                       }
!                               }
!                               
!                               if (this.ChildNodes.Count >0)
!                               {
!                                       return true;
!                               }
!                               else
!                               {
!                                       return false;
!                               }
                        }
  

Index: XmlTextReader.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Xml/XmlTextReader.cs,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -r1.12 -r1.13
*** XmlTextReader.cs    24 Dec 2002 03:31:11 -0000      1.12
--- XmlTextReader.cs    8 Jan 2003 23:48:52 -0000       1.13
***************
*** 54,62 ****
        private String namespaceURI;
        private String value;
        private XmlAttributeCollection attributes;
        private int attributeIndex;
        private int depth;
        private bool isEmpty;
! 
        // Constructors.
        protected XmlTextReader()
--- 54,65 ----
        private String namespaceURI;
        private String value;
+       internal XmlAttribute attr;
        private XmlAttributeCollection attributes;
        private int attributeIndex;
        private int depth;
        private bool isEmpty;
!       internal bool contextSupport;
!       internal StringBuilder builder;
!       internal String name;
        // Constructors.
        protected XmlTextReader()
***************
*** 92,99 ****
                                namespaceURI = String.Empty;
                                value = String.Empty;
!                               attributes = null;
                                attributeIndex = -1;
                                depth = 1;
                                isEmpty = false;
                        }
        public XmlTextReader(Stream input)
--- 95,105 ----
                                namespaceURI = String.Empty;
                                value = String.Empty;
!                               attr = null;
!                               attributes = new XmlAttributeCollection(attr); 
                                attributeIndex = -1;
                                depth = 1;
                                isEmpty = false;
+                               contextSupport = false;
+                               name = String.Empty;
                        }
        public XmlTextReader(Stream input)
***************
*** 178,182 ****
                                        throw new 
XmlException(S._("Xml_InvalidNodeType"));
                                }
!                               // TODO
                        }
        [TODO]
--- 184,205 ----
                                        throw new 
XmlException(S._("Xml_InvalidNodeType"));
                                }
!                               
!                               if(context == null)
!                               {
!                                       baseURI = String.Empty;
!                                       // TODO: find byte order mark
!                                       // else ...
!                                       // encoding = 
System.Text.UT8Encoding(true);
!                               }
!                               else
!                               {
!                                       baseURI = context.BaseURI;
!                                       encoding = context.Encoding;
!                                       xmlLang = context.XmlLang;
!                                       xmlSpace = context.XmlSpace;
!                                       contextSupport = true;
!                               }
!                               namespaces = false;
!                               
                        }
        [TODO]
***************
*** 195,199 ****
                                        throw new 
XmlException(S._("Xml_InvalidNodeType"));
                                }
!                               // TODO
                        }
        public XmlTextReader(String url)
--- 218,242 ----
                                        throw new 
XmlException(S._("Xml_InvalidNodeType"));
                                }
!                       
!                               if(context == null)
!                               {
!                                       baseURI = String.Empty;
!                                       // TODO: find byte order mark
!                                       // else ...
!                                       // encoding = 
System.Text.UT8Encoding(true);
!                                       StringReader sr = new 
StringReader(xmlFragment);
!                                       encoding = Encoding.ASCII;
!                                       reader = sr;
!                               }
!                               else
!                               {
!                                       baseURI = context.BaseURI;
!                                       encoding = context.Encoding;
!                                       xmlLang = context.XmlLang;
!                                       xmlSpace = context.XmlSpace;
!                                       contextSupport = true;
!                               }
! 
!                               namespaces = false;     
                        }
        public XmlTextReader(String url)
***************
*** 434,440 ****
  
        // Read an identifier from the input stream.
!       private String ReadIdentifier()
                        {
!                               // TODO
                                return null;
                        }
--- 477,517 ----
  
        // Read an identifier from the input stream.
!       private String ReadIdentifier(int ch)
                        {
!                               StringBuilder builder = new StringBuilder();
! 
!                               if(ch != -1)
!                               {
!                                       builder.Append((char)ch);
!                               }
!                               
!                               while((ch = ReadChar()) != -1)
!                               {
!                                       builder.Append((char)ch);
!                                       linePosition++;
!                                       if((char)reader.Peek() == '>' )
!                                       {
!                                               nodeType = XmlNodeType.Element;
!                                               return builder.ToString();
!                                       }
!                                       else if((char)reader.Peek() == '/')
!                                       {
!                                               nodeType = 
XmlNodeType.EndElement;
!                                               isEmpty = true;
!                                               return builder.ToString();
!                                       }
!                                       else if((char)ch == '>')
!                                       {
!                                               nodeType = XmlNodeType.Element;
!                                               ungetch = ch;
!                                               return builder.ToString(0, 
builder.Length -1);
!                                       }
!                                       else if(Char.IsWhiteSpace((char)ch))
!                                       {
!                                               nodeType = XmlNodeType.Element;
!                                               return builder.ToString(0, 
builder.Length -1);
!                                       }
! 
!                               }
                                return null;
                        }
***************
*** 457,460 ****
--- 534,538 ----
                        }
  
+       
        // Skip white space characters.
        private void SkipWhite()
***************
*** 468,471 ****
--- 546,559 ----
                                                break;
                                        }
+                                       if((char)ch == '\n')
+                                       {
+                                               lineNumber++;
+                                               linePosition = 0;
+                                       }
+                                       else if(Char.IsWhiteSpace((char)ch))
+                                       {
+                                               linePosition++;
+                                       }
+                                               
                                }
                        }
***************
*** 481,525 ****
                        }
  
!       // Read the next node in the input stream.
!       [TODO]
!       public override bool Read()
                        {
!                               int ch;
!                               StringBuilder builder;
!                               String name;
!                               int count;
! 
!                               // Validate the current state of the stream.
!                               if(readState == ReadState.EndOfFile)
!                               {
!                                       return false;
!                               }
!                               else if(reader == null)
!                               {
!                                       throw new 
XmlException(S._("Xml_ReaderClosed"));
!                               }
!                               else if(readState == ReadState.Error)
!                               {
!                                       throw new 
XmlException(S._("Xml_ReaderError"));
!                               }
! 
!                               // Skip white space in the input stream.  TODO: 
collect
!                               // up significant white space.
!                               while((ch = ReadChar()) != -1)
!                               {
!                                       if(!Char.IsWhiteSpace((char)ch))
!                                       {
!                                               break;
!                                       }
!                                       if(ch == '\n')
!                                       {
!                                               ++lineNumber;
!                                               linePosition = 0;
!                                       }
!                               }
                                if(ch == -1)
                                {
-                                       // We've reached the end of the stream. 
 Throw
-                                       // an error if we haven't closed all 
elements.
                                        if(linePosition > 1)
                                        {
--- 569,577 ----
                        }
  
!       internal void AnalyzeChar(int ch, bool structFlag)
                        {
!                       
                                if(ch == -1)
                                {
                                        if(linePosition > 1)
                                        {
***************
*** 528,546 ****
                                        readState = ReadState.EndOfFile;
                                        ClearNodeInfo();
!                                       return false;
                                }
! 
!                               // Determine what to do based on the next 
character.
!                               if(ch == '<')
                                {
!                                       // Some kind of tag.
!                                       ch = ReadChar();
!                                       if(ch == '/')
!                                       {
                                                // End element tag.
!                                               name = ReadIdentifier();
                                                SkipWhite();
                                                Expect('>');
!                                               nodeType = XmlNodeType.Element;
                                                SetName(name);
                                                value = String.Empty;
--- 580,609 ----
                                        readState = ReadState.EndOfFile;
                                        ClearNodeInfo();
!                                       return;
                                }
!                               
!                               
!                               switch((char)ch)
                                {
!                                       case '<':
!                                               ch = ReadChar();
!                                               
!                                               // Set structFlag to true for 
specialchar
!                                               // start sequences
!                                               AnalyzeChar(ch, true);
!                                               break;
!                                       case '/':
!                                               // Check for correct structure 
!                                               if(structFlag != true)
!                                               {
!                                                       throw new XmlException
!                                                               
(S._("Xml_Malformed"));
!                                               }
!                                               
                                                // End element tag.
!                                               name = ReadIdentifier(-1);
                                                SkipWhite();
                                                Expect('>');
!                                               nodeType = 
XmlNodeType.EndElement;
                                                SetName(name);
                                                value = String.Empty;
***************
*** 548,649 ****
                                                attributeIndex = -1;
                                                isEmpty = false;
!                                               --depth;
!                                       }
!                                       else if(ch == '!')
!                                       {
                                                // Comment, CDATA, or document 
type information.
                                                ch = ReadChar();
!                                               if(ch == '-')
                                                {
!                                                       // Parse the "<!--" 
comment start sequence.
!                                                       ch = ReadChar();
!                                                       if(ch != '-')
!                                                       {
!                                                               
UngetAndThrow(ch);
!                                                       }
  
!                                                       // Search for the "-->" 
comment end sequence.
!                                                       builder = new 
StringBuilder();
!                                                       count = 0;
!                                                       while((ch = ReadChar()) 
!= -1)
                                                        {
-                                                               
builder.Append((char)ch);
-                                                               if(ch == '-')
-                                                               {
                                                                        ++count;
!                                                               }
!                                                               else if(ch == 
'>')
!                                                               {
!                                                                       
if(count >= 2)
!                                                                       {
!                                                                               
builder.Remove(builder.Length - 3, 3);
!                                                                               
break;
!                                                                       }
!                                                                       count = 
0;
!                                                               }
!                                                               else
!                                                               {
!                                                                       count = 
0;
!                                                               }
!                                                               if(ch == '\n')
                                                                {
!                                                                       
++lineNumber;
!                                                                       
linePosition = 0;
                                                                }
                                                        }
!                                                       if(ch != '>')
                                                        {
!                                                               
UngetAndThrow(ch);
                                                        }
  
!                                                       // Create a comment 
node and return.
!                                                       ClearNodeInfo();
!                                                       nodeType = 
XmlNodeType.Comment;
!                                                       value = 
builder.ToString();
!                                                       return true;
                                                }
!                                               else if(ch == '[')
                                                {
!                                                       // TODO: CDATA nodes.
                                                }
!                                               else if(ch == 'D')
                                                {
!                                                       // TODO: document type 
nodes.
                                                }
!                                               else
                                                {
!                                                       UngetAndThrow(ch);
                                                }
!                                       }
!                                       else if(ch == '?')
!                                       {
!                                               // Processing instruction.
!                                               // TODO
!                                       }
!                                       else 
if(XmlConvert.IsNameStart((char)ch, true))
!                                       {
!                                               // Start element tag.
!                                               // TODO
!                                       }
!                                       else
!                                       {
!                                               UngetAndThrow(ch);
!                                       }
                                }
!                               else
                                {
!                                       // Text and entity references.
!                                       // TODO
                                }
  
                                return false;
                        }
  
        // Read the next attribute value in the input stream.
-       [TODO]
        public override bool ReadAttributeValue()
                        {
!                               // TODO
!                               return false;
                        }
  
--- 611,885 ----
                                                attributeIndex = -1;
                                                isEmpty = false;
!                                               --depth;        
!                                               break;
!                                       case '?':
!                                               // TODO: Processing Instructions
!                                               if(structFlag != true)
!                                               {
!                                                       throw new XmlException
!                                                               
(S._("Xml_Malformed"));
!                                               }
! 
!                                               ch = ReadChar();
!                                               AnalyzeChar(ch, true);
!                                               break;
!                                       case '!':
!                                               // Check for correct structure 
!                                               if(structFlag != true)
!                                               {
!                                                       throw new XmlException
!                                                               
(S._("Xml_Malformed"));
!                                               }
! 
! 
                                                // Comment, CDATA, or document 
type information.
                                                ch = ReadChar();
!                                               AnalyzeChar(ch, true);
!                                               break;
!                                       case '-':
!                                               // Parse the "<!--" comment 
start sequence.
!                                               if(structFlag != true)
                                                {
!                                                       throw new XmlException
!                                                               
(S._("Xml_Malformed"));
!                                               }
  
!                                               ch = ReadChar();
!                                               if((char)ch != '-')
!                                               {
!                                                       UngetAndThrow(ch);
!                                               }
! 
!                                               // Search for the "-->" comment 
end sequence.
!                                               int count = 0;
!                                               while((ch = ReadChar()) != -1)
!                                               {
!                                                       
builder.Append((char)ch);
!                                               
!                                                       if((char)ch == '-')
                                                        {
                                                                        ++count;
!                                                       }
!                                                       else if((char)ch == '>')
!                                                       {
!                                                               if(count >= 2)
                                                                {
!                                                                       
builder.Remove(builder.Length - 3, 3);
!                                                                       break;
                                                                }
+                                                               count = 0;
                                                        }
!                                                       else
                                                        {
!                                                               count = 0;
                                                        }
+                                                       if((char)ch == '\n')
+                                                       {
+                                                               ++lineNumber;
+                                                               linePosition = 
0;
+                                                       }
+                                               }
+                                               if((char)ch != '>')
+                                               {
+                                                       UngetAndThrow(ch);
+                                               }
  
!                                               // Create a comment node and 
return.
!                                               ClearNodeInfo();
!                                               nodeType = XmlNodeType.Comment;
!                                               value = builder.ToString();
!                                               break;
!                                               
!                                       case '[':
!                                               if(structFlag != true)
!                                               {
!                                                       throw new XmlException
!                                                               
(S._("Xml_Malformed"));
                                                }
! 
!                                               // TODO: CDATA node
!                                               break;
!                                                       
!                                       case 'D':
!                                               if(structFlag != true)
                                                {
!                                                       throw new XmlException
!                                                               
(S._("Xml_Malformed"));
                                                }
!                                               
!                                               // document type nodes
!                                               // clean the buffer
!                                               builder = new StringBuilder();
!                                               builder.Append((char)ch);
!                                               while ((ch = ReadChar()) != -1)
                                                {
!                                                       
builder.Append((char)ch);
!                                                       
if(Char.IsWhiteSpace((char)reader.Peek()))
!                                                       {
!                                                               nodeType = 
XmlNodeType.DocumentType;
!                                                               name = 
builder.ToString();
!                                                               value = 
ReadIdentifier(-1);
!                                                               
!                                                               break;
!                                                       }
                                                }
!                                               break;
!                                       case '=':
!                                               // TODO: save attribute name
!                                               ClearNodeInfo();
!                                               name = builder.ToString();
!                                               SetName(name);
!                                               nodeType = 
XmlNodeType.Attribute;
!                                               // reset buffer
!                                               builder = new StringBuilder();
!                                               break;
!                                       case '"':
!                                               if(nodeType != 
XmlNodeType.Attribute)
                                                {
!                                                       throw new XmlException
!                                                               
(S._("Xml_WrongNode"));
                                                }
!                                               // Get Text value of an 
Attribute       
!                                               while((ch = ReadChar()) != -1)
!                                               {
!                                                       if((char)ch == '"')
!                                                       {
!                                                               value = 
builder.ToString();
!                                                               nodeType = 
XmlNodeType.Text;
! 
!                                                               // go to next 
char
!                                                               SkipWhite();
!                                                               
!                                                               // reset buffer
!                                                               builder = new 
StringBuilder();
!                                                               
!                                                               
if((char)reader.Peek() == '/')
!                                                               {
!                                                                       
ReadChar();
!                                                                       
SkipWhite();
!                                                                       
Expect('>');
!                                                               }
!                                                               else if 
((char)reader.Peek() == '>')
!                                                               {
!                                                                       
ReadChar();
!                                                               }
!                                                               
!                                                               break;
!                                                       }
!                                                       
!                                                       
builder.Append((char)ch);
!                                               }
!                                               break;
!                                       default:
!                                               // save any text
!                                               builder.Append((char)ch);
!                                               // if '<'
!                                               if(structFlag == true)
!                                               {
!                                                       // move back one space
!                                                       ClearNodeInfo();
!                                                       name = 
ReadIdentifier(ch);
!                                                       // checking for 
termination '/'
!                                                       SetName(name);
!                                                       // reset buffer
!                                                       builder = new 
StringBuilder();
!                                                       break;
!                                               }
!                                               
!                                               nodeType = XmlNodeType.Text;
!                                               ch = ReadChar();
!                                               AnalyzeChar(ch, false);
!                                               break;
!                                       
!                               }// end switch(ch)
!                       }// end AnalyzeChar
!               
! 
!       // Read the next node in the input stream.
!       public override bool Read()
!                       {
!                               int ch;
!                               builder = new StringBuilder();
! 
!                               // Validate the current state of the stream.
!                               if(readState == ReadState.EndOfFile)
!                               {
!                                       return false;
                                }
!                               else if(reader == null)
                                {
!                                       throw new 
XmlException(S._("Xml_ReaderClosed"));
!                               }
!                               else if(readState == ReadState.Error)
!                               {
!                                       throw new 
XmlException(S._("Xml_ReaderError"));
                                }
+                               
+                               // Skip white space in the input stream.  TODO: 
collect
+                               // up significant white space.
+                               SkipWhite();
+ 
+                               ch = ReadChar();
  
+                               if(ch == -1)
+                               {
+                                       // We've reached the end of the stream. 
 Throw
+                                       // an error if we haven't closed all 
elements.
+                                       if(linePosition > 1)
+                                       {
+                                               --linePosition;
+                                       }
+                                       readState = ReadState.EndOfFile;
+                                       ClearNodeInfo();
+                                       return false;
+                               }
+                               
+                               readState = ReadState.Interactive;      
+                               // Determine what to do based on the next 
character.
+                               
+                       
+                               
+                               switch (nodeType)
+                               {
+                                       case XmlNodeType.Attribute:
+                                               // Set structFlag to true so 
quoteChar will
+                                               // know it is the first quote
+                                               AnalyzeChar(ch,true);
+                                               return true;
+                                               break;
+                                       default:
+                                               // Handling, set flag to true 
if first char is <
+                                               if ((char)ch == '<')
+                                               {
+                                                       AnalyzeChar(ch, true);
+                                               }
+                                               else 
+                                               {
+                                                       AnalyzeChar(ch, false);
+                                               }
+                                               return true;
+                                               break;
+                               }
+                               
                                return false;
                        }
  
        // Read the next attribute value in the input stream.
        public override bool ReadAttributeValue()
                        {
!                               
!                               if(readState !=  ReadState.Interactive)
!                               {
!                                       throw new XmlException
!                                               (S._("Xml_WrongReadState"));
!                               }
!                               
!                               
!                               
!                               if(nodeType != XmlNodeType.Attribute)
!                                       return false;           
! 
!                               Read();
!                               return true;    
                        }
  
***************
*** 665,681 ****
  
        // Read character data from the current element.
!       [TODO]
!       public int ReadChars(byte[] array, int index, int count)
                        {
!                               // TODO
                                return 0;
                        }
  
        // Read the contents of the current node, including all markup.
-       [TODO]
        public override String ReadInnerXml()
                        {
!                               // TODO
!                               return null;
                        }
  
--- 901,986 ----
  
        // Read character data from the current element.
!       public int ReadChars(char[] buffer, int index, int count)
                        {
!                               if(count > buffer.Length - index)
!                               {
!                                       throw new ArgumentException
!                                               (S._("ArgumentExceedsLength"), 
"count");
!                               }
!                               else if (buffer == null)
!                               {
!                                       throw new ArgumentNullException
!                                               (S._("ArgumentIsNull"), 
"buffer");
!                               }
!                               else if ( index < 0 || count < 0 )
!                               {
!                                       throw new ArgumentOutOfRangeException
!                                               (S._("ArgumentOutOfRange"));
!                               }
!                               else if (nodeType != XmlNodeType.Text && 
nodeType != XmlNodeType.Element)
!                               {
!                                       throw new XmlException
!                                               (S._("Xml_WrongNodeType"));
!                               }
!                               
!                               int length;
!                               String output;
!                               if(nodeType != XmlNodeType.Text)
!                               {
!                                       // if we are not at a text node, move 
to current element's content
!                                       
!                                       MoveToContent();
!                               }
!                               
!                               
!                               Read();
! 
!                               length = value.IndexOf("<");
! 
!                               // go back to '<' position
!                               linePosition -= value.Length - length;
! 
!                               output = value.Substring(0, length);
!                               
!                               // read text now        
!                               if( output.Length < count)
!                               {
!                                       Array.Copy(output.ToCharArray(0, 
output.Length), 0, buffer, index, output.Length);
!                               }
!                               else
!                               {
!                                       Array.Copy(output.ToCharArray(0, 
count), 0, buffer, index, count);
!                               }
!                       
                                return 0;
                        }
  
        // Read the contents of the current node, including all markup.
        public override String ReadInnerXml()
                        {
!                               if(nodeType != XmlNodeType.Element && nodeType 
!= XmlNodeType.Attribute)
!                               {
!                                       throw new XmlException
!                                               (S._("Xml_WrongNodeType"));
!                               }
!                               
!                               int ch;
!                               StringBuilder builder = new StringBuilder();
!                               if(nodeType == XmlNodeType.Element)
!                               {
!                                       MoveToContent();        
!                                       Read();
!                                       return value;
!                               }
!                               else if(nodeType == XmlNodeType.Attribute)
!                               {
!                                       if(ReadAttributeValue() == true)
!                                       {
!                                               return value;
!                                       }
!                               }
!                       
!                               return String.Empty;
!                               
                        }
  
***************
*** 689,704 ****
  
        // Read the contents of an element or text node as a string.
-       [TODO]
        public override String ReadString()
                        {
!                               // TODO
!                               return null;
                        }
  
        // Reset to the initial state.
-       [TODO]
        public void ResetState()
                        {
!                               // TODO
                        }
  
--- 994,1012 ----
  
        // Read the contents of an element or text node as a string.
        public override String ReadString()
                        {
!                               return null;    
                        }
  
        // Reset to the initial state.
        public void ResetState()
                        {
!                               if(contextSupport != false)
!                               {
!                                       throw new InvalidOperationException
!                                               (S._("Xml_ContextNotNull"));
!                               }
!                               
!                               readState = ReadState.Initial;
                        }
  





reply via email to

[Prev in Thread] Current Thread [Next in Thread]