XML/DOM serialization: Difference between revisions
→{{header|Z80 Assembly}}
(→{{header|Wren}}: Added a version using an XML library.) |
Puppydrum64 (talk | contribs) |
||
Line 1,855:
</xsl:template>
</xsl:stylesheet></lang>
=={{header|Z80 Assembly}}==
Assembled and run using WinAPE's built-in assembler. Tags have to be manually opened and closed, but it works!
<lang z80>org &1000
main:
ld hl,XML_Header
ld de,XMLRam
call strcpy
ld hl,XML_Root
push hl
call AddXMLNode
ld hl,XML_Element
push hl
call AddXMLNode
ld hl,XML_Entry
call strcpy
pop hl ;ld hl,XML_Element
call CloseXMLNode
pop hl ;ld hl,XML_Root
call CloseXMLNode
ld hl,XMLRam
jp PrintString ;and then return to basic.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
AddXMLNode:
;hl = pointer to desired node name
;de = destination ram
;carry flag; set = <foo/>, clear = <foo></foo>
push af
ld a,'<'
ld (de),a
inc de
call strcpy
pop af
jr nc,skip_AddXMLNode
ld a,'/'
ld (de),a
inc de
skip_AddXMLNode:
ld a,'>'
ld (de),a
inc de
xor a
ld (de),a
;don't inc de afterwards, since we may want to add more
ret
CloseXMLNode:
ld a,'<'
ld (de),a
inc de
ld a,'/'
ld (de),a
inc de
call strcpy
ld a,'>'
ld (de),a
inc de
xor a
ld (de),a
ret
PrintString:
ld a,(hl)
or a
ret z
call &BB5A
inc hl
jr PrintString
strcpy:
;HL = string source
;DE = destination
;copies 1 byte at a time until a null terminator is copied, then exits.
ld a,(hl)
ld (de),a
or a
ret z
inc hl
inc de
jp strcpy
org &1200
XML_Header:
byte "<?xml version=",&22,"1.0",&22,"?>",0
XML_Root:
byte "root",0
XML_Element:
byte "element",0
XML_Entry:
byte "some text here",0
org &1300
XMLRam: ;this is where the output is stored.</lang>
{{out}}
<pre>call &1000
<?xml version="1.0"?><root><element>some text here</element></root></pre>
{{omit from|Batch File|No way of XML parsing or processing.}}
|