private void AddHtml(XmlNode context, DekiScriptOutputBuffer buffer, ref int index, bool safe) { while (true) { object current = buffer[index]; if (current is DekiScriptOutputBuffer.XmlStart) { DekiScriptOutputBuffer.XmlStart start = (DekiScriptOutputBuffer.XmlStart)current; switch (start.Name) { case "head": if (safe) { SkipNode(buffer, ref index); } else { AddHead(buffer, ref index); } break; case "body": AddBody(context ?? _body, buffer, ref index, safe); break; case "tail": if (safe) { SkipNode(buffer, ref index); } else { AddTail(buffer, ref index); } break; default: // unexpected node; ignore it SkipNode(buffer, ref index); break; } } else if (current is DekiScriptOutputBuffer.XmlEnd) { // we're done break; } else { // unexpected node; ignore it } ++index; } }
private void ConvertStateToHtml(DekiScriptOutputBuffer.XmlStart start) { if (_state != State.HTML) { _bodies = new Dictionary <string, XmlNode>(); // check if we're upconverting from the XML state XmlNode xml = null; if (_state == State.XML) { // preserve the XML element xml = _document.FirstChild; _document.RemoveChild(xml); } else { _document = new XmlDocument(XDoc.XmlNameTable); } // initialize the HTML fields _state = State.HTML; if (start != null) { _html = _document.CreateElement(start.Name); if (start.Attributes != null) { foreach (var attribute in start.Attributes) { // TODO (steveb): add support for namespaces var attr = _document.CreateAttribute(attribute.Item2); attr.Value = attribute.Item3; _html.Attributes.Append(attr); } } } else { _html = _document.CreateElement("html"); } _body = _document.CreateElement("body"); _document.AppendChild(_html); _html.AppendChild(_body); // append the preserved XML element if (xml != null) { _body.AppendChild(xml); } } }