Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[Xml] Start reworking DTD document handling

  • Loading branch information...
commit 0f49d4a5be8b1caa3861afa6148f947abcb01039 1 parent 87e8ec4
@Whiteknight authored
View
19 src/unstable/xml/Document.winxed
@@ -77,16 +77,25 @@ class Rosella.Xml.Document
// be used to feed data into the document.
}
-class Rosella.Xml.DtdDocument
+class Rosella.Xml.DtdDocument : Rosella.Xml.Document
{
- var dtd_header;
+ function DtdDocument() { }
+
+ function to_xml()
+ {
+ // TODO: This
+ return self.dtd_header.to_xml();
+ }
- function DtdDocument()
+ function read_from_file(string filename)
{
+ var f = new Rosella.FileSystem.File(filename);
+ string dtd = f.read_all_text();
+ Rosella.Xml.parse(dtd, self);
}
- function set_dtd_header(var header)
+ function read_from_string(string dtd)
{
- self.dtd_header = header;
+ Rosella.Xml.parse_dtd(dtd, self);
}
}
View
7 src/unstable/xml/Parser.winxed
@@ -175,7 +175,7 @@ namespace Rosella.Xml.Parser
Rosella.Parse.error_unknown_char(c, "!DOCTYPE header", current_position(len, s, b));
}
- function __parse_dtd_standalone(string dtd, var s, var b, int len)
+ function __parse_dtd_standalone(string dtd, var s, var b, int len, var dtd_document)
{
var dtd_header = new Rosella.Xml.Tag.DtdHeader(0, "");
while (have_more_chars(s, b)) {
@@ -188,9 +188,8 @@ namespace Rosella.Xml.Parser
else
Rosella.Parse.error_unknown_char(c, "DTD", current_position(len, s, b));
}
- var dtd_doc = new Rosella.Xml.DtdDocument();
- dtd_doc.set_dtd_header(dtd_header);
- return dtd_doc;
+ dtd_document.set_dtd_header(dtd_header);
+ return dtd_document;
}
function __parse_dtd_inline_tag(string xml, var s, var b, int len, var dtd_header)
View
41 src/unstable/xml/Xml.winxed
@@ -1,5 +1,14 @@
+/* Rosella XML Library
+ This library contains utilities for working with XML, both parsing XML into
+ objects and turning objects into XML. The routines in this namespace are
+ some of the main driver routines for use by client programs.
+*/
namespace Rosella.Xml
{
+ /* Public API
+ */
+
+ // Read XML from a file. Return an Xml.Document object
function read_file(string filename)
{
var document = new Rosella.Xml.Document();
@@ -7,6 +16,7 @@ namespace Rosella.Xml
return document;
}
+ // Read XML from a string. Return an Xml.Document object
function read_string(string xml)
{
var document = new Rosella.Xml.Document();
@@ -14,8 +24,31 @@ namespace Rosella.Xml
return document;
}
+ // Read a standalone DTD declaration from a string
+ function read_dtd_string(string dtd)
+ {
+ var dtd_doc = new Rosella.Xml.DtdDocument();
+ dtd_doc.read_from_string(dtd);
+ return dtd_doc;
+ }
+
+ // Read a standalone DTD declaration from a file
+ function read_dtd_file(string filename)
+ {
+ var dtd_doc = new Rosella.Xml.DtdDocument();
+ dtd_doc.read_from_file(dtd);
+ return dtd_doc;
+ }
+
+ /* Helper Routines
+ */
+
+ // Parse the XML string into the given document. Optionally perform
+ // verification on the generated structure
function parse(string xml, var document, int do_verify = true)
{
+ if (document == null)
+ document = new Rosella.Xml.Document();
:(xml, var s, var b, int len) = Rosella.Parse.setup_parse(xml);
Rosella.Xml.Parser.__parse_xml(xml, s, b, len, document);
if (do_verify)
@@ -23,9 +56,13 @@ namespace Rosella.Xml
return document;
}
- function parse_dtd(string dtd)
+ // Parse the DTD string into the given document.
+ function parse_dtd(string dtd, var document)
{
+ if (document == null)
+ document = new Rosella.Xml.DtdDocument();
:(dtd, var s, var b, int len) = Rosella.Parse.setup_parse(dtd);
- return Rosella.Xml.Parser.__parse_dtd_standalone(dtd, s, b, len);
+ Rosella.Xml.Parser.__parse_dtd_standalone(dtd, s, b, len, document);
+ return document;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.