[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/System.Xml XmlDocument.cs,1.14,1.15 X
From: |
Adam Ballai <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/System.Xml XmlDocument.cs,1.14,1.15 XmlParserContext.cs,1.5,1.6 XmlStreamReader.cs,1.1,1.2 XmlTextReader.cs,1.38,1.39 |
Date: |
Sat, 05 Apr 2003 01:17:07 -0500 |
Update of /cvsroot/dotgnu-pnet/pnetlib/System.Xml
In directory subversions:/tmp/cvs-serv31288/System.Xml
Modified Files:
XmlDocument.cs XmlParserContext.cs XmlStreamReader.cs
XmlTextReader.cs
Log Message:
Add DTD support to System.Xml
Index: XmlDocument.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Xml/XmlDocument.cs,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -r1.14 -r1.15
*** XmlDocument.cs 1 Apr 2003 00:36:50 -0000 1.14
--- XmlDocument.cs 5 Apr 2003 06:17:05 -0000 1.15
***************
*** 690,698 ****
{
XmlNode parent = this;
! XmlNode current = null;
parent = ReadNode(reader);
! if(parent != null)
{
--- 690,698 ----
{
XmlNode parent = this;
! XmlNode docType = null;
parent = ReadNode(reader);
! if(parent != null && reader.NodeType !=
XmlNodeType.DocumentType)
{
***************
*** 700,703 ****
--- 700,712 ----
return true;
}
+ else if(parent != null && reader.NodeType ==
XmlNodeType.DocumentType)
+ {
+ docType = parent;
+ parent = ReadNode(reader);
+ this.AppendChild(parent);
+ // add DocumentType
+ this.AppendChild(docType);
+ return true;
+ }
else
{
***************
*** 793,797 ****
break;
case XmlNodeType.DocumentType:
! // TODO: DocumentType
break;
case
XmlNodeType.SignificantWhitespace:
--- 802,818 ----
break;
case XmlNodeType.DocumentType:
! if(currentNode != null)
! {
! throw new
XmlException(
!
S._("XmlException_InvalidPosition"));
! }
! currentNode =
CreateDocumentType(
!
reader.Name,
!
reader.GetAttribute("PUBLIC"),
!
reader.GetAttribute("SYSTEM"),
!
reader.Value);
!
!
!
break;
case
XmlNodeType.SignificantWhitespace:
***************
*** 804,808 ****
break;
}
-
}
--- 825,828 ----
Index: XmlParserContext.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Xml/XmlParserContext.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** XmlParserContext.cs 27 Jul 2002 04:47:40 -0000 1.5
--- XmlParserContext.cs 5 Apr 2003 06:17:05 -0000 1.6
***************
*** 25,28 ****
--- 25,29 ----
using System;
using System.Text;
+ using System.Collections.Specialized;
public class XmlParserContext
***************
*** 34,37 ****
--- 35,41 ----
private String internalsubset;
private XmlNameTable nametable;
+ #if !ECMA_COMPAT
+ private NameValueCollection namecollection;
+ #endif
private XmlNamespaceManager namespacemanager;
private String publicid;
***************
*** 69,77 ****
--- 73,88 ----
throw new
XmlException(S._("Xml_WrongNameTable"));
}
+
if (nt == null)
+ {
+ if(nsMgr == null)
+ nsMgr = new
XmlNamespaceManager(new NameTable());
nametable = nsMgr.NameTable;
+ }
else
+ {
nametable = nt;
+ }
namespacemanager = nsMgr;
***************
*** 109,113 ****
xmlspace = xmlSpace;
! encoding = enc;
}
--- 120,136 ----
xmlspace = xmlSpace;
! encoding = enc;
!
! #if !ECMA_COMPAT
! namecollection = new NameValueCollection();
!
! if (internalSubset != null)
! {
! XmlTextReader reader = new
XmlTextReader(internalSubset, XmlNodeType.Document, null);
! while( reader.ReadDeclaration() );
!
! namecollection =
reader.ParserContext.NameCollection;
! }
! #endif
}
***************
*** 250,253 ****
--- 273,289 ----
}
}
+ #if !ECMA_COMPAT
+ internal NameValueCollection NameCollection
+ {
+ get
+ {
+ return namecollection;
+ }
+ set
+ {
+ namecollection = value;
+ }
+ }
+ #endif
}; // class XmlParserContext
Index: XmlStreamReader.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Xml/XmlStreamReader.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** XmlStreamReader.cs 10 Mar 2003 00:10:00 -0000 1.1
--- XmlStreamReader.cs 5 Apr 2003 06:17:05 -0000 1.2
***************
*** 52,59 ****
--- 52,76 ----
private int outBufferLen;
private bool sawEOF;
+ internal TextReader TxtReader;
+ internal bool canseek;
// Constructors that are based on a stream.
public XmlStreamReader(Stream stream)
: this(stream, Encoding.UTF8, true, STREAM_BUFSIZ) {}
+
+ internal XmlStreamReader(TextReader txtReader)
+ {
+ this.TxtReader = txtReader;
+ StreamReader strReader = txtReader as
StreamReader;
+ if(strReader != null)
+ {
+ canseek = strReader.BaseStream.CanSeek;
+ }
+ else
+ {
+ canseek = txtReader != null &&
txtReader.Peek() != -1;
+ }
+
+ }
public XmlStreamReader(Stream stream, bool
detectEncodingFromByteOrderMarks)
: this(stream, Encoding.UTF8,
Index: XmlTextReader.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Xml/XmlTextReader.cs,v
retrieving revision 1.38
retrieving revision 1.39
diff -C2 -r1.38 -r1.39
*** XmlTextReader.cs 1 Apr 2003 00:36:50 -0000 1.38
--- XmlTextReader.cs 5 Apr 2003 06:17:05 -0000 1.39
***************
*** 59,66 ****
private int depth;
private bool isEmpty;
! internal bool readAttribute;
! internal bool contextSupport;
! internal StringBuilder builder;
! internal String name;
// Constructors.
protected XmlTextReader()
--- 59,74 ----
private int depth;
private bool isEmpty;
! private bool readAttribute;
! private bool contextSupport;
! private StringBuilder builder;
! private String name;
! private String systemId;
! private String publicId;
! private XmlParserContext parserContext;
! private String docTypeName;
! private String internalSubset;
! private bool isEntity = false;
! private int startEntity = 0;
!
// Constructors.
protected XmlTextReader()
***************
*** 95,98 ****
--- 103,108 ----
localName = String.Empty;
namespaceURI = String.Empty;
+ docTypeName = String.Empty;
+ internalSubset = String.Empty;
value = String.Empty;
attr = new
XmlAttributeToken(nameTable,null,null);
***************
*** 104,107 ****
--- 114,121 ----
name = String.Empty;
readAttribute = false;
+ systemId = String.Empty;
+ publicId = String.Empty;
+ parserContext = new XmlParserContext(nt,
namespaceManager, xmlLang,
+ xmlSpace );
}
public XmlTextReader(Stream input)
***************
*** 199,202 ****
--- 213,217 ----
xmlSpace = context.XmlSpace;
contextSupport = true;
+ parserContext = context;
}
namespaces = false;
***************
*** 221,227 ****
{
baseURI = String.Empty;
! XmlStreamReader sr = new
XmlStreamReader(xmlFragment);
encoding = sr.CurrentEncoding;
! reader = sr;
}
else
--- 236,243 ----
{
baseURI = String.Empty;
! XmlStreamReader sr = new
XmlStreamReader(new StringReader(xmlFragment));
!
encoding = sr.CurrentEncoding;
! reader = sr.TxtReader;
}
else
***************
*** 231,235 ****
xmlSpace = context.XmlSpace;
contextSupport = true;
! XmlStreamReader sr = new
XmlStreamReader(xmlFragment);
if(context.Encoding == null)
{
--- 247,251 ----
xmlSpace = context.XmlSpace;
contextSupport = true;
! XmlStreamReader sr = new
XmlStreamReader(new StringReader(xmlFragment));
if(context.Encoding == null)
{
***************
*** 240,244 ****
encoding = context.Encoding;
}
! reader = sr;
}
--- 256,261 ----
encoding = context.Encoding;
}
! reader = sr.TxtReader;
! parserContext = context;
}
***************
*** 270,273 ****
--- 287,291 ----
encoding = sr.CurrentEncoding;
reader = sr;
+ parserContext.NameTable = nt;
}
***************
*** 279,282 ****
--- 297,302 ----
namespaceURI = String.Empty;
value = String.Empty;
+ systemId = String.Empty;
+ publicId = String.Empty;
attr = new
XmlAttributeToken(nameTable,null,null);
attributes = new XmlAttributeCollection(attr);
***************
*** 477,480 ****
--- 497,502 ----
namespaceURI = String.Empty;
value = String.Empty;
+ systemId = String.Empty;
+ publicId = String.Empty;
attr = new
XmlAttributeToken(nameTable,null,null);
attributes = new XmlAttributeCollection(attr);
***************
*** 554,558 ****
return null;
}
!
// Set the name information from an identifier.
private void SetName(String identifier)
--- 576,588 ----
return null;
}
! #if !ECMA_COMPAT
! private String ParseEntity(String entityref)
! {
! String value =
parserContext.NameCollection.Get(entityref);
! return value;
! }
! #endif
!
!
// Set the name information from an identifier.
private void SetName(String identifier)
***************
*** 573,576 ****
--- 603,714 ----
}
+ internal string ReadTo(char stop)
+ {
+ StringBuilder builder = new StringBuilder();
+ int ch = 0;
+ while((ch = ReadChar()) != -1 && (char)ch !=
stop)
+ {
+ builder.Append((char)ch);
+ }
+ return builder.ToString();
+ }
+
+ #if !ECMA_COMPAT
+ internal void ReadDTDInternalSubset(int ch)
+ {
+ StringBuilder builder = new StringBuilder();
+ SkipWhite ();
+ builder.Append((char)ch);
+ switch((char)ch)
+ {
+ case ']':
+ nodeType = XmlNodeType.None;
+ break;
+ case '%':
+ string peName =
ReadIdentifier(ch);
+ Expect (';');
+ nodeType =
XmlNodeType.EntityReference;
+ break;
+ case '<':
+ ch = ReadChar();
+ builder.Append((char)ch);
+ switch((char)ch)
+ {
+ case '!':
+ ch = ReadChar();
+
builder.Append((char)ch);
+ switch((char)ch)
+ {
+ case
'-':
+
AnalyzeChar(ch, true);
+
break;
+ case
'E':
+
ch = ReadChar();
+
builder.Append((char)ch);
+
switch((char)ch)
+
{
+
case 'N':
+
while((ch = ReadChar()) != -1)
+
{
+
builder.Append((char)ch);
+
if(builder.ToString() == "<!ENTITY")
+
{
+
SkipWhite();
+
String name = ReadTo(' ');
+
String space = ReadTo('\'');
+
String value = ReadTo('\'');
+
builder.Append(name + space + value +
ReadTo('>'));
+
parserContext.InternalSubset =
builder.ToString();
+
parserContext.NameCollection.Add(name, value);
+
return;
+
}
+
}
+
break;
+
case 'L':
+
while((ch = ReadChar()) != -1)
+
{
+
builder.Append((char)ch);
+
if(builder.ToString() == "<!ELEMENT")
+
{
+
ch = ReadChar();
+
if(!Char.IsWhiteSpace((char)ch))
+
throw new XmlException(
+
S._("Xml_BadDTDDeclaration"));
+
+
builder.Append((char)ch);
+
builder.Append(ReadTo('>'));
+
parserContext.InternalSubset =
builder.ToString();
+
return;
+
}
+
}
+
break;
+
default:
+
throw new XmlException(S._("Syntax Error after '<!E' (ELEMENT
or ENTITY must be found)"));
+
}
+
break;
+ case
'A':
+
//Expect ("TTLIST");
+
//ReadAttListDecl ();
+
break;
+ case
'N':
+
//Expect ("OTATION");
+
//ReadNotationDecl ();
+
break;
+ default:
+
throw new XmlException(S._("Syntax Error after '<!' characters."));
+ }
+ break;
+ default:
+ throw new
XmlException(S._("Syntax Error after '<' character."));
+ }
+ break;
+ default:
+ throw new
XmlException(S._("Syntax Error inside doctypedecl markup."));
+ }
+
+ return;
+ }
+ #endif
+
// Skip white space characters.
***************
*** 610,614 ****
internal void AnalyzeChar(int ch, bool structFlag)
{
!
if(ch == -1)
{
--- 748,752 ----
internal void AnalyzeChar(int ch, bool structFlag)
{
!
if(ch == -1)
{
***************
*** 622,626 ****
}
-
switch((char)ch)
{
--- 760,763 ----
***************
*** 822,825 ****
--- 959,1126 ----
(S._("Xml_Malformed"));
}
+ SkipWhite();
+ builder = new
StringBuilder();
+ while((ch =
ReadChar()) != -1)
+ {
+
+
if(Char.IsWhiteSpace((char)ch))
+ {
+
SkipWhite();
+
name = builder.ToString();
+
break;
+ }
+ else
if((char)ch == '>')
+ {
+
name = builder.ToString();
+
return;
+ }
+ else
+ {
+
builder.Append((char)ch);
+ }
+ }
+ SkipWhite();
+ if((char)ch ==
'>')
+ {
+ return;
+ }
+ builder = new
StringBuilder();
+ while((ch =
ReadChar()) != -1)
+ {
+
builder.Append((char)ch);
+
if(Char.IsWhiteSpace((char)reader.Peek()))
+ {
+ #if !ECMA_COMPAT
+
if(builder.ToString() == "SYSTEM")
+
{
+
builder = new StringBuilder();
+
SkipWhite();
+
int qChar = ReadChar();
+
ch = ReadChar();
+
while(ch != qChar && ch != -1)
+
{
+
builder.Append((char)ch);
+
ch = ReadChar();
+
}
+
systemId = builder.ToString();
+
+
break;
+
}
+
else if(builder.ToString() == "PUBLIC")
+
{
+
builder = new StringBuilder();
+
SkipWhite();
+
int qChar = ReadChar();
+
ch = ReadChar();
+
while(ch != qChar && ch != -1)
+
{
+
builder.Append((char)ch);
+
ch = ReadChar();
+
// TODO: Check for non-pubid characters
+
}
+
publicId = builder.ToString();
+
builder = new StringBuilder();
+
SkipWhite();
+
qChar = ReadChar();
+
ch = ReadChar();
+
while(ch != qChar && ch != -1)
+
{
+
builder.Append((char)ch);
+
ch = ReadChar();
+
}
+
systemId = builder.ToString();
+
break;
+
}
+
else if((char)ch == '[')
+
{
+
// seek to ']'
+
SkipWhite();
+
+
while((ch = ReadChar()) != -1)
+
{
+
builder.Append((char)ch);
+
if((char)ch == ']' && (char)reader.Peek() == '>')
+
{
+
internalSubset = builder.ToString();
+
ReadChar();
+
return;
+
}
+
}
+
+
break;
+
}
+
else
+
{
+
name = builder.ToString();
+
SkipWhite();
+
ch = ReadChar();
+
if((char)ch == '[')
+
{
+
// seek to ']'
+
SkipWhite();
+
ch = ReadChar();
+
builder.Append((char)ch);
+
ReadDTDInternalSubset(ch);
+
break;
+
}
+
+
break;
+
}
+ #else
+
if((char)ch == '[')
+
{
+
isEntity = true;
+
}
+
if((char)ch == ']' && (char)reader.Peek() == '>'
+
&& isEntity == true)
+
{
+
internalSubset = builder.ToString();
+
ReadChar();
+
return;
+
}
+ #endif
+
+ }
+ }
+
+ SkipWhite();
+ builder = new
StringBuilder();
+ int level = 0;
+
if((char)reader.Peek() == '[')
+ {
+ // seek
to ']'
+
while((ch = ReadChar()) != -1)
+ {
+
builder.Append((char)ch);
+
if((char)reader.Peek() == ']' && level == 0)
+
{
+
ReadChar();
+
break;
+
}
+
else if((char)reader.Peek() == '[')
+
{
+
// DTDInternalSubset
+
ReadChar();
+
while(reader.Peek() != ']')
+
{
+ #if !ECMA_COMPAT
+
ReadDeclaration();
+ #else
+
builder.Append((char)ch);
+ #endif
+
}
+
}
+
+ }
+
+ }
+ else
if((char)reader.Peek() == '>')
+ {
+
ReadChar();
+ isEmpty
= false;
+ value =
parserContext.InternalSubset;
+ return;
+ }
+
builder = new
StringBuilder();
count++;
***************
*** 874,878 ****
attr.Value =
builder.ToString();
attributes.Append(attr);
! nodeType =
XmlNodeType.Text;
if(prefix ==
"xmlns")
{
--- 1175,1186 ----
attr.Value =
builder.ToString();
attributes.Append(attr);
! if(!isEntity)
! {
!
nodeType = XmlNodeType.Text;
! }
! else
! {
!
nodeType = XmlNodeType.EntityReference;
! }
if(prefix ==
"xmlns")
{
***************
*** 903,908 ****
break;
}
!
!
builder.Append((char)ch);
}
break;
--- 1211,1233 ----
break;
}
! #if !ECMA_COMPAT
! else if((char)ch == '&')
! {
! // found entity
reference
! isEntity = true;
! startEntity =
builder.Length;
! }
! else if((char)ch == ';'
&& isEntity == true)
! {
! String
entityRef = builder.ToString(startEntity, builder.Length - startEntity);
!
builder.Remove(startEntity, builder.Length - startEntity);
! builder.Append(
ParseEntity(entityRef) );
! isEntity =
false;
! }
! #endif
! else
! {
!
builder.Append((char)ch);
! }
}
break;
***************
*** 926,935 ****
else
{
!
! ch = ReadChar();
if((char)ch != '<')
{
! AnalyzeChar(ch,
false);
break;
}
else
--- 1251,1295 ----
else
{
! #if !ECMA_COMPAT
! if((char)ch == '&')
! {
! // found entity
reference
! isEntity = true;
! startEntity =
builder.Length -1;
!
builder.Remove(builder.Length-1, 1);
! }
! #endif
! ch = ReadChar();
if((char)ch != '<')
{
! #if !ECMA_COMPAT
! if((char)ch ==
';' && isEntity == true)
! {
! String
entityRef = builder.ToString(startEntity, builder.Length - startEntity);
!
builder.Remove(startEntity, builder.Length - startEntity);
!
builder.Append(ParseEntity(entityRef));
!
isEntity = false;
!
! ch =
ReadChar();
!
if((char)ch != '<')
! {
!
AnalyzeChar(ch, false);
! }
! else
! {
!
ClearNodeInfo();
!
nodeType = XmlNodeType.Text;
!
ungetch = ch;
!
value = builder.ToString();
! }
! }
! else
! {
!
AnalyzeChar(ch, false);
! }
break;
+ #else
+ AnalyzeChar(ch,
false);
+ #endif
}
else
***************
*** 940,943 ****
--- 1300,1305 ----
value =
builder.ToString();
}
+
+
}
break;
***************
*** 945,950 ****
}// end switch(ch)
}// end AnalyzeChar
!
// Read the next node in the input stream. -- This should mimic mono's
interpretation of Read()
public override bool Read()
--- 1307,1369 ----
}// end switch(ch)
}// end AnalyzeChar
! #if !ECMA_COMPAT
! internal bool ReadDeclaration()
! {
! int ch;
! string tempName;
! 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.
! 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.
!
!
!
! // Handling, set flag to true if first char is <
! if ((char)ch == '<')
! {
! while(ch != -1)
! {
! ReadDTDInternalSubset(ch);
! ch = ReadChar();
! }
! }
! return false;
+
+ }
+ #endif
+
// Read the next node in the input stream. -- This should mimic mono's
interpretation of Read()
public override bool Read()
***************
*** 1302,1307 ****
--- 1721,1728 ----
// Read the contents of an element or text node as a string.
+ [TODO]
public override String ReadString()
{
+ // TODO
return null;
}
***************
*** 1320,1327 ****
// Resolve an entity reference.
- [TODO]
public override void ResolveEntity()
{
! // TODO
}
--- 1741,1748 ----
// Resolve an entity reference.
public override void ResolveEntity()
{
! throw new InvalidOperationException(
! S._("Xml_CannotResolveEntity"));
}
***************
*** 1736,1739 ****
--- 2157,2169 ----
return xmlSpace;
}
+ }
+
+ internal XmlParserContext ParserContext
+ {
+ get
+ {
+ return parserContext;
+ }
+
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/System.Xml XmlDocument.cs,1.14,1.15 XmlParserContext.cs,1.5,1.6 XmlStreamReader.cs,1.1,1.2 XmlTextReader.cs,1.38,1.39,
Adam Ballai <address@hidden> <=