4 ms·
JS is a procedural language. The somewhat forgotten procedural pattern for constructing these things in procedural languages is to use a canvas:: xmlCtx =
by Mikhail_Edoshin 6y ago
JS is a procedural language. The somewhat forgotten procedural pattern for constructing these things in procedural languages is to use a canvas::
xmlCtx = MkXmlCtx()
SetNsPfx(xmlCtx, "foo", "http://foo.com/ns")
OpenTag(xmlCtx, "foo:bar")
SetAttr(xmlCtx, "name", "value")
Write(xmlCtx, "string")
CloseTag(xmlCtx)
xml = GetXml(xmlCtx)
It may look boring but it's exactly the right thing. Syntactic sugar is deceptive. A declarative approach is not the right pattern in JS. (It's essential to XML, but XML is a very different thing.)