XML/DOM serialization: Difference between revisions
< XML
Content added Content deleted
mNo edit summary |
(Undo revision 7941 by Special:Contributions/Cf2Nem (User talk:Cf2Nem)) |
||
Line 1: | Line 1: | ||
{{task}} |
|||
[http://snakeystil.ifrance.com/jelenakarleusa/index.html jelenakarleusa] [http://oddonpurpose.ifrance.com/lady-diana-morente.html lady diana morente] [http://risdimpuka.ifrance.com/lets-get-retared/index.html lets get retared] [http://oddonpurpose.ifrance.com/litfiba-tour.html litfiba tour] [http://eliasn5gh.ifrance.com/let-go-lavigne.html let go lavigne] [http://katzella.ifrance.com/hand-in-glove/index.html hand in glove] [http://starcross33.ifrance.com/libri-e-racconti-vari/index.html libri e racconti vari] [http://alexandraa80.ifrance.com/laura-sex-annunci/index.html laura sex annunci] [http://pupsik1993.ifrance.com/lmc-versus-u2.html lmc versus u2] [http://taylors-acolyte.ifrance.com/il-toro-loco.html il toro loco] [http://cuivenarius.ifrance.com/honky-tonk-blues.html honky tonk blues] [http://busjavka.ifrance.com/http-videoirc/index.html http videoirc fidolab net] [http://xxxenichkaa.ifrance.com/licinia-lentini.html licinia lentini] [http://oddonpurpose.ifrance.com/la-zoo.html la zoo] [http://risdimpuka.ifrance.com/la-rueca/index.html la rueca] [http://child-ofadot.ifrance.com/insesto.html insesto] [http://carbonphoenix.ifrance.com/joker-cam.html joker cam] [http://listmishyk.ifrance.com/keane-everbody/index.html keane everbody changing] [http://busjavka.ifrance.com/hotel-aquila/index.html hotel aquila] [http://plyuh-vios.ifrance.com/incontri-free.html incontri free] [http://plyuh-vios.ifrance.com/immaggini-d-ristorante.html immaggini d ristorante] [http://busjavka.ifrance.com/hit-mania-7/index.html hit mania 7] [http://katzella.ifrance.com/hahas/index.html hahas] [http://xxxenichkaa.ifrance.com/le-cantique-de-noel.html le cantique de noel] [http://oddonpurpose.ifrance.com/locupletare.html locupletare] [http://angeljazz711.ifrance.com/indaco-dagli-occhi.html indaco dagli occhi del cielo di zucchero] [http://pupsik1993.ifrance.com/lacafetera-m.html lacafetera m n] [http://pupsik1993.ifrance.com/la100-com.html la100 com] [http://alexandraa80.ifrance.com/liu-jo/index.html liu jo] [http://busjavka.ifrance.com/houstones/index.html houstones] [http://snakeystil.ifrance.com/jan-crocker/index.html jan crocker] [http://oddonpurpose.ifrance.com/la-campionessa.html la campionessa] [http://xxxenichkaa.ifrance.com/la-morochita-merengue.html la morochita merengue] [http://taylors-acolyte.ifrance.com/io-si.html io si] [http://carbonphoenix.ifrance.com/jomega.html jomega] [http://listmishyk.ifrance.com/kover-plus/index.html kover plus] [http://xxxenichkaa.ifrance.com/lady-sonia-com.html lady sonia com] [http://katzella.ifrance.com/il-ballo-di-nando/index.html il ballo di nando] [http://snakeystil.ifrance.com/jej-portret/index.html jej portret] [http://eliasn5gh.ifrance.com/le-taglitelle-di-nonna.html le taglitelle di nonna pina] [http://katzella.ifrance.com/haiduci-mp3-gratis/index.html haiduci mp3 gratis] [http://eliasn5gh.ifrance.com/lord-ofthe-rings.html lord ofthe rings] [http://angeljazz711.ifrance.com/intimacy.html intimacy] [http://thecrownless.ifrance.com/insubria-winner/index.html insubria winner] [http://eliasn5gh.ifrance.com/louis-benedictus.html louis benedictus] [http://xxxenichkaa.ifrance.com/liceo-la-farina.html liceo la farina messina] [http://katzella.ifrance.com/ig/index.html ig] [http://carbonphoenix.ifrance.com/jewel-lyrics-spirit.html jewel lyrics spirit] [http://katzella.ifrance.com/iitta-di-israele/index.html iitta di israele] [http://xxxenichkaa.ifrance.com/lambada-kjarkas.html lambada kjarkas] [http://busjavka.ifrance.com/hitlerjugent/index.html hitlerjugent] [http://angeljazz711.ifrance.com/immagini-gatto-nero.html immagini gatto nero] [http://angeljazz711.ifrance.com/italia-uno.html italia uno] [http://carbonphoenix.ifrance.com/juaquin-cortez.html juaquin cortez] [http://xxxenichkaa.ifrance.com/lettere-dell-alfabeto.html lettere dell alfabeto cinese] [http://katzella.ifrance.com/hidalgo/index.html hidalgo] [http://busjavka.ifrance.com/hotel-des-alpes/index.html hotel des alpes misurina] [http://chasingspaces.ifrance.com/hiduchi/index.html hiduchi] [http://starcross33.ifrance.com/log-a-attivazioni-v7/index.html log a attivazioni v7] [http://cuivenarius.ifrance.com/hir-ja-kam-hir.html hir ja kam hir aj go] [http://taylors-acolyte.ifrance.com/infiniti-carezze.html infiniti carezze] [http://snakeystil.ifrance.com/i-m-a-raver-baby/index.html i m a raver baby] [http://alexandraa80.ifrance.com/la-balilla-mid/index.html la balilla mid] [http://listmishyk.ifrance.com/k550/index.html k550] [http://oddonpurpose.ifrance.com/liberta-stampa.html liberta stampa] [http://carbonphoenix.ifrance.com/jingle-bells-per-coro.html jingle bells per coro misto] [http://risdimpuka.ifrance.com/laskovski/index.html laskovski] [http://xxxenichkaa.ifrance.com/librerie-autocad.html librerie autocad] [http://pupsik1993.ifrance.com/lean-bvack.html lean bvack] [http://fluffy-mind.ifrance.com/koja-gora-ivo.html koja gora ivo] [http://katzella.ifrance.com/heroes-of-might/index.html heroes of might and magic cd crack] [http://fluffy-mind.ifrance.com/katiejordan.html katiejordan] [http://oddonpurpose.ifrance.com/locali-sex-a-novara.html locali sex a novara] [http://xxxenichkaa.ifrance.com/lihdo.html lihdo] [http://fluffy-mind.ifrance.com/kama-sexo.html kama sexo] [http://fluffy-mind.ifrance.com/kekilli.html kekilli] [http://oddonpurpose.ifrance.com/los-12-discipulos.html los 12 discipulos] [http://busjavka.ifrance.com/hhttp-hotmail-com/index.html hhttp hotmail com] [http://taylors-acolyte.ifrance.com/incanto-live.html incanto live baglioni] [http://oddonpurpose.ifrance.com/latetia-casta.html latetia casta] [http://child-ofadot.ifrance.com/incontri-sesso-torino.html incontri sesso torino] [http://child-ofadot.ifrance.com/il-coccogrillo-come.html il coccogrillo come fa] [http://thecrownless.ifrance.com/indipop-midi/index.html indipop midi] [http://pupsik1993.ifrance.com/la-dolce-vta.html la dolce vta] [http://busjavka.ifrance.com/hijo-de-la-luna/index.html hijo de la luna] [http://child-ofadot.ifrance.com/il-ballo-di-aureliano.html il ballo di aureliano mcr] [http://taylors-acolyte.ifrance.com/inno-tedesco.html inno tedesco] [http://fluffy-mind.ifrance.com/koda-video.html koda video] [http://listmishyk.ifrance.com/kellytrump/index.html kellytrump] [http://xxxenichkaa.ifrance.com/la-fiera-dll.html la fiera dll est] [http://plyuh-vios.ifrance.com/immagini-birra.html immagini birra] [http://taylors-acolyte.ifrance.com/io-nieves.html io nieves] [http://thecrownless.ifrance.com/i-stand-by-you/index.html i stand by you] [http://chasingspaces.ifrance.com/grande-mela-sona/index.html grande mela sona] [http://child-ofadot.ifrance.com/i-dubbi-dell-amore.html i dubbi dell amore fiorella mannoia] [http://risdimpuka.ifrance.com/luci-per-spettacolo/index.html luci per spettacolo musicale] [http://starcross33.ifrance.com/la-casetta-in-canada/index.html la casetta in canada] [http://snakeystil.ifrance.com/japan-sylvian/index.html japan sylvian] [http://plyuh-vios.ifrance.com/italo-calvino-marcovaldo.html italo calvino marcovaldo 1990] [http://carbonphoenix.ifrance.com/juve-it.html juve it] [http://taylors-acolyte.ifrance.com/infojardin.html infojardin] [http://cuivenarius.ifrance.com/hpdeskjet920c.html hpdeskjet920c] [http://xxxenichkaa.ifrance.com/la-canzone-di.html la canzone di natale] [http://thecrownless.ifrance.com/in-the-zone/index.html in the zone] [http://child-ofadot.ifrance.com/inzest.html inzest] [http://carbonphoenix.ifrance.com/jose-velez-vino-griego.html jose velez vino griego] [http://snakeystil.ifrance.com/jackson-browne/index.html jackson browne] [http://plyuh-vios.ifrance.com/il-parto-dele-nuvole.html il parto dele nuvole pesanti] [http://alexandraa80.ifrance.com/l-emozione-non/index.html l emozione non ha voce] [http://eliasn5gh.ifrance.com/las-tres-espias-sinlimite.html las tres espias sinlimite] [http://child-ofadot.ifrance.com/io1616.html io1616] [http://angeljazz711.ifrance.com/inno-israeliano.html inno israeliano] [http://angeljazz711.ifrance.com/indirizzi-in-francia.html indirizzi in francia] [http://alexandraa80.ifrance.com/la-historia-de/index.html la historia de la computadora] [http://chasingspaces.ifrance.com/hoy-di-gloria-estefan/index.html hoy di gloria estefan] [http://thecrownless.ifrance.com/isole-tremiti-mese-di/index.html isole tremiti mese di settembre] [http://chasingspaces.ifrance.com/horse-sex/index.html horse sex] [http://starcross33.ifrance.com/lucas-arna/index.html lucas arna] [http://snakeystil.ifrance.com/jarabe-del-palo/index.html jarabe del palo] [http://starcross33.ifrance.com/lady/index.html lady] [http://listmishyk.ifrance.com/komat-su-it/index.html komat su it] [http://alexandraa80.ifrance.com/le-luvre/index.html le luvre] [http://starcross33.ifrance.com/la-vita-e-bella/index.html la vita e bella di nicola piovani] [http://child-ofadot.ifrance.com/israel-iz-kamakawiwo.html israel iz kamakawiwo ole] [http://risdimpuka.ifrance.com/lunatica-greta/index.html lunatica greta] [http://risdimpuka.ifrance.com/la-ndrezzata/index.html la ndrezzata] [http://listmishyk.ifrance.com/kymco-rivenditori-milano/index.html kymco rivenditori milano] [http://listmishyk.ifrance.com/kris-groove/index.html kris groove] [http://listmishyk.ifrance.com/key-viaccess-2-3/index.html key viaccess 2 3] [http://busjavka.ifrance.com/hotel-gattopardo-a-brolo/index.html hotel gattopardo a brolo] [http://katzella.ifrance.com/iva-jerkovic/index.html iva jerkovic nuda] [http://pupsik1993.ifrance.com/lakatos.html lakatos] [http://eliasn5gh.ifrance.com/loops-reggaeton.html loops reggaeton gratis] [http://eliasn5gh.ifrance.com/la-guerra-di-piero-mp3.html la guerra di piero mp3] [http://busjavka.ifrance.com/hotelmediterraneo/index.html hotelmediterraneo] [http://chasingspaces.ifrance.com/horoskop/index.html horoskop] [http://oddonpurpose.ifrance.com/mskv-7.html mskv 7] [http://snakeystil.ifrance.com/joecassano/index.html joecassano] [http://listmishyk.ifrance.com/karaoke-breathe-easy/index.html karaoke breathe easy] [http://snakeystil.ifrance.com/jlo-photo/index.html jlo photo] [http://katzella.ifrance.com/http-luatinh-com/index.html http luatinh com] [http://child-ofadot.ifrance.com/ismail-yk.html ismail yk] [http://xxxenichkaa.ifrance.com/la-oreja-devangoh.html la oreja devangoh] [http://child-ofadot.ifrance.com/indaco-dagl-occhi-del.html indaco dagl occhi del cielo] [http://fluffy-mind.ifrance.com/kemer.html kemer] [http://listmishyk.ifrance.com/kazaa-media-deskop/index.html kazaa media deskop] [http://risdimpuka.ifrance.com/la-tua-immagine-dino/index.html la tua immagine dino] [http://carbonphoenix.ifrance.com/jimmi-villotti.html jimmi villotti] [http://oddonpurpose.ifrance.com/liviu-guta-feat.html liviu guta feat daniela gyorfy mp3] [http://oddonpurpose.ifrance.com/motori-di-riocerca.html motori di riocerca] [http://chasingspaces.ifrance.com/hard-gratuiti/index.html hard gratuiti] [http://katzella.ifrance.com/hip-hot/index.html hip hot] [http://eliasn5gh.ifrance.com/last-minut-sicilia.html last minut sicilia] [http://katzella.ifrance.com/italiachimami/index.html italiachimami] [http://listmishyk.ifrance.com/keating/index.html keating] [http://busjavka.ifrance.com/hotel-sul-mare-a/index.html hotel sul mare a capri] [http://snakeystil.ifrance.com/jhonny-hallyday/index.html jhonny hallyday] [http://chasingspaces.ifrance.com/hinh-ca-si-nguyen/index.html hinh ca si nguyen hong nhung khoa than] [http://taylors-acolyte.ifrance.com/ilaria-galassi.html ilaria galassi] [http://child-ofadot.ifrance.com/immagini-di-nani.html immagini di nani] [http://plyuh-vios.ifrance.com/if-you-still-belive.html if you still belive] [http://angeljazz711.ifrance.com/infrazione-stradale.html infrazione stradale] [http://listmishyk.ifrance.com/keneth/index.html keneth] [http://oddonpurpose.ifrance.com/museo-ceramiche-di.html museo ceramiche di faenza] [http://pupsik1993.ifrance.com/libro-21-livio.html libro 21 livio] [http://eliasn5gh.ifrance.com/letitia-casta-gallery.html letitia casta gallery] [http://oddonpurpose.ifrance.com/la-puntina.html la puntina] [http://katzella.ifrance.com/helly-holland/index.html helly holland] [http://pupsik1993.ifrance.com/le-canzoni-estate-2004.html le canzoni estate 2004] [http://alexandraa80.ifrance.com/leaving-new-yorc/index.html leaving new yorc] [http://child-ofadot.ifrance.com/integratori.html integratori] [http://eliasn5gh.ifrance.com/lucadamiano.html lucadamiano] [http://carbonphoenix.ifrance.com/john-cale.html john cale] [http://katzella.ifrance.com/hilltop-hoods/index.html hilltop hoods] [http://alexandraa80.ifrance.com/le-opere-di-munch/index.html le opere di munch] [http://alexandraa80.ifrance.com/laurabranigan-self/index.html laurabranigan self control] [http://risdimpuka.ifrance.com/love-2-see-you/index.html love 2 see you cry] [http://oddonpurpose.ifrance.com/lupin3.html lupin3] [http://alexandraa80.ifrance.com/leticia/index.html leticia] [http://plyuh-vios.ifrance.com/incontri-torino.html incontri torino] [http://carbonphoenix.ifrance.com/jeux-tf1.html jeux tf1] [http://busjavka.ifrance.com/hit-musicali-del-momento/index.html hit musicali del momento] [http://starcross33.ifrance.com/lionsleeps/index.html lionsleeps] [http://cuivenarius.ifrance.com/hop.html hop] [http://busjavka.ifrance.com/hat-dance/index.html hat dance] [http://listmishyk.ifrance.com/kingsat/index.html kingsat] [http://carbonphoenix.ifrance.com/jerk.html jerk] [http://pupsik1993.ifrance.com/lesbianl.html lesbianl] [http://fluffy-mind.ifrance.com/kidsnextdoor-com.html kidsnextdoor com] [http://thecrownless.ifrance.com/italianos/index.html italianos] [http://xxxenichkaa.ifrance.com/lorytrans.html lorytrans] [http://cuivenarius.ifrance.com/himno-nacional-mexicano.html himno nacional mexicano] [http://snakeystil.ifrance.com/jahre/index.html jahre] [http://katzella.ifrance.com/hit-my-hard/index.html hit my hard] [http://starcross33.ifrance.com/luigi-loperfido/index.html luigi loperfido] [http://starcross33.ifrance.com/les-apes/index.html les apes] [http://taylors-acolyte.ifrance.com/i-dont-wana-know-midi.html i dont wana know midi] [http://alexandraa80.ifrance.com/licenciada-tetarelli/index.html licenciada tetarelli] [http://oddonpurpose.ifrance.com/lyrices.html lyrices] [http://snakeystil.ifrance.com/jhon-barry/index.html jhon barry] {{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:53, 31 August 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)