XML/DOM serialization: Difference between revisions

Added FreeBASIC
(Added FreeBASIC)
(3 intermediate revisions by 2 users not shown)
Line 505:
 
Main
String XML, body;
Stack{
Store ( body, Multi_copy( body,"<?xml version=\"1.0\" ?>",
Line 511:
NORMAL_TAG), NORMAL_TAG),
NULL) );
}Stack_off;
 
Print "%s\n", body;
Free secure XML, body;
End
</syntaxhighlight>
Line 820:
 
(On the use of <tt>&lt;unsafe></tt>: The class has not yet been reviewed for E safety, so <tt>&lt;import:...makeDocumentBuilderFactory></tt> is not yet allowed. The review would probably be straightforward.)
 
=={{header|FreeBASIC}}==
{{libheader|libxml2}}
<syntaxhighlight lang="vbnet">#include once "crt/stdio.bi"
#include once "crt/stdlib.bi"
#include once "libxml/tree.bi"
#include once "libxml/parser.bi"
 
'' Create a new document
Dim As xmlDocPtr doc = xmlNewDoc(Strptr("1.0"))
 
'' Create a root node
Dim As xmlNodePtr root_node = xmlNewNode(NULL, Strptr("root"))
 
'' Set the root node for the document
xmlDocSetRootElement(doc, root_node)
 
'' Create a new node
Dim As xmlNodePtr node = xmlNewNode(NULL, Strptr("element"))
 
'' Add some text to the node
xmlNodeSetContent(node, Strptr("Some text here"))
 
'' Add the new node to the root node
xmlAddChild(root_node, node)
 
'' Dump the document to stdout, it will be well formatted
xmlDocDump(stdout, doc)
 
'' Free the document
xmlFreeDoc(doc)
 
'' Free the global variables that may have been allocated by the parser
xmlCleanupParser()</syntaxhighlight>
 
=={{header|F_Sharp|F#}}==
Line 1,828 ⟶ 1,862:
=={{header|Wren}}==
Wren has no built-in or (AFAIK) third party support for XML so we code a minimal DOM sufficient for completing this task.
<syntaxhighlight lang="ecmascriptwren">class XmlDocument {
construct new(root) {
_root = root
Line 1,878 ⟶ 1,912:
{{libheader|Wren-xsequence}}
Since the first version was written, the above XML parser has appeared and, consequently, the solution can now be rewritten as follows.
<syntaxhighlight lang="ecmascriptwren">import "./xsequence" for XDocument, XElement
 
var doc = XDocument.new(
2,148

edits