Permalink
Browse files

[Xml] Several fixes for .to_xml() of ELEMENT and ATTLIST tags

  • Loading branch information...
1 parent c60a711 commit fc88b180b44fd4e6c3aa32e6458e60597cd6781d @Whiteknight committed Apr 28, 2012
Showing with 42 additions and 13 deletions.
  1. +16 −3 src/unstable/xml/Document.winxed
  2. +26 −10 src/unstable/xml/Tag.winxed
@@ -45,7 +45,13 @@ class Rosella.Xml.Document
function to_xml()
{
- return self.get_document_root().to_xml();
+ var sb = new 'StringBuilder';
+ if (self.xml_header != null)
+ self.xml_header.to_xml_sb(sb, 0);
+ if (self.dtd_header != null)
+ self.dtd_header.to_xml_sb(sb, 0);
+ self.get_document_root().to_xml_sb(sb, 0);
+ return sb;
}
function write_to_file(string filename)
@@ -79,10 +85,17 @@ class Rosella.Xml.DtdDocument : Rosella.Xml.Document
function DtdDocument() { }
- function to_xml(var sb = new 'StringBuilder')
+ function to_xml()
+ {
+ var sb = new 'StringBuilder';
+ self.to_xml_sb(sb, 0);
+ return string(sb);
+ }
+
+ function to_xml_sb(var sb, int indent)
{
for (string elem in self.typedefs)
- elem.to_xml_sb(sb, 1);
+ self.typedefs[elem].to_xml_sb(sb, indent);
}
function validate_xml(var xmldoc)
@@ -132,7 +132,7 @@ class Rosella.Xml.Tag.XmlHeader : Rosella.Xml.Tag
function to_xml_sb(var sb, int indent)
{
push(sb, "<?xml ");
- self.__to_xml_sb_attrs(sb);
+ self.__to_xml_sb_attrs(sb, indent);
push(sb, "?>");
}
@@ -174,7 +174,7 @@ class Rosella.Xml.Tag.DtdHeader : Rosella.Xml.Tag
if (self.dtd_document != null)
return self.dtd_document;
string scope = self.scope;
- string dtd_document;
+ var dtd_document;
// TODO: If we have a SYSTEM or PUBLIC DTD, the <?xml ?> header should have
// a standalone="no" attribute
switch (scope) {
@@ -200,6 +200,8 @@ class Rosella.Xml.Tag.DtdHeader : Rosella.Xml.Tag
function to_xml_sb(var sb, int indent)
{
+ string indent_str = indent_level(indent);
+ push(sb, indent_str);
push(sb, "<!DOCTYPE ");
push(sb, self.doctype);
push(sb, " ");
@@ -221,9 +223,11 @@ class Rosella.Xml.Tag.DtdHeader : Rosella.Xml.Tag
}
if (self.dtd_document != null) {
push(sb, " [");
- self.dtd_document.to_xml(sb);
+ self.dtd_document.to_xml_sb(sb, indent + 1);
+ push(sb, indent_str);
push(sb, "]");
- }
+ } else
+ push(sb, indent_str);
push(sb, ">");
}
@@ -288,13 +292,22 @@ class Rosella.Xml.Tag.DtdElement
push(sb, indent_str);
push(sb, "<!ELEMENT ");
push(sb, self.name);
- // TODO: The rest of it
- push(sb, ">\n");
- for (var attr in self.attributes)
- attr.to_xml_sb(sb, indent);
+ push(sb, " (");
+ string separator = "";
+ for (string child in self.children) {
+ push(sb, separator);
+ push(sb, child);
+ push(sb, self.children[child]);
+ separator = ",";
+ }
+ push(sb, ")>");
+ for (string attr in self.attributes)
+ self.attributes[attr].to_xml_sb(sb, indent);
}
}
+// TODO: !ATTLIST actually allows a list of attributes in the same tag. We need
+// to cover that case.
class Rosella.Xml.Tag.DtdAttlist
{
var name;
@@ -345,8 +358,12 @@ class Rosella.Xml.Tag.DtdAttlist
push(sb, self.elemname);
push(sb, " ");
push(sb, self.name);
+ push(sb, " ");
+ push(sb, self.type);
+ push(sb, " #");
+ push(sb, self.default_rule);
// TODO: The rest of it
- push(sb, ">\n");
+ push(sb, ">");
}
}
@@ -381,5 +398,4 @@ class Rosella.Xml.Tag.Comment
class Rosella.Xml.Tag.DocumentRoot : Rosella.Xml.Tag
{
function DocumentRoot() { self.children = []; }
-
}

0 comments on commit fc88b18

Please sign in to comment.