diff --git a/playlet-lib/src/source/services/XmlObject.bs b/playlet-lib/src/source/services/XmlObject.bs index 98cf84b1..f6acdd33 100644 --- a/playlet-lib/src/source/services/XmlObject.bs +++ b/playlet-lib/src/source/services/XmlObject.bs @@ -69,20 +69,21 @@ class XmlObject for i = 0 to node.children.count() - 1 child = node.children[i] + childIsString = IsString(child) if i = 0 - if not IsString(child) + if not childIsString xmlString += `\n` end if end if - if IsString(child) + if childIsString xmlString += m.XmlEscape(child) else xmlString += m.NodeToXmlString(child, indentLevel + 1) end if if i = node.children.count() - 1 - if not IsString(child) + if not childIsString xmlString += `${indentString}` end if end if diff --git a/playlet-lib/src/source/services/XmlObject.spec.bs b/playlet-lib/src/source/services/XmlObject.spec.bs new file mode 100644 index 00000000..dce10160 --- /dev/null +++ b/playlet-lib/src/source/services/XmlObject.spec.bs @@ -0,0 +1,34 @@ +namespace Tests + + @suite + class XmlObjectTests extends Rooibos.BaseTestSuite + + @describe("XmlObject") + + @it("creates valid XML") + function _() + xml = new XmlObject() + if xml.Node("Person", { "name": `John "Joker" Doe`, "age": 30 }) + xml.EmptyNode("Address", { "street": "123 Main St", "city": "Anytown", "state": "NY" }) + if xml.Node("Metadata") + xml.TextNode("Data", "Some data") + xml.End() + end if + xml.End() + end if + + expected = ` + +
+ + Some data + + +` + + m.assertEqual(xml.ToXmlString(), expected) + end function + + end class + +end namespace