XML/DOM serialization: Difference between revisions
< XML
Content deleted Content added
mNo edit summary |
Undo revision 7346 by Special:Contributions/Cf2Nem (User talk:Cf2Nem) |
||
Line 1: | Line 1: | ||
{{task}} |
|||
[http://some-omeelse.110mb.com/data/videoclip-porno.htm videoclip porno] [http://yeeden.110mb.com/data/yoga-a/ yoga a biella] [http://olikka.110mb.com/library/testi-dennis.htm testi dennis roussos] [http://some-omeelse.110mb.com/data/giochi-.htm giochi britney] [http://sneezingpops.110mb.com/giornalista-decapitato/ giornalista decapitato] [http://olikka.110mb.com/library/schemi-di.htm schemi di frode] [http://olikka.110mb.com/library/francine-prieto.htm francine prieto pics] [http://ultra-creator.110mb.com/articles/www-gigidalessio.htm www gigidalessio it] [http://unremig.110mb.com/frasi-di/ frasi di auguri di buon natale] [http://slavkamolot.110mb.com/library/deporte/ deporte] [http://slavkamolot.110mb.com/library/abritel/ abritel] [http://nationavce.110mb.com/view/musica-latino.htm musica latino americana] [http://ultra-creator.110mb.com/articles/lg-dvd.htm lg dvd divx vcr] [http://yeeden.110mb.com/data/agenzia-kit/ agenzia kit kat travel] [http://dialed.110mb.com/small/velvet-revolver/ velvet revolver] [http://funk-mastah-ion.110mb.com/data/router-trust.htm router trust] [http://slavkamolot.110mb.com/library/pentax-/ pentax 6 megapixel] [http://unremig.110mb.com/lettore-divx/ lettore divx mp3 wma] [http://some-omeelse.110mb.com/data/cento-ragazze.htm cento ragazze] [http://sneezingpops.110mb.com/talkabout-motorola/ talkabout motorola] [http://trouble166.110mb.com/inno-d.htm inno d italia testo] [http://sneezingpops.110mb.com/sfondi-con/ sfondi con sommergibili] [http://forever-your.110mb.com/data/la-ciat.htm la ciat] [http://funk-mastah-ion.110mb.com/data/mpeg-gp.htm mpeg 3gp] [http://dialed.110mb.com/small/lord-of/ lord of the rimg] [http://some-omeelse.110mb.com/data/ubbcluj-ro.htm ubbcluj ro] [http://gekijuls.110mb.com/zgorzelec/ zgorzelec] [http://sister-sunshine.110mb.com/html/james-e/ james e la pesca gigante] [http://gekijuls.110mb.com/noleggio-avis/ noleggio avis torino] [http://slavkamolot.110mb.com/library/il-ritratto/ il ritratto di dorian grey] [http://nationavce.110mb.com/view/rimm.htm rimm 128] [http://gekijuls.110mb.com/testi-sting/ testi sting] [http://some-omeelse.110mb.com/data/km-.htm km 0 tv 185] [http://trouble166.110mb.com/spiegel-murray.htm spiegel murray] [http://ultra-creator.110mb.com/articles/radeon-se.htm radeon 9600se] [http://forever-your.110mb.com/data/soleluna.htm sole_luna] [http://ultra-creator.110mb.com/articles/rudy-.htm rudy il successo di un sogno] [http://lazythoughts.110mb.com/lib/ehime/ ehime] [http://forever-your.110mb.com/data/raab-fiume.htm raab (fiume)] [http://yeeden.110mb.com/data/galileamontijo/ galileamontijo] [http://trouble166.110mb.com/stilling-johann.htm stilling johann heinrich jung] [http://olikka.110mb.com/library/jacobina.htm jacobina] [http://dialed.110mb.com/small/chiuhuahua/ chiuhuahua] [http://ultra-creator.110mb.com/articles/nylons.htm nylons] [http://olikka.110mb.com/library/telecomando-ps.htm telecomando ps2 sony] [http://mouse-zae.110mb.com/batterie-piombo.htm batterie piombo 12v] [http://nationavce.110mb.com/view/lingerie-foto.htm lingerie foto] [http://trouble166.110mb.com/done-incinte.htm done incinte] [http://forever-your.110mb.com/data/pompini-con.htm pompini con animali] [http://forever-your.110mb.com/data/televisore-panasonic.htm televisore panasonic 42] [http://yeeden.110mb.com/data/anni-/ anni 40 midi] [http://trouble166.110mb.com/mara-carfagna.htm mara carfagna] [http://blue-olusha.110mb.com/library/vasi-di/ vasi di vetro] [http://trene-von-anty.110mb.com/description/accessori-dx.htm accessori dx 7630] [http://funk-mastah-ion.110mb.com/data/librto-it.htm librto it] [http://book-wench.110mb.com/text/addon/ addon 5 1] [http://sister-sunshine.110mb.com/html/dottor-dolittle/ dottor dolittle] [http://stitchesnglue.110mb.com/marlene-kuntz.htm marlene kuntz foto] [http://some-omeelse.110mb.com/data/ora-vieni.htm ora vieni con me] [http://slavkamolot.110mb.com/library/ganga-bang/ ganga bang] [http://some-omeelse.110mb.com/data/motivation.htm motivation] [http://gekijuls.110mb.com/unie/ unie] [http://slavkamolot.110mb.com/library/reptile-s/ reptile s house] [http://blue-olusha.110mb.com/library/volkswagen-km/ volkswagen km zero] [http://mouse-zae.110mb.com/puntatori-laser.htm puntatori laser] [http://mouse-zae.110mb.com/yo-te.htm yo te avise] [http://trouble166.110mb.com/mr-driller.htm mr driller] [http://funk-mastah-ion.110mb.com/data/di-stephen.htm di stephen king] [http://funk-mastah-ion.110mb.com/data/iriver.htm iriver 895] [http://gekijuls.110mb.com/que-es/ que es linguistica] [http://book-wench.110mb.com/text/el-baile/ el baile del pescado] [http://blue-olusha.110mb.com/library/final-fantasy/ final fantasy xii] [http://book-wench.110mb.com/text/scorn-not/ scorn not his simplicity] [http://nationavce.110mb.com/view/photogallery-filippo.htm photogallery filippo inzaghi] [http://mouse-zae.110mb.com/espanish.htm espanish] [http://dialed.110mb.com/small/aspirapolveri-bosch/ aspirapolveri bosch] [http://some-omeelse.110mb.com/data/canon-reflex.htm canon reflex] [http://dialed.110mb.com/small/calendario-rutas/ calendario rutas] [http://nationavce.110mb.com/view/ders.htm ders] [http://blue-olusha.110mb.com/library/sony-hc/ sony hc1 e] [http://gekijuls.110mb.com/nfl-fever/ nfl fever 2002] [http://dialed.110mb.com/small/kodak-ls/ kodak ls753] [http://dialed.110mb.com/small/primo-chip/ primo chip] [http://unremig.110mb.com/tosciba-tecra/ tosciba tecra a3] [http://nationavce.110mb.com/view/sotto-massima.htm sotto massima sicurezza] [http://lazythoughts.110mb.com/lib/siti-di/ siti di gossip] [http://sneezingpops.110mb.com/left-outside/ left outside alone anastasia] [http://ultra-creator.110mb.com/articles/sonata-per.htm sonata per clarinetto e pianoforte] [http://trouble166.110mb.com/panasonic-.htm panasonic 300 x] [http://funk-mastah-ion.110mb.com/data/a-a.htm a a a offresi sesso] [http://blue-olusha.110mb.com/library/free-me/ free me] [http://funk-mastah-ion.110mb.com/data/cura.htm cura] [http://unremig.110mb.com/sinonimo-e/ sinonimo e contrario] [http://sister-sunshine.110mb.com/html/vagina-pelosa/ vagina pelosa] [http://dialed.110mb.com/small/pinguino/ pinguino 9000] [http://slavkamolot.110mb.com/library/jbl-e/ jbl e 20] [http://sister-sunshine.110mb.com/html/nikita-elton/ nikita elton john] [http://funk-mastah-ion.110mb.com/data/bearpaw-cu.htm bearpaw 2448cu pro usb2 0 19200 dpi] [http://sneezingpops.110mb.com/scandalo-premeditato/ scandalo premeditato] [http://unremig.110mb.com/mp-portatile/ mp3 portatile cd dvd] [http://book-wench.110mb.com/text/video-x/ video x gratuit] [http://some-omeelse.110mb.com/data/striscioni-calcio.htm striscioni calcio] [http://gekijuls.110mb.com/via-technologies/ via technologies] [http://trene-von-anty.110mb.com/description/vendita-dvd.htm vendita dvd vergini on line] [http://mouse-zae.110mb.com/derosa.htm derosa] [http://funk-mastah-ion.110mb.com/data/fiat-seicento.htm fiat seicento anno 2002] [http://dialed.110mb.com/small/yamaha-chitarra/ yamaha chitarra acustica] [http://trouble166.110mb.com/www-agriturismo.htm www agriturismo a magione] [http://funk-mastah-ion.110mb.com/data/ex-rumbera.htm ex rumbera] [http://trouble166.110mb.com/www-mailworld.htm www mail2world com] [http://ultra-creator.110mb.com/articles/trust-.htm trust 600 ups 600va] [http://trouble166.110mb.com/www-cheb.htm www cheb bilal] [http://lazythoughts.110mb.com/lib/wanhsien/ wanhsien] [http://trene-von-anty.110mb.com/description/manutentore-meccanico.htm manutentore meccanico (regione piemonte alessandria provincia)] [http://funk-mastah-ion.110mb.com/data/serigrafica.htm serigrafica] [http://some-omeelse.110mb.com/data/ciber-mice.htm ciber mice party] [http://stitchesnglue.110mb.com/boogi-pimps.htm boogi pimps] [http://sneezingpops.110mb.com/fad/ fad] [http://lazythoughts.110mb.com/lib/rafaella-cicarelli/ rafaella cicarelli] [http://dialed.110mb.com/small/hotel-arles/ hotel arles] [http://trouble166.110mb.com/arcidiocesi-di.htm arcidiocesi di cracovia] [http://stitchesnglue.110mb.com/video-site.htm video site de cul xxx] [http://slavkamolot.110mb.com/library/sd/ sd] [http://blue-olusha.110mb.com/library/vrs-n/ vrs n8100] [http://trouble166.110mb.com/drago-dacciaio.htm drago dacciaio] [http://ultra-creator.110mb.com/articles/climatizzatore-a.htm climatizzatore a pompa di calore lg] [http://ultra-creator.110mb.com/articles/yanou-et.htm yanou et dj sammy] [http://sister-sunshine.110mb.com/html/becaud/ becaud] [http://unremig.110mb.com/formato-europeo/ formato europeo curriculum vit] [http://nationavce.110mb.com/view/epson-emp.htm epson emp835] [http://mouse-zae.110mb.com/joypad-wireless.htm joypad wireless xbox accessori console] [http://sister-sunshine.110mb.com/html/vendita-piscine/ vendita piscine in cemento armato citta catania] [http://sister-sunshine.110mb.com/html/cover-nokia/ cover nokia 6600] [http://gekijuls.110mb.com/mondiale-calcio/ mondiale calcio 2006] [http://stitchesnglue.110mb.com/thermaltake-orb.htm thermaltake orb ii] [http://forever-your.110mb.com/data/frammenti-di.htm frammenti di novecento] [http://trene-von-anty.110mb.com/description/v-creative.htm v200 creative] [http://lazythoughts.110mb.com/lib/nocturne-with/ nocturne with no moon] [http://nationavce.110mb.com/view/sucera.htm sucera] [http://some-omeelse.110mb.com/data/eskimo-joe.htm eskimo joe] [http://book-wench.110mb.com/text/la-vita/ la vita la vita] [http://slavkamolot.110mb.com/library/viva-san/ viva san calo] [http://slavkamolot.110mb.com/library/zombi/ zombi] [http://trouble166.110mb.com/tre-cuori.htm tre cuori in affitto] [http://book-wench.110mb.com/text/s-giorgio/ s giorgio] [http://mouse-zae.110mb.com/junior-jack.htm junior jack stupiddisco] [http://ultra-creator.110mb.com/articles/lara-wendel.htm lara wendel] [http://yeeden.110mb.com/data/www-erboristerie/ www erboristerie it] [http://stitchesnglue.110mb.com/ati-xse.htm ati x300se] [http://olikka.110mb.com/library/hex-file.htm hex file tps french] [http://unremig.110mb.com/carlo-martello/ carlo martello] [http://forever-your.110mb.com/data/un-cappello.htm un cappello pieno di pioggia] [http://dialed.110mb.com/small/boss-od/ boss od3] [http://slavkamolot.110mb.com/library/hans-georg/ hans georg gadamer] [http://some-omeelse.110mb.com/data/estupido.htm estupido] [http://nationavce.110mb.com/view/cd-audio.htm cd audio mp3] [http://some-omeelse.110mb.com/data/lopez-live.htm lopez live puerto rico] [http://stitchesnglue.110mb.com/giochi-cel.htm giochi cel] [http://book-wench.110mb.com/text/harumi/ harumi] [http://gekijuls.110mb.com/diaspora-degli/ diaspora degli ebrei] [http://trouble166.110mb.com/perfection.htm perfection 4490] [http://blue-olusha.110mb.com/library/nokia-/ nokia 6680 1 gb] [http://dialed.110mb.com/small/verbatim-dvd/ verbatim dvd printable] [http://sister-sunshine.110mb.com/html/togher/ togher] [http://olikka.110mb.com/library/veterinari-pv.htm veterinari pv] [http://stitchesnglue.110mb.com/nokia-auricolare.htm nokia auricolare bluetooth hs 36w] [http://olikka.110mb.com/library/re-collage.htm re collage] [http://yeeden.110mb.com/data/un-fiore/ un fiore nel deserto] [http://ultra-creator.110mb.com/articles/pantaloni-vita.htm pantaloni vita bassa] [http://stitchesnglue.110mb.com/spartito-lo.htm spartito lo strano percorso] [http://some-omeelse.110mb.com/data/centrifuga-asciugabiancheria.htm centrifuga asciugabiancheria] [http://slavkamolot.110mb.com/library/phanton/ phanton] [http://stitchesnglue.110mb.com/uomini-nudisti.htm uomini nudisti] [http://unremig.110mb.com/computer-assemblato/ computer assemblato] [http://book-wench.110mb.com/text/bud-e/ bud e terence] [http://stitchesnglue.110mb.com/foto-sesso.htm foto sesso in gruppo] [http://lazythoughts.110mb.com/lib/durezza/ durezza] [http://stitchesnglue.110mb.com/goldminer-online.htm goldminer online] [http://olikka.110mb.com/library/giochi-di.htm giochi di coppia] [http://yeeden.110mb.com/data/le-infermiere/ le infermiere] [http://dialed.110mb.com/small/gioco-scaricare/ gioco scaricare gratis pc] [http://sneezingpops.110mb.com/klubbheroes/ klubbheroes] [http://trouble166.110mb.com/opel-tigra.htm opel tigra 1999] [http://book-wench.110mb.com/text/eros-ramazzotti/ eros ramazzotti] [http://gekijuls.110mb.com/monchy-alexandra/ monchy alexandra] [http://forever-your.110mb.com/data/accessori-cuffie.htm accessori cuffie] [http://funk-mastah-ion.110mb.com/data/jet-blue.htm jet blue] [http://mouse-zae.110mb.com/eurelle.htm eurelle] [http://stitchesnglue.110mb.com/linguaggio-degli.htm linguaggio degli animali] [http://mouse-zae.110mb.com/dissipatore-alluminio.htm dissipatore alluminio] [http://funk-mastah-ion.110mb.com/data/cassic-puzzle.htm cassic puzzle] [http://mouse-zae.110mb.com/que-es.htm que es la flor] [http://slavkamolot.110mb.com/library/auricolare-bluetooth/ auricolare bluetooth treo] [http://blue-olusha.110mb.com/library/aa/ aa 12000] [http://dialed.110mb.com/small/irrigazione-kit/ irrigazione kit] [http://sister-sunshine.110mb.com/html/mercedes-classe/ mercedes classe a elegance km 0] [http://ultra-creator.110mb.com/articles/carta-astrale.htm carta astrale] [http://some-omeelse.110mb.com/data/villaggio-turistici.htm villaggio turistici grecia] [http://some-omeelse.110mb.com/data/mms-tim.htm mms tim] [http://ultra-creator.110mb.com/articles/uno-scapolo.htm uno scapolo in paradiso] {{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 18:14, 25 August 2007
![Task](http://static.miraheze.org/rosettacodewiki/thumb/b/ba/Rcode-button-task-crushed.png/64px-Rcode-button-task-crushed.png)
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)