XML/DOM serialization: Difference between revisions
< XML
Content added Content deleted
mNo edit summary |
(Undo revision 8490 by Special:Contributions/Cf2Nem (User talk:Cf2Nem)) |
||
Line 1: | Line 1: | ||
{{task}} |
|||
[http://pouringsunny.ifrance.com/description/moveies/ moveies] [http://eccoblackfin.ifrance.com/html/puppe-apera.htm puppe apera] [http://seachildelf.ifrance.com/resources/fulda/ fulda] [http://emrinalexander.ifrance.com/styles/les-ailes.htm les ailes] [http://animaetrix00.ifrance.com/content/giro-di/ giro di prova per gtr] [http://jazzyjoe.ifrance.com/sex-arabc/ sex arabc] [http://feelosof.ifrance.com/description/trans-a/ trans a torino] [http://firejedi.ifrance.com/new/mercedes-/ mercedes 320 e] [http://firejedi.ifrance.com/new/frigoriferi-a/ frigoriferi a incasso] [http://pouringsunny.ifrance.com/description/grow-rpg/ grow rpg] [http://lethalga.ifrance.com/topic/reading-usa/ reading (usa)] [http://animaetrix00.ifrance.com/content/e-amore/ e amore] [http://chrystiala.ifrance.com/library/ps-splinter.htm ps2 splinter cell] [http://cikumuffin.ifrance.com/topic/timeshare-resales/ timeshare resales] [http://eccoblackfin.ifrance.com/html/ufo-edizione.htm ufo edizione speciale limitata] [http://jojorock.ifrance.com/articles/protezioni-snowboard/ protezioni snowboard] [http://emrinalexander.ifrance.com/styles/faccetta-nera.htm faccetta nera rmx] [http://listsobacka.ifrance.com/small/come-impostare.htm come impostare un curriculum] [http://beatpoetsa.ifrance.com/description/fujifilm-a.htm fujifilm a 210] [http://beatpoetsa.ifrance.com/description/cartolina-mms.htm cartolina mms] [http://emrinalexander.ifrance.com/styles/hypersoft.htm hypersoft] [http://jojorock.ifrance.com/articles/gli-/ gli incredibili] [http://jazzyjoe.ifrance.com/fica-/ fica 18 anni] [http://listsobacka.ifrance.com/small/musica-de.htm musica de chicha] [http://infunt.ifrance.com/articles/discount-cruise/ discount cruise] [http://firejedi.ifrance.com/new/la-maschera/ la maschera di vetro la serie completa] [http://belikan.ifrance.com/library/piaggio-x.htm piaggio x9] [http://liubash.ifrance.com/new/decoder-terrestre.htm decoder terrestre humax 5000] [http://cikumuffin.ifrance.com/topic/www-condominioweb/ www condominioweb it] [http://thecakeblog.ifrance.com/articles/coppie-vt/ coppie vt] [http://cikumuffin.ifrance.com/topic/nella/ nella] [http://jazzyjoe.ifrance.com/annuncio-lavoro/ annuncio lavoro bergamo] [http://makkiesan.ifrance.com/sober.htm sober] [http://firejedi.ifrance.com/new/unicredito/ unicredito] [http://chrystiala.ifrance.com/library/sistem-of.htm sistem of a down download] [http://jene7777777.ifrance.com/new/plip.htm plip] [http://eccoblackfin.ifrance.com/html/christina-versilia.htm christina versilia] [http://beatpoetsa.ifrance.com/description/file-soft.htm file soft cam] [http://pouringsunny.ifrance.com/description/armidillo/ armidillo] [http://jojorock.ifrance.com/articles/nikon-d/ nikon d70 kit 1870mm] [http://chrystiala.ifrance.com/library/il-misterioso.htm il misterioso mr moto] [http://jazzyjoe.ifrance.com/frendz/ frendz] [http://lethalga.ifrance.com/topic/autoroute/ autoroute 2005] [http://animaetrix00.ifrance.com/content/p/ p4 640] [http://feelosof.ifrance.com/description/hub-con/ hub con alimentatore] [http://infunt.ifrance.com/articles/gabriel-pontello/ gabriel pontello supersex] [http://lethalga.ifrance.com/topic/casio-ex/ casio ex s500] [http://makkiesan.ifrance.com/la-serenissima.htm la serenissima dei moltosugo] [http://beatpoetsa.ifrance.com/description/dj-pandolfi.htm dj pandolfi main title the kiss] [http://listsobacka.ifrance.com/small/anastacia-stick.htm anastacia stick] [http://makkiesan.ifrance.com/russell-court.htm russell court] [http://liubash.ifrance.com/new/keane-changing.htm keane changing] [http://firejedi.ifrance.com/new/residence-san/ residence san remo] [http://seachildelf.ifrance.com/resources/bad-boy/ bad boy bubby] [http://makkiesan.ifrance.com/chendi-ilarie.htm chendi ilarie] [http://shmarodral.ifrance.com/text/ella-y.htm ella y yo aventura y don omar] [http://firejedi.ifrance.com/new/dmc-fz/ dmc fz2 panasonic] [http://infunt.ifrance.com/articles/byc-nie/ byc nie miec 2] [http://liubash.ifrance.com/new/nikolias.htm nikolias] [http://chrystiala.ifrance.com/library/tabuk.htm tabuk] [http://beatpoetsa.ifrance.com/description/canon-eos.htm canon eos 20] [http://firejedi.ifrance.com/new/perth-shopping/ perth shopping] [http://lethalga.ifrance.com/topic/sheke/ sheke] [http://jojorock.ifrance.com/articles/tesi-in/ tesi in economia e gestione delle impres] [http://animaetrix00.ifrance.com/content/trango-trek/ trango trek] [http://animaetrix00.ifrance.com/content/adventure-pokemon/ adventure pokemon] [http://firejedi.ifrance.com/new/magix-music/ magix music studio 2005 deluxe] [http://shmarodral.ifrance.com/text/gruppo-informatico.htm gruppo informatico siges] [http://firejedi.ifrance.com/new/vie-di/ vie di roma] [http://cikumuffin.ifrance.com/topic/pw-e/ pw e320] [http://pouringsunny.ifrance.com/description/zen-nano/ zen nano plus 512 mb] [http://listsobacka.ifrance.com/small/allenatore.htm allenatore] [http://firejedi.ifrance.com/new/thinkpad-re/ thinkpad r50e] [http://listsobacka.ifrance.com/small/tiger-woods.htm tiger woods psp] [http://listsobacka.ifrance.com/small/mr-snoozle.htm mr snoozle] [http://cikumuffin.ifrance.com/topic/dipinti-su/ dipinti su stoffe] [http://beatpoetsa.ifrance.com/description/erotik-oyun.htm erotik oyun] [http://pouringsunny.ifrance.com/description/rivista-arte/ rivista arte mensile] [http://cikumuffin.ifrance.com/topic/scheda-video/ scheda video ati radeon x600 256] [http://chrystiala.ifrance.com/library/monzuno.htm monzuno] [http://jene7777777.ifrance.com/new/ristorante-dalla.htm ristorante dalla padella alla brace roma] [http://chrystiala.ifrance.com/library/robo-pit.htm robo pit] [http://cikumuffin.ifrance.com/topic/masterizzatore-combo/ masterizzatore combo notebook] [http://listsobacka.ifrance.com/small/toner-magicolor.htm toner magicolor 2300] [http://jazzyjoe.ifrance.com/www-bevande/ www bevande com] [http://animaetrix00.ifrance.com/content/ultime-canzoni/ ultime canzoni mauro nardi] [http://chrystiala.ifrance.com/library/formaggini-susanna.htm formaggini susanna] [http://pouringsunny.ifrance.com/description/il-mondo/ il mondo insieme a te di max pezzali] [http://feelosof.ifrance.com/description/pigaultlebrun/ pigaultlebrun] [http://lethalga.ifrance.com/topic/convention-bush/ convention bush] [http://animaetrix00.ifrance.com/content/driver-nec/ driver nec e313 gratis] [http://shotlandetz.ifrance.com/blog/aranea/ aranea] [http://animaetrix00.ifrance.com/content/uefa-ps/ uefa ps2] [http://lethalga.ifrance.com/topic/ilgioco/ ilgioco] [http://beatpoetsa.ifrance.com/description/black-out.htm black out catastrofe a los angeles] [http://belikan.ifrance.com/library/porno-diva.htm porno diva] [http://feelosof.ifrance.com/description/duncan-david/ duncan david douglas] [http://feelosof.ifrance.com/description/shure-ec/ shure e5c] [http://jojorock.ifrance.com/articles/foto-orologio/ foto orologio parete] [http://seachildelf.ifrance.com/resources/ottimizzazione-sito/ ottimizzazione sito web] [http://pouringsunny.ifrance.com/description/severina-nude/ severina nude free] [http://cikumuffin.ifrance.com/topic/aequidens/ aequidens] [http://cikumuffin.ifrance.com/topic/detergente-intimo/ detergente intimo] [http://thecakeblog.ifrance.com/articles/la-danza/ la danza del vampiro] [http://eccoblackfin.ifrance.com/html/cesar-pueyrredon.htm cesar pueyrredon] [http://listsobacka.ifrance.com/small/fiat-punto.htm fiat punto el] [http://makkiesan.ifrance.com/www-vascorossi.htm www vascorossi it] [http://lethalga.ifrance.com/topic/stamping-ground/ stamping ground] [http://eccoblackfin.ifrance.com/html/piastra-di.htm piastra di registrazione] [http://emrinalexander.ifrance.com/styles/blonde-blowjob.htm blonde blowjob] [http://listsobacka.ifrance.com/small/irrigazione-tubo.htm irrigazione tubo] [http://lethalga.ifrance.com/topic/conquistare-ragazze/ conquistare ragazze] [http://firejedi.ifrance.com/new/que-puedo/ que puedo decir] [http://lethalga.ifrance.com/topic/sigla-th/ sigla 7th heaven] [http://makkiesan.ifrance.com/tan-solo.htm tan solo palabras] [http://pouringsunny.ifrance.com/description/showgirl-nude/ showgirl nude gratis] [http://animaetrix00.ifrance.com/content/auto-tata/ auto tata safari] [http://beatpoetsa.ifrance.com/description/cancrini-francesco.htm cancrini francesco] [http://firejedi.ifrance.com/new/sample-video/ sample video porn teen] [http://shotlandetz.ifrance.com/blog/bernie-boulder/ bernie boulder] [http://liubash.ifrance.com/new/chiropratici.htm chiropratici] [http://emrinalexander.ifrance.com/styles/omosessuali-transe.htm omosessuali transe cazzi grossi] [http://jazzyjoe.ifrance.com/ma-/ ma 322 a maggi] [http://shotlandetz.ifrance.com/blog/risoluzione-portatili/ risoluzione portatili] [http://eccoblackfin.ifrance.com/html/iomega-hd.htm iomega hd esterno] [http://infunt.ifrance.com/articles/cucaracia/ cucaracia] [http://listsobacka.ifrance.com/small/luoghi-per.htm luoghi per guardoni torino forum] [http://lethalga.ifrance.com/topic/www-hamer/ www hamer] [http://makkiesan.ifrance.com/le-passeggiate.htm le passeggiate al campo di marte] [http://seachildelf.ifrance.com/resources/roy-ayers/ roy ayers testi] [http://eccoblackfin.ifrance.com/html/new-mexico.htm new mexico cose fare] [http://shotlandetz.ifrance.com/blog/diario-epoca/ diario epoca] [http://thecakeblog.ifrance.com/articles/xoomer/ xoomer] [http://shmarodral.ifrance.com/text/icarplay-cassette.htm icarplay cassette adapter] [http://animaetrix00.ifrance.com/content/lettore-dvd/ lettore dvd con uscite audio] [http://thecakeblog.ifrance.com/articles/collegio-periti/ collegio periti tecnici palermo] [http://pouringsunny.ifrance.com/description/george-michel/ george michel] [http://liubash.ifrance.com/new/www-flowerhorn.htm www flowerhorn com] [http://chrystiala.ifrance.com/library/www-horoscopos.htm www horoscopos com mx] [http://cikumuffin.ifrance.com/topic/bearshare-ita/ bearshare ita] [http://liubash.ifrance.com/new/acebal-emilio.htm acebal emilio] [http://beatpoetsa.ifrance.com/description/diapositive-proiettore.htm diapositive proiettore] [http://liubash.ifrance.com/new/smart-usata.htm smart usata] [http://infunt.ifrance.com/articles/celebrity-sex/ celebrity sex] [http://shmarodral.ifrance.com/text/culi-sfondati.htm culi sfondati da cavalli] [http://cikumuffin.ifrance.com/topic/casio-exp/ casio exp700] [http://jazzyjoe.ifrance.com/nikkei-lcd/ nikkei lcd] [http://feelosof.ifrance.com/description/mueve/ mueve] [http://lethalga.ifrance.com/topic/ceolin-group/ ceolin group] [http://listsobacka.ifrance.com/small/nina-mirc.htm nina mirc] [http://seachildelf.ifrance.com/resources/fiat-punto/ fiat punto nuovo] [http://firejedi.ifrance.com/new/www-fihp/ www fihp org] [http://shotlandetz.ifrance.com/blog/leccare-i/ leccare i miei piedi] [http://feelosof.ifrance.com/description/risorsa-midi/ risorsa midi] [http://firejedi.ifrance.com/new/sailo-moon/ sailo moon] [http://cikumuffin.ifrance.com/topic/doveri-costituzione/ doveri costituzione europea] [http://emrinalexander.ifrance.com/styles/powershot-.htm powershot 75 canon] [http://liubash.ifrance.com/new/le-nuove.htm le nuove avventure di furia] [http://seachildelf.ifrance.com/resources/atlantis-i/ atlantis i storm adsl] [http://listsobacka.ifrance.com/small/tupac-shakur.htm tupac shakur hip hop genius] [http://makkiesan.ifrance.com/lacoste-uomo.htm lacoste uomo] [http://belikan.ifrance.com/library/incontro-thiene.htm incontro thiene] [http://cikumuffin.ifrance.com/topic/bang-bus/ bang bus] [http://shmarodral.ifrance.com/text/kelly-clarkson.htm kelly clarkson] [http://makkiesan.ifrance.com/www-pinkfloyd.htm www pinkfloyd con] [http://seachildelf.ifrance.com/resources/suggest-link/ suggest link] [http://feelosof.ifrance.com/description/orologiaio/ orologiaio] [http://feelosof.ifrance.com/description/usb-/ usb 2 mac controller] [http://firejedi.ifrance.com/new/encarta-plus/ encarta plus 2005] [http://pouringsunny.ifrance.com/description/scheda-video/ scheda video pci express geforce 6600] [http://beatpoetsa.ifrance.com/description/christiane-f.htm christiane f noi i ragazzi dello zoo di] [http://emrinalexander.ifrance.com/styles/hyundai-santa.htm hyundai santa f] [http://feelosof.ifrance.com/description/bobble-ice/ bobble ice age] [http://seachildelf.ifrance.com/resources/microonde-candy/ microonde candy] [http://cikumuffin.ifrance.com/topic/morsztyn-zbigniew/ morsztyn zbigniew] [http://infunt.ifrance.com/articles/sistema-modulare/ sistema modulare] [http://thecakeblog.ifrance.com/articles/il-nostro/ il nostro prossimo] [http://animaetrix00.ifrance.com/content/jaguar-xtype/ jaguar xtype executive] [http://liubash.ifrance.com/new/percorsi-autostradali.htm percorsi autostradali e stradali] [http://beatpoetsa.ifrance.com/description/ragazza-chivasso.htm ragazza chivasso] [http://makkiesan.ifrance.com/mientes-tan.htm mientes tan bien] [http://jazzyjoe.ifrance.com/lechwe/ lechwe] [http://ohmygoshalix.ifrance.com/blog/sbn-online.htm sbn online] [http://jojorock.ifrance.com/articles/soddr-ram/ soddr2 ram 512mb] [http://pouringsunny.ifrance.com/description/power/ power 5013] [http://liubash.ifrance.com/new/gemboy-teorema.htm gemboy teorema] [http://seachildelf.ifrance.com/resources/calcio-americano/ calcio americano] [http://makkiesan.ifrance.com/masterizzatore-lg.htm masterizzatore lg black] [http://jazzyjoe.ifrance.com/fly-girl/ fly girl] [http://cikumuffin.ifrance.com/topic/dr-alban/ dr alban] [http://jojorock.ifrance.com/articles/condizionatori-usati/ condizionatori usati] [http://eccoblackfin.ifrance.com/html/fred-vargas.htm fred vargas] [http://thecakeblog.ifrance.com/articles/blaupunkt-casablanca/ blaupunkt casablanca] [http://chrystiala.ifrance.com/library/esecuzione-ostaggi.htm esecuzione ostaggi video] [http://infunt.ifrance.com/articles/bataglie-in/ bataglie in terra] [http://eccoblackfin.ifrance.com/html/moto-storiche.htm moto storiche vendita] [http://shotlandetz.ifrance.com/blog/giochi-lg/ giochi lg u8110] [http://shmarodral.ifrance.com/text/toner-epson.htm toner epson laser] [http://emrinalexander.ifrance.com/styles/reale-mutua.htm reale mutua] [http://shmarodral.ifrance.com/text/nelly-forza.htm nelly forza] {{task}} |
|||
Create a simple DOM and having it serialize to: |
Create a simple DOM and having it serialize to: |
||
Line 29: | Line 29: | ||
println(document.saveXML(root)) |
println(document.saveXML(root)) |
||
(On the use of <code><unsafe></code>: The class has not yet been reviewed for E safety, so <code><import:...makeDocumentBuilderFactory></code> is not yet allowed. The review would probably be straightforward.) |
|||
(On the use of <code> |
|||
==[[JavaScript]]== |
|||
[[Category:JavaScript]] |
|||
'''Interpreter:''' Firefox 2.0 |
|||
DOM |
|||
var doc = document.implementation.createDocument( null, 'root', null ); |
|||
var root = doc.documentElement; |
|||
var element = doc.createElement( 'element' ); |
|||
root.appendChild( element ); |
|||
element.appendChild( document.createTextNode('Some text here') ); |
|||
var xmlString = new XMLSerializer().serializeToString( doc ); |
|||
E4X |
|||
var xml = <root> |
|||
<element>Some text here</element> |
|||
</root>; |
|||
var xmlString = xml.toXMLString(); |
|||
E4X — with processing instruction |
|||
XML.ignoreProcessingInstructions = false; |
|||
var xml = <?xml version="1.0"?> |
|||
<root> |
|||
<element>Some text here</element> |
|||
</root>; |
|||
var xmlString = xml.toXMLString(); |
|||
==[[Perl]]== |
|||
[[Category:Perl]] |
|||
use XML::DOM::BagOfTricks qw(createDocument createTextElement); |
|||
my ($doc, $root) = createDocument('root'); |
|||
$root->appendChild( |
|||
createTextElement($doc, 'element', 'Some text here') |
|||
); |
|||
print $doc->toString; |
|||
==[[PHP]]== |
|||
[[Category:PHP]] |
|||
'''Interpreter:''' [[PHP]] 5 |
|||
<?php |
|||
$dom = new DOMDocument();//the constructor also takes the version and char-encoding as it's two respective parameters |
|||
$dom->formatOutput = true;//format the outputted xml |
|||
$root = $dom->createElement('root'); |
|||
$element = $dom->createElement('element'); |
|||
$element->appendChild($dom->createTextNode('Some text here')); |
|||
$root->appendChild($element); |
|||
$dom->appendChild($root); |
|||
$xmlstring = $dom->saveXML(); |
|||
==[[Python]]== |
|||
[[Category:Python]] |
|||
'''Interpreter:''' [[Python]] 2.5 |
|||
from xml.dom.minidom import getDOMImplementation |
|||
dom = getDOMImplementation() |
|||
document = dom.createDocument(None, "root", None) |
|||
topElement = document.documentElement |
|||
firstElement = document.createElement("element") |
|||
topElement.appendChild(firstElement) |
|||
textNode = document.createTextNode("Some text here") |
|||
firstElement.appendChild(textNode) |
|||
xmlString = document.toprettyxml(" " * 4) |
|||
'''Interpreter:''' [[Python]] 2.5 |
|||
from xml.etree import ElementTree as et |
|||
root = et.Element("root") |
|||
et.SubElement(root, "element").text = "Some text here" |
|||
xmlString = et.tostring(root) |
|||
==[[Ruby]]== |
|||
[[Category:Ruby]] |
|||
require("rexml/document") |
|||
include REXML |
|||
(xml = Document.new) << XMLDecl.new |
|||
root=xml.add_element('root') |
|||
element=root.add_element('element') |
|||
element.add_text('Some text here') |
|||
puts xml.to_s(0) |
Revision as of 19:19, 10 September 2007
XML/DOM serialization
You are encouraged to solve this task according to the task description, using any language you may know.
You are encouraged to solve this task according to the task description, using any language you may know.
Create a simple DOM and having it serialize to:
<?xml version="1.0" ?> <root> <element> Some text here </element> </root>
E
Implementation: E-on-Java
This makes use of XML libraries provided with Java.
def document := <unsafe:javax.xml.parsers.makeDocumentBuilderFactory> \ .newInstance() \ .newDocumentBuilder() \ .getDOMImplementation() \ .createDocument(null, "root", null) def root := document.getDocumentElement() root.appendChild( def element := document.createElement("element")) element.appendChild( document.createTextNode("Some text here")) println(document.saveXML(root))
(On the use of <unsafe>
: The class has not yet been reviewed for E safety, so <import:...makeDocumentBuilderFactory>
is not yet allowed. The review would probably be straightforward.)
JavaScript
Interpreter: Firefox 2.0
DOM
var doc = document.implementation.createDocument( null, 'root', null ); var root = doc.documentElement; var element = doc.createElement( 'element' ); root.appendChild( element ); element.appendChild( document.createTextNode('Some text here') ); var xmlString = new XMLSerializer().serializeToString( doc );
E4X
var xml = <root> <element>Some text here</element> </root>; var xmlString = xml.toXMLString();
E4X — with processing instruction
XML.ignoreProcessingInstructions = false; var xml = <?xml version="1.0"?> <root> <element>Some text here</element> </root>; var xmlString = xml.toXMLString();
Perl
use XML::DOM::BagOfTricks qw(createDocument createTextElement); my ($doc, $root) = createDocument('root'); $root->appendChild( createTextElement($doc, 'element', 'Some text here') ); print $doc->toString;
PHP
Interpreter: PHP 5
<?php $dom = new DOMDocument();//the constructor also takes the version and char-encoding as it's two respective parameters $dom->formatOutput = true;//format the outputted xml $root = $dom->createElement('root'); $element = $dom->createElement('element'); $element->appendChild($dom->createTextNode('Some text here')); $root->appendChild($element); $dom->appendChild($root); $xmlstring = $dom->saveXML();
Python
Interpreter: Python 2.5
from xml.dom.minidom import getDOMImplementation dom = getDOMImplementation() document = dom.createDocument(None, "root", None) topElement = document.documentElement firstElement = document.createElement("element") topElement.appendChild(firstElement) textNode = document.createTextNode("Some text here") firstElement.appendChild(textNode) xmlString = document.toprettyxml(" " * 4)
Interpreter: Python 2.5
from xml.etree import ElementTree as et root = et.Element("root") et.SubElement(root, "element").text = "Some text here" xmlString = et.tostring(root)
Ruby
require("rexml/document") include REXML (xml = Document.new) << XMLDecl.new root=xml.add_element('root') element=root.add_element('element') element.add_text('Some text here') puts xml.to_s(0)