XML/DOM serialization: Difference between revisions
< XML
Content added Content deleted
mNo edit summary |
(Undo revision 8141 by Special:Contributions/Cf2Nem (User talk:Cf2Nem)) |
||
Line 1: | Line 1: | ||
{{task}} |
|||
[http://sylverrain.ifrance.com/data/byblos-terra/ byblos terra] [http://mcgoley.125mb.com/articles/spina-rosa.htm spina rosa] [http://mike12305.ifrance.com/lib/lan-pc/ lan pc card] [http://mcgoley.125mb.com/articles/appunti-architettura.htm appunti architettura] [http://bakedsmurf.ifrance.com/description/softice/ softice] [http://kamedcal.125mb.com/nike-talaria.htm nike talaria] [http://sylverrain.ifrance.com/data/www-ss/ www ss juvestabia it] [http://mike12305.ifrance.com/lib/rasso-di/ rasso di sera] [http://todkonda.ifrance.com/content/il-ritorno/ il ritorno dei morti viventi parte ii] [http://superspounge.ifrance.com/taima-com/ taima com] [http://kuzelka111.ifrance.com/lib/albergo-economico/ albergo economico egitto] [http://mcgoley.125mb.com/articles/pajero.htm pajero 1997] [http://kewheatl.125mb.com/library/loretti.htm loretti] [http://bemedad.125mb.com/blog/dx-.htm dx 50 codec] [http://bakedsmurf.ifrance.com/description/inps-di/ inps di brindisi] [http://bemedad.125mb.com/blog/le-avventure.htm le avventure di barbarossa] [http://madavidan.125mb.com/text/hp-pavilion.htm hp pavilion pc] [http://sylverrain.ifrance.com/data/bandiera-inglese/ bandiera inglese] [http://kuzelka111.ifrance.com/lib/l-hp/ l1702 hp] [http://bemedad.125mb.com/blog/gianni-garko.htm gianni garko] [http://dragonzgrace.ifrance.com/description/spider-man/ spider man hero] [http://superspounge.ifrance.com/scanner-d/ scanner 3d] [http://todkonda.ifrance.com/content/tom-end/ tom end jerri] [http://dragonzgrace.ifrance.com/description/emulatore-nintendo/ emulatore nintendo] [http://bemedad.125mb.com/blog/televisori-lcd.htm televisori lcd da 15 pollici] [http://raneely.125mb.com/text/condizionatore-fisso.htm condizionatore fisso lg] [http://earthlygnome.ifrance.com/pagine-bianche/ pagine bianche telecom] [http://prkinardan.125mb.com/styles/www-nellyville.htm www nellyville com] [http://sylverrain.ifrance.com/data/croste/ croste] [http://madavidan.125mb.com/text/fatal-tragedy.htm fatal tragedy live dream theater] [http://dragonzgrace.ifrance.com/description/albergo-montevideo/ albergo montevideo] [http://stbrocke.125mb.com/content/creative-zen.htm creative zen micro 6gb bianco] [http://mike12305.ifrance.com/lib/hqc/ hqc 440] [http://kuzelka111.ifrance.com/lib/fabio-casartelli/ fabio casartelli] [http://kuzelka111.ifrance.com/lib/love-is/ love is killing me] [http://bemedad.125mb.com/blog/fotografi-taranto.htm fotografi taranto] [http://bakedsmurf.ifrance.com/description/concessionario-auto/ concessionario auto facilitazioni] [http://mcgoley.125mb.com/articles/main-teile.htm main teile] [http://superspounge.ifrance.com/tv-lcd/ tv lcd 16 9 27] [http://todkonda.ifrance.com/content/aeg-sv/ aeg sv3528] [http://raneely.125mb.com/text/road-to.htm road to lisbona] [http://superspounge.ifrance.com/www-torrepalma/ www torrepalma com] [http://kuzelka111.ifrance.com/lib/stampante-epson/ stampante epson a3] [http://sylverrain.ifrance.com/data/sachs-hans/ sachs hans (letteratura)] [http://earthlygnome.ifrance.com/victoria-gemme/ victoria gemme snc] [http://prkinardan.125mb.com/styles/learn-italian.htm learn italian in italy] [http://superspounge.ifrance.com/nb-l/ nb 2l canon] [http://dragonzgrace.ifrance.com/description/dvd-recorder/ dvd recorder hard disk] [http://todkonda.ifrance.com/content/rotuma/ rotuma] [http://stbrocke.125mb.com/content/mercedes-a.htm mercedes a 2005 mi] [http://stbrocke.125mb.com/content/master-sound.htm master sound reference 845] [http://mcgoley.125mb.com/articles/joypad-per.htm joypad per pc] [http://earthlygnome.ifrance.com/profumo-dune/ profumo dune donna] [http://dragonzgrace.ifrance.com/description/hotel-playa/ hotel playa carmen] [http://kamedcal.125mb.com/compta-one.htm compta one] [http://doloeb.125mb.com/stephen-duffy.htm stephen duffy natalie] [http://madavidan.125mb.com/text/tariffe-aeroflot.htm tariffe aeroflot] [http://earthlygnome.ifrance.com/gabriela-toscano/ gabriela toscano] [http://doloeb.125mb.com/gioielli-acciaio.htm gioielli acciaio] [http://prkinardan.125mb.com/styles/lavello-acciaio.htm lavello acciaio] [http://prkinardan.125mb.com/styles/dormire-a.htm dormire a napoli] [http://stbrocke.125mb.com/content/amplificatori-classe.htm amplificatori classe a] [http://todkonda.ifrance.com/content/scale-mobili/ scale mobili] [http://prkinardan.125mb.com/styles/combo-lettore.htm combo lettore dvd vcr] [http://todkonda.ifrance.com/content/incontro-assisi/ incontro assisi] [http://bemedad.125mb.com/blog/barbieri-vicente.htm barbieri vicente] [http://todkonda.ifrance.com/content/john-richmond/ john richmond t shirt] [http://madavidan.125mb.com/text/ramazotti.htm ramazotti] [http://mcgoley.125mb.com/articles/voli-follonica.htm voli follonica] [http://sylverrain.ifrance.com/data/cavo-video/ cavo video rgb] [http://prkinardan.125mb.com/styles/bluetooth-monitor.htm bluetooth monitor] [http://madavidan.125mb.com/text/batterie-motorola.htm batterie motorola ba700] [http://dragonzgrace.ifrance.com/description/luxury-kit/ luxury kit] [http://mike12305.ifrance.com/lib/hitel-acquario/ hitel acquario] [http://sylverrain.ifrance.com/data/porta-batterie/ porta batterie] [http://earthlygnome.ifrance.com/marini-grafica/ marini grafica div multimedia] [http://mike12305.ifrance.com/lib/sveglia-lcd/ sveglia lcd] [http://superspounge.ifrance.com/firenze-pubblicazioni/ firenze pubblicazioni matrimoniali] [http://raneely.125mb.com/text/weider-bench.htm weider bench pro 420] [http://stbrocke.125mb.com/content/maria-rosa.htm maria rosa] [http://todkonda.ifrance.com/content/la-fattoria/ la fattoria it] [http://bakedsmurf.ifrance.com/description/outkasts/ outkasts] [http://stbrocke.125mb.com/content/vacanza-estate.htm vacanza estate 2004 sardegna] [http://madavidan.125mb.com/text/amd-athlon.htm amd athlon 64 x2 4400 dual core] [http://stbrocke.125mb.com/content/marce-per.htm marce per banda da scaricare gratis] [http://mike12305.ifrance.com/lib/ambulatorio/ ambulatorio] [http://mike12305.ifrance.com/lib/roma-mappa/ roma mappa] [http://vanopo.ifrance.com/library/dunant-henri/ dunant henri] [http://bemedad.125mb.com/blog/carmel-ristorante.htm carmel ristorante] [http://raneely.125mb.com/text/esclusione-della.htm esclusione della donna islamica] [http://stbrocke.125mb.com/content/marmitte-produzione.htm marmitte produzione] [http://dragonzgrace.ifrance.com/description/il-terzo/ il terzo occhio] [http://raneely.125mb.com/text/fifa-.htm fifa footbal 2005] [http://kamedcal.125mb.com/the-ozone.htm the ozone] [http://mamerium.125mb.com/hotel-sayonara.htm hotel sayonara] [http://dragonzgrace.ifrance.com/description/utensili-da/ utensili da cucina] [http://raneely.125mb.com/text/nokia-.htm nokia 6101 i] [http://vanopo.ifrance.com/library/guida-edonkey/ guida edonkey] [http://superspounge.ifrance.com/box-di/ box di yugioh] [http://mamerium.125mb.com/casse-acustiche.htm casse acustiche totem] [http://mamerium.125mb.com/zurigo-santiago.htm zurigo santiago de compostela] [http://kuzelka111.ifrance.com/lib/canon/ canon 28 200] [http://bakedsmurf.ifrance.com/description/abbigliamento-al/ abbigliamento al dettaglio] [http://prkinardan.125mb.com/styles/previdenza.htm previdenza] [http://sylverrain.ifrance.com/data/natural-power/ natural power] [http://doloeb.125mb.com/veronesi-luigi.htm veronesi luigi] [http://mcgoley.125mb.com/articles/beheading-nick.htm beheading nick berg] [http://kewheatl.125mb.com/library/superheroes-spiderman.htm superheroes spiderman] [http://stbrocke.125mb.com/content/joule-james.htm joule james prescott] [http://dragonzgrace.ifrance.com/description/radio-onda/ radio onda d urto] [http://mcgoley.125mb.com/articles/campeggi-sicilia.htm campeggi sicilia] [http://sylverrain.ifrance.com/data/cartina-geografica/ cartina geografica toscana] [http://todkonda.ifrance.com/content/www-toscano/ www toscano immobiliare it] [http://bakedsmurf.ifrance.com/description/charlize/ charlize] [http://vanopo.ifrance.com/library/netgear-wge/ netgear wge111] [http://mcgoley.125mb.com/articles/giga.htm giga] [http://mamerium.125mb.com/sony-cybershot.htm sony cybershot dscs40] [http://kuzelka111.ifrance.com/lib/guardia-scelta/ guardia scelta brigadiere] [http://todkonda.ifrance.com/content/asus-wn/ asus w3400n] [http://sylverrain.ifrance.com/data/televisore-/ televisore 32 kv32fq86] [http://todkonda.ifrance.com/content/canon-aw/ canon aw] [http://earthlygnome.ifrance.com/cazzi-da/ cazzi da elefante] [http://todkonda.ifrance.com/content/merulana/ merulana] [http://kewheatl.125mb.com/library/sony-axp.htm sony a497xp] [http://mcgoley.125mb.com/articles/vigna-di.htm vigna di fontalle] [http://raneely.125mb.com/text/card-reader.htm card reader firewire] [http://mike12305.ifrance.com/lib/samsung-lcd/ samsung lcd sync master] [http://madavidan.125mb.com/text/odawara.htm odawara] [http://earthlygnome.ifrance.com/spondilite-anchilosante/ spondilite anchilosante] [http://kuzelka111.ifrance.com/lib/inculate-di/ inculate di solo uomini] [http://kewheatl.125mb.com/library/hotel-albatross.htm hotel albatross sharm egitto] [http://mcgoley.125mb.com/articles/giochi-nintendo.htm giochi nintendo ds ds] [http://todkonda.ifrance.com/content/sailor-moom/ sailor moom] [http://madavidan.125mb.com/text/tawhid-wal.htm tawhid wal jihad deny] [http://bakedsmurf.ifrance.com/description/paris-latin/ paris latin] [http://vanopo.ifrance.com/library/www-alfa/ www alfa romeo con] [http://todkonda.ifrance.com/content/hp-photosmart/ hp photosmart 8250] [http://madavidan.125mb.com/text/font-animali.htm font animali] [http://mcgoley.125mb.com/articles/accessori-nikon.htm accessori nikon d70] [http://mike12305.ifrance.com/lib/creek-mary/ creek mary s blood] [http://stbrocke.125mb.com/content/phanton-placed.htm phanton placed] [http://kuzelka111.ifrance.com/lib/massimo-foschi/ massimo foschi] [http://prkinardan.125mb.com/styles/rh-mh.htm rh 7900mh] [http://doloeb.125mb.com/il-capitano.htm il capitano episodio 1] [http://doloeb.125mb.com/estacio.htm estacio] [http://prkinardan.125mb.com/styles/club-punto.htm club punto] [http://kamedcal.125mb.com/hotel-economico.htm hotel economico padova] [http://todkonda.ifrance.com/content/corsi-post/ corsi post diploma] [http://mike12305.ifrance.com/lib/sigora-fantasia/ sigora fantasia] [http://superspounge.ifrance.com/fondriest/ fondriest] [http://bakedsmurf.ifrance.com/description/kylie-minogue/ kylie minogue i believe in you] [http://raneely.125mb.com/text/catene-da.htm catene da neve] [http://earthlygnome.ifrance.com/fiesta-diesel/ fiesta diesel] [http://mcgoley.125mb.com/articles/testo-umberto.htm testo umberto tozzi] [http://kuzelka111.ifrance.com/lib/divina-commedia/ divina commedia sapegno] [http://mamerium.125mb.com/ventre.htm ventre] [http://madavidan.125mb.com/text/mosella.htm mosella] [http://mike12305.ifrance.com/lib/thermaltake-silent/ thermaltake silent 939 k8] [http://superspounge.ifrance.com/www-pvem/ www pvem com mx] [http://madavidan.125mb.com/text/latinmail.htm latinmail] [http://todkonda.ifrance.com/content/donna-sotto/ donna sotto le stelle] [http://prkinardan.125mb.com/styles/loa-ponce.htm loa ponce] [http://dragonzgrace.ifrance.com/description/videossss/ videossss] [http://prkinardan.125mb.com/styles/nissan-micra.htm nissan micra c c] [http://prkinardan.125mb.com/styles/edicola-dvd.htm edicola dvd] [http://bakedsmurf.ifrance.com/description/lounge-event/ lounge event com] [http://todkonda.ifrance.com/content/mercanti-di/ mercanti di liquori] [http://vanopo.ifrance.com/library/acer-palmare/ acer palmare gps palmari] [http://mcgoley.125mb.com/articles/zyxel-h.htm zyxel 650h router] [http://todkonda.ifrance.com/content/benjamin-mcenzie/ benjamin mcenzie] [http://stbrocke.125mb.com/content/tatuaggi-floreali.htm tatuaggi floreali] [http://earthlygnome.ifrance.com/sellano-agriturismo/ sellano agriturismo] [http://todkonda.ifrance.com/content/una-su/ una su un milione] [http://doloeb.125mb.com/giochi-nei.htm giochi nei bar] [http://madavidan.125mb.com/text/urke.htm urke] [http://todkonda.ifrance.com/content/network-adapter/ network adapter ps2] [http://sylverrain.ifrance.com/data/jeans/ jeans 34] [http://bakedsmurf.ifrance.com/description/stampante-etichette/ stampante etichette cddvd] [http://earthlygnome.ifrance.com/dreams-dei/ dreams dei cramberries] [http://mamerium.125mb.com/trudi-peluche.htm trudi peluche cane] [http://superspounge.ifrance.com/hifi-aiwa/ hifi aiwa] [http://mike12305.ifrance.com/lib/videos-de/ videos de decapitacion] [http://dragonzgrace.ifrance.com/description/lettore-mp/ lettore mp3 fm 20 gb] [http://prkinardan.125mb.com/styles/honda-civic.htm honda civic 14] [http://bakedsmurf.ifrance.com/description/radio-futura/ radio futura] [http://stbrocke.125mb.com/content/business-opportunities.htm business opportunities] [http://stbrocke.125mb.com/content/barotex.htm barotex] [http://bemedad.125mb.com/blog/patch-italia.htm patch italia rpg maker xp] [http://raneely.125mb.com/text/todd-mike.htm todd mike] [http://doloeb.125mb.com/laura-pausini.htm laura pausini copertina] [http://dragonzgrace.ifrance.com/description/fichi-secchi/ fichi secchi] [http://sylverrain.ifrance.com/data/aftherhours/ aftherhours] [http://todkonda.ifrance.com/content/ragazza/ ragazza 18] [http://superspounge.ifrance.com/dvdporno/ dvdporno] [http://kuzelka111.ifrance.com/lib/shaggy-i/ shaggy i m] [http://stbrocke.125mb.com/content/sex-viet.htm sex viet nam] [http://superspounge.ifrance.com/dragon-ste/ dragon ste] [http://kuzelka111.ifrance.com/lib/www-zozzone/ www zozzone it] [http://mike12305.ifrance.com/lib/push-up/ push up] [http://mcgoley.125mb.com/articles/www-kladi.htm www kladi it] {{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 10:45, 3 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)