1 // -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
3 // System.Xml.XmlDocument
6 // Daniel Weber (daniel-weber@austin.rr.com)
8 // (C) 2001 Daniel Weber
16 public delegate void XmlNodeChangedEventHandler (XmlNodeChangedEventArgs args);
19 /// Abstract class XmlNodeList.
21 public class XmlDocument : XmlNode
23 // Private data members
24 XmlResolver _resolver = null;
27 //===========================================================================
28 public event XmlNodeChangedEventHandler NodeChanged;
30 public event XmlNodeChangedEventHandler NodeChanging;
32 public event XmlNodeChangedEventHandler NodeInserted;
34 public event XmlNodeChangedEventHandler NodeInserting;
36 public event XmlNodeChangedEventHandler NodeRemoved;
38 public event XmlNodeChangedEventHandler NodeRemoving;
43 /// Get the base URI for this document (the location from where the document was loaded)
45 /// <example>If a document was loaded with doc.Load("c:\tmp\mydoc.xml"),
46 /// then BaseURI would hold "c:\tmp\mydoc.xml"</example>
47 public override string BaseURI
51 // TODO - implement XmlDocument.BaseURI {get;}
52 throw new NotImplementedException("BaseURI.get not implemented");
57 /// Get the root element for the document. If no root exists, null is returned.
59 public XmlElement DocumentElement
63 XmlNode node = FirstChild;
65 while (node != null) {
66 if (node is XmlElement)
68 node = node.NextSibling;
71 return node != null ? node as XmlElement : null;
76 /// Gets the node containing the DOCTYPE declaration.
78 public virtual XmlDocumentType DocumentType
82 // TODO - implement XmlDocument.DocumentType
83 throw new NotImplementedException("XmlDocument.DocumentType not implemented");
89 /// Get the XmlImplemenation for the current document.
91 public XmlImplementation Implementation
95 // TODO - implement XmlDocument.Implementation
96 throw new NotImplementedException("Implementation not implemented");
102 /// Get/Set the markup representing the children of the document.
104 public override string InnerXml
108 // TODO - implement XmlDocument.InnerXml {get;}
109 throw new NotImplementedException("InnerXml get not implemented");
113 // TODO - implement XmlDocument.InnerXml {set;}
114 throw new NotImplementedException("InnerXml set not implemented");
119 /// Get a value indicating if the document is read-only.
121 public override bool IsReadOnly
130 /// Get the local name of the node. For documents, returns "#document"
132 public override string LocalName {
140 /// Get the qualified name of the node. For documents, returns "#document"
142 public override string Name
150 public XmlNameTable NameTable
154 // TODO - implement XmlDocument.NameTable {get;}
155 throw new NotImplementedException("NameTable get not implemented");
160 public override XmlNodeType NodeType
164 return XmlNodeType.Document;
169 /// Returns OwnerDocument. For an XmlDocument, this property is always null.
171 public override XmlDocument OwnerDocument
179 public bool PreserveWhitespace
183 // TODO - implement XmlDocument.PreserveWhitespace {get;}
184 throw new NotImplementedException("PreserveWhitespace get not implemented");
188 // TODO - implement XmlDocument.PreserveWhitespace {set;}
189 throw new NotImplementedException("PreserveWhitespace set not implemented");
193 public XmlResolver XmlResolver
197 // TODO - Finish/test XmlDocument.XmlResolver {set;}
203 //===========================================================================
204 public override XmlNode CloneNode(bool deep)
206 // TODO - implement XmlDocument.CloneNode(bool)
207 throw new NotImplementedException("CloneNode(bool) not implemented");
210 public XmlAttribute CreateAttribute(string name)
212 // TODO - implement XmlDocument.CreateAttribute(string name)
213 throw new NotImplementedException("CreateAttribute(string name) not implemented");
216 public XmlAttribute CreateAttribute(string qualifiedName,string namespaceURI)
218 // TODO - implement XmlDocument.CreateAttribute(string, string)
219 throw new NotImplementedException("CreateAttribute(string, string) not implemented");
222 public virtual XmlAttribute CreateAttribute(
228 // TODO - implement XmlDocument.CreateAttribute(prefix, localName, namespaceURI)
229 throw new NotImplementedException("CreateAttribute(prefix, localName, namespaceURI) not implemented");
232 public virtual XmlCDataSection CreateCDataSection(string data)
234 // TODO - implement XmlDocument.CreateCDataSection(string data)
235 throw new NotImplementedException("CreateCDataSection(string data) not implemented");
239 public virtual XmlComment CreateComment(string data)
241 // TODO - implement XmlDocument.CreateComment(string data)
242 throw new NotImplementedException("CreateComment(string data) not implemented");
245 public virtual XmlDocumentFragment CreateDocumentFragment()
247 // TODO - implement XmlDocument.CreateDocumentFragment
248 throw new NotImplementedException("CreateDocumentFragment not implemented");
251 public virtual XmlDocumentType CreateDocumentType(
255 string internalSubset
258 // TODO - implement XmlDocument.CreateDocumentType
259 throw new NotImplementedException("CreateDocumentType not implemented");
262 public XmlElement CreateElement(string name)
264 // TODO - implement XmlDocument.CreateElement(string name)
265 throw new NotImplementedException("CreateElement(string name) not implemented");
268 public XmlElement CreateElement(
269 string qualifiedName,
273 // TODO - implement XmlDocument.CreateElement(string qualifiedName, string namespaceURI)
274 throw new NotImplementedException("CreateElement(string qualifiedName, string namespaceURI) not implemented");
277 public virtual XmlElement CreateElement(
283 return new XmlElement(prefix, localName, namespaceURI, this);
287 public virtual XmlEntityReference CreateEntityReference(string name)
289 // TODO - implement XmlDocument.CreateEntityReference
290 throw new NotImplementedException("XmlDocument.CreateEntityReference not implemented.");
293 public virtual XmlNode CreateNode(
294 string nodeTypeString,
299 // TODO - implement XmlDocument.CreateNode(string, string, string)
300 throw new NotImplementedException("XmlDocument.CreateNode not implemented.");
303 public virtual XmlNode CreateNode(
309 // TODO - implement XmlDocument.CreateNode(XmlNodeType, string, string)
310 throw new NotImplementedException("XmlDocument.CreateNode not implemented.");
313 public virtual XmlNode CreateNode(
320 // TODO - implement XmlDocument.CreateNode(XmlNodeType, string, string, string)
321 throw new NotImplementedException("XmlDocument.CreateNode not implemented.");
324 public virtual XmlProcessingInstruction CreateProcessingInstruction(
329 // TODO - implement XmlDocument.CreateProcessingInstruction
330 throw new NotImplementedException("XmlDocument.CreateProcessingInstruction not implemented.");
333 public virtual XmlSignificantWhitespace CreateSignificantWhitespace(string text )
335 // TODO - implement XmlDocument.CreateSignificantWhitespace
336 throw new NotImplementedException("XmlDocument.CreateSignificantWhitespace not implemented.");
339 public virtual XmlText CreateTextNode(string text)
341 // TODO - implement XmlDocument.CreateTextNode
342 throw new NotImplementedException("XmlDocument.CreateTextNode not implemented.");
345 public virtual XmlWhitespace CreateWhitespace(string text)
347 // TODO - implement XmlDocument.CreateWhitespace
348 throw new NotImplementedException("XmlDocument.CreateWhitespace not implemented.");
351 public virtual XmlDeclaration CreateXmlDeclaration(
357 // TODO - implement XmlDocument.CreateXmlDeclaration
358 throw new NotImplementedException("XmlDocument.CreateXmlDeclaration not implemented.");
361 public virtual XmlElement GetElementById(string elementId)
363 // TODO - implement XmlDocument.GetElementById
364 throw new NotImplementedException("XmlDocument.GetElementById not implemented.");
367 public virtual XmlNodeList GetElementsByTagName(string name)
369 // TODO - implement XmlDocument.GetElementsByTagName(name)
370 throw new NotImplementedException("XmlDocument.GetElementsByTagName not implemented.");
373 public virtual XmlNodeList GetElementsByTagName(
378 // TODO - implement XmlDocument.GetElementsByTagName(localName, namespaceURI)
379 throw new NotImplementedException("XmlDocument.GetElementsByTagName not implemented.");
382 public virtual XmlNode ImportNode(
387 // TODO - implement XmlDocument.ImportNode
388 throw new NotImplementedException("XmlDocument.ImportNode not implemented.");
391 public virtual void Load(Stream inStream)
393 // TODO - implement XmlDocument.Load(Stream)
394 throw new NotImplementedException("XmlDocument.Load(Stream) not implemented.");
397 public virtual void Load(string filename)
399 // TODO - implement XmlDocument.Load(string)
400 throw new NotImplementedException("XmlDocument.Load(string) not implemented.");
403 public virtual void Load(TextReader txtReader)
405 // TODO - implement XmlDocument.Load(TextReader)
406 throw new NotImplementedException("XmlDocument.Load(TextReader) not implemented.");
409 public virtual void Load(XmlReader reader)
411 // TODO - implement XmlDocument.Load(XmlReader)
412 throw new NotImplementedException("XmlDocument.Load(XmlReader) not implemented.");
415 public virtual void LoadXml(string xml)
417 XmlReader xmlReader = new XmlTextReader(new StringReader(xml));
418 XmlNode currentNode = this;
421 // Reset our document
422 // For now this just means removing all our children but later this
423 // may turn out o need to call a private method that resets other things
424 // like properties we have, etc.
427 // Wrapping in try/catch for now until XmlTextReader starts throwing XmlException
430 while (xmlReader.Read())
432 switch(xmlReader.NodeType)
434 case XmlNodeType.Element:
435 newNode = CreateElement(xmlReader.Name, xmlReader.LocalName, xmlReader.NamespaceURI);
436 currentNode.AppendChild(newNode);
437 if (!xmlReader.IsEmptyElement)
439 currentNode = newNode;
443 case XmlNodeType.Text:
444 newNode = CreateTextNode(xmlReader.Value);
445 currentNode.AppendChild(newNode);
448 case XmlNodeType.EndElement:
449 currentNode = currentNode.ParentNode;
456 throw new XmlException(e.Message, e);
460 public virtual void Save(Stream outStream)
462 // TODO - implement XmlDocument.Save(Stream)
463 throw new NotImplementedException("XmlDocument.Save(Stream) not implemented.");
466 public virtual void Save(string filename)
468 // TODO - implement XmlDocument.Save(string)
469 throw new NotImplementedException("XmlDocument.Save(string) not implemented.");
472 public virtual void Save(TextWriter writer)
474 // TODO - implement XmlDocument.Save(TextWriter)
475 throw new NotImplementedException("XmlDocument.Save(TextWriter) not implemented.");
478 public virtual void Save(XmlWriter writer)
480 // TODO - implement XmlDocument.Save(XmlWriter)
481 throw new NotImplementedException("XmlDocument.Save(XmlWriter) not implemented.");
484 public override void WriteContentTo(XmlWriter w)
486 // TODO - implement XmlDocument.WriteContentTo
487 throw new NotImplementedException("XmlDocument.WriteContentTo not implemented.");
490 public override void WriteTo(XmlWriter w)
492 // TODO - implement XmlDocument.WriteTo
493 throw new NotImplementedException("XmlDocument.WriteTo not implemented.");
497 // Internal functions
498 //===========================================================================
499 internal void onNodeChanging(XmlNode node, XmlNode Parent)
501 if (NodeInserting != null)
502 NodeChanging( new XmlNodeChangedEventArgs(XmlNodeChangedAction.Change,
503 node, Parent, Parent));
506 internal void onNodeChanged(XmlNode node, XmlNode Parent)
508 if (NodeChanged != null)
509 NodeInserted( new XmlNodeChangedEventArgs(XmlNodeChangedAction.Change,
510 node, Parent, Parent));
513 internal void onNodeInserting(XmlNode node, XmlNode newParent)
515 if (NodeInserting != null)
516 NodeInserting( new XmlNodeChangedEventArgs(XmlNodeChangedAction.Insert,
517 node, null, newParent));
520 internal void onNodeInserted(XmlNode node, XmlNode newParent)
522 if (NodeInserted != null)
523 NodeInserted( new XmlNodeChangedEventArgs(XmlNodeChangedAction.Insert,
524 node, null, newParent));
527 internal void onNodeRemoving(XmlNode node, XmlNode oldParent)
529 if (NodeRemoving != null)
530 NodeRemoving(new XmlNodeChangedEventArgs(XmlNodeChangedAction.Remove,
531 node, oldParent, null));
534 internal void onNodeRemoved(XmlNode node, XmlNode oldParent)
536 if (NodeRemoved != null)
537 NodeRemoved(new XmlNodeChangedEventArgs(XmlNodeChangedAction.Remove,
538 node, oldParent, null));
543 //===========================================================================
544 public XmlDocument() : base(null)
546 FOwnerDocument = this;