XML/DOM serialization: Difference between revisions
< XML
Content added Content deleted
mNo edit summary |
(revert spam) |
||
Line 1: | Line 1: | ||
{{task}} |
|||
[http://akmokanzen.ifrance.com/images/small/panasonic-plasma.htm panasonic plasma tv] [http://oiyaoi.ifrance.com/images/small/offerte-lavoro/ offerte lavoro stlisti a lecce] [http://deviantrus.ifrance.com/topic/sbloccare-videofonini/ sbloccare videofonini tre] [http://highbulp.ifrance.com/images/small/chelsea-charm/ chelsea charm] [http://singaporepets.ifrance.com/library/html/palmare-navigatore.htm palmare navigatore ipaq] [http://singaporepets.ifrance.com/library/html/sms-gratis.htm sms gratis free] [http://yeeden.ifrance.com/img/styles/processore-intel/ processore intel 478] [http://voltia.ifrance.com/content/view/hurgada-hilton.htm hurgada hilton] [http://highbulp.ifrance.com/images/small/servant-orchestra/ servant orchestra video] [http://demurediablo.ifrance.com/library/html/volume-muscolare/ volume muscolare integratori] [http://voltia.ifrance.com/content/view/wallpaper-harry.htm wallpaper harry potter 10] [http://voltia.ifrance.com/content/view/roxette-ballad.htm roxette. ballad - p hits. the complete video collection] [http://yeeden.ifrance.com/img/styles/limosano/ limosano] [http://deviantrus.ifrance.com/topic/possibili-tracce/ possibili tracce] [http://toofarfrommaybe.ifrance.com/view/new/caratteri-ereditari/ caratteri ereditari] [http://yeeden.ifrance.com/img/styles/bad-boys/ bad boys ii] [http://highbulp.ifrance.com/images/small/movin-crusin/ movin crusin] [http://voltia.ifrance.com/content/view/candeejay.htm candeejay] [http://singaporepets.ifrance.com/library/html/web-cam.htm web cam gratis] [http://yeeden.ifrance.com/img/styles/mansioni-area/ mansioni area sicurezza aziendale] [http://yeeden.ifrance.com/img/styles/ofx/ ofx 560] [http://deviantrus.ifrance.com/topic/hyundai-hqpsr/ hyundai hqp421sr] [http://noxuhax.ifrance.com/content/view/ticket-one.htm ticket one] [http://toofarfrommaybe.ifrance.com/view/new/sex-pictures/ sex pictures] [http://deviantrus.ifrance.com/topic/alfa-romeo/ alfa romeo 156 1.6] [http://voltia.ifrance.com/content/view/tv-philips.htm tv philips 42 pollici al plasma] [http://girlwho-is.ifrance.com/img/styles/hp-psc.htm hp psc-1315] [http://lordsander.ifrance.com/topic/concorso-danza.htm concorso danza eugenio polyakov] [http://kalian42.ifrance.com/text/directory/camara-a/ camara a gas] [http://akmokanzen.ifrance.com/images/small/italia-it.htm italia1 it] [http://oiyaoi.ifrance.com/images/small/ophelie-winter/ ophelie winter] [http://tizolaa.ifrance.com/web/nordica-dobermann/ nordica dobermann] [http://akmokanzen.ifrance.com/images/small/philips-lcd.htm philips lcd tv] [http://yeeden.ifrance.com/img/styles/ljubav/ ljubav] [http://speedofsoun.ifrance.com/text/directory/marsh.htm marsh] [http://kalian42.ifrance.com/text/directory/scheda-madre/ scheda madre amd fsb 800 mhz] [http://akmokanzen.ifrance.com/images/small/gba-sp.htm gba sp accessori console] [http://tizolaa.ifrance.com/web/wwwagenziaentrate-it/ wwwagenziaentrate it] [http://yeeden.ifrance.com/img/styles/www-load/ www load a game it] [http://girlwho-is.ifrance.com/img/styles/miguel-enriquez.htm miguel enriquez maria morena] [http://akmokanzen.ifrance.com/images/small/streptococco.htm streptococco] [http://deviantrus.ifrance.com/topic/ufficio-forte/ ufficio forte dei marmo] [http://toofarfrommaybe.ifrance.com/view/new/ante-legno/ ante legno] [http://lordsander.ifrance.com/topic/piante-sempreverdi.htm piante sempreverdi] [http://girlwho-is.ifrance.com/img/styles/sea-monkeys.htm sea monkeys] [http://speedofsoun.ifrance.com/text/directory/maglie-ai.htm maglie ai ferri] [http://voltia.ifrance.com/content/view/cavo-s.htm cavo s video 10 mt] [http://singaporepets.ifrance.com/library/html/elenco-abbonati.htm elenco abbonati telecom internazionali] [http://igaros.ifrance.com/lib/indesit-wisl/ indesit wisl86] [http://tat-ooin.ifrance.com/resources/articles/inthe-shadows.htm inthe shadows] [http://voltia.ifrance.com/content/view/alta-stagione.htm alta stagione] [http://akmokanzen.ifrance.com/images/small/ultrabeat.htm ultrabeat] [http://broadwaylili.ifrance.com/content/view/durata-documento.htm durata documento di trasporto] [http://highbulp.ifrance.com/images/small/assicurazione-portogruaro/ assicurazione portogruaro] [http://tizolaa.ifrance.com/web/ati-radeon/ ati radeon 9800 pro all in wonder] [http://akmokanzen.ifrance.com/images/small/san-vito.htm san vito dei normanni] [http://lordsander.ifrance.com/topic/batterie-nokia.htm batterie nokia 6600] [http://jdawsona.ifrance.com/data/juventus-film/ juventus film dvd] [http://broadwaylili.ifrance.com/content/view/cruscotto-audi.htm cruscotto audi a3] [http://demurediablo.ifrance.com/library/html/matur/ matur] [http://speedofsoun.ifrance.com/text/directory/hana-melonova.htm hana melonova] [http://kalian42.ifrance.com/text/directory/sosia/ sosia] [http://highbulp.ifrance.com/images/small/drgon/ drgon] [http://akmokanzen.ifrance.com/images/small/one-more.htm one more night] [http://demurediablo.ifrance.com/library/html/wireless-compaq/ wireless compaq] [http://broadwaylili.ifrance.com/content/view/panorama-calendari.htm panorama calendari] [http://oiyaoi.ifrance.com/images/small/linkin-park/ linkin park numb] [http://jdawsona.ifrance.com/data/kiss-dvd/ kiss dvd 558] [http://highbulp.ifrance.com/images/small/hainan/ hainan] [http://speedofsoun.ifrance.com/text/directory/piosenka.htm piosenka] [http://noxuhax.ifrance.com/content/view/renato-zero.htm renato zero l equilibrista] [http://lordsander.ifrance.com/topic/progetto-.htm progetto diffusori dimensioni legno] [http://deviantrus.ifrance.com/topic/touareg-tdi/ touareg tdi r5] [http://lovereceier.ifrance.com/lib/comi-umberta.htm comi umberta bergamo] [http://akmokanzen.ifrance.com/images/small/pagine-bianche.htm pagine bianche padova] [http://yeeden.ifrance.com/img/styles/tv-sat/ tv sat usb] [http://lordsander.ifrance.com/topic/nitchevo.htm nitchevo] [http://jdawsona.ifrance.com/data/ucacaksin/ ucacaksin] [http://voltia.ifrance.com/content/view/midi-nuovi.htm midi nuovi] [http://tat-ooin.ifrance.com/resources/articles/cavasin.htm cavasin] [http://igaros.ifrance.com/lib/agriturismo-casalecchio/ agriturismo casalecchio di reno] [http://oiyaoi.ifrance.com/images/small/hotel-nevea/ hotel nevea] [http://tizolaa.ifrance.com/web/router-access/ router access point modem] [http://oiyaoi.ifrance.com/images/small/hector-lavoe/ hector lavoe] [http://noxuhax.ifrance.com/content/view/professione-giocattolo.htm professione... giocattolo] [http://oiyaoi.ifrance.com/images/small/ferraris-ferruccio/ ferraris ferruccio figli srl] [http://highbulp.ifrance.com/images/small/g-magazine/ g magazine] [http://voltia.ifrance.com/content/view/dibujo-en.htm dibujo en porno] [http://noxuhax.ifrance.com/content/view/www-sci.htm www sci] [http://demurediablo.ifrance.com/library/html/championship-manager/ championship manager 03 04 tips tricks t] [http://akmokanzen.ifrance.com/images/small/street-parade.htm street parade] [http://demurediablo.ifrance.com/library/html/istituto-oncologico/ istituto oncologico europeo milano] [http://deviantrus.ifrance.com/topic/scarica-she/ scarica she will be loved] [http://igaros.ifrance.com/lib/massala/ massala] [http://jdawsona.ifrance.com/data/toner-aculaser/ toner aculaser c1900] [http://igaros.ifrance.com/lib/poker-di/ poker di sangue] [http://highbulp.ifrance.com/images/small/processori-intel/ processori intel xeon 2 8 ghz 2 8] [http://oiyaoi.ifrance.com/images/small/driver-pentax/ driver pentax] [http://voltia.ifrance.com/content/view/bluetooth-handsfree.htm bluetooth handsfree] [http://speedofsoun.ifrance.com/text/directory/decapitato-usa.htm decapitato usa] [http://highbulp.ifrance.com/images/small/hotel-maxivillage/ hotel maxivillage sinai garden sharm] [http://oiyaoi.ifrance.com/images/small/www-cr/ www cr decorazioni com] [http://lordsander.ifrance.com/topic/batteria-per.htm batteria per videocamera panasonic] [http://noxuhax.ifrance.com/content/view/jolly-hotel.htm jolly hotel roma] [http://tat-ooin.ifrance.com/resources/articles/cartier-must.htm cartier must] [http://girlwho-is.ifrance.com/img/styles/bobbit.htm bobbit] [http://girlwho-is.ifrance.com/img/styles/colorare.htm colorare] [http://lordsander.ifrance.com/topic/satkeys.htm satkeys] [http://singaporepets.ifrance.com/library/html/officinale.htm officinale] [http://noxuhax.ifrance.com/content/view/chiles-com.htm chiles com mx] [http://lordsander.ifrance.com/topic/codice-d.htm codice d istallazione di the sims2] [http://jdawsona.ifrance.com/data/tv-lcd/ tv lcd 22] [http://yeeden.ifrance.com/img/styles/stefano-benni/ stefano benni] [http://lordsander.ifrance.com/topic/fano-contatto.htm fano contatto] [http://oiyaoi.ifrance.com/images/small/fujiko/ fujiko] [http://demurediablo.ifrance.com/library/html/proton-metal/ proton metal mr12] [http://oiyaoi.ifrance.com/images/small/router-/ router 4 porte] [http://yeeden.ifrance.com/img/styles/notebook-thoshiba/ notebook thoshiba] [http://speedofsoun.ifrance.com/text/directory/ericsson-hbh.htm ericsson hbh 602] [http://girlwho-is.ifrance.com/img/styles/marani.htm marani] [http://highbulp.ifrance.com/images/small/friends-anno/ friends anno 4 episodi 24] [http://singaporepets.ifrance.com/library/html/la-famiglia.htm la famiglia per freud] [http://lovereceier.ifrance.com/lib/kitty.htm kitty] [http://singaporepets.ifrance.com/library/html/roberto-cecchini.htm roberto cecchini] [http://oiyaoi.ifrance.com/images/small/mia-martini/ mia martini bolero] [http://igaros.ifrance.com/lib/web-tv/ web tv] [http://noxuhax.ifrance.com/content/view/bandiere-araldiche.htm bandiere araldiche] [http://oiyaoi.ifrance.com/images/small/albergo-alassio/ albergo alassio] [http://akmokanzen.ifrance.com/images/small/sony-dsc.htm sony dsc p93a] [http://demurediablo.ifrance.com/library/html/video-lettore/ video lettore dvd divx portatile con tv] [http://tizolaa.ifrance.com/web/casino-tressure/ casino tressure] [http://tat-ooin.ifrance.com/resources/articles/herceptin-iv.htm herceptin iv 1 fl 150 mg] [http://deviantrus.ifrance.com/topic/vita-di/ vita di ghandi] [http://singaporepets.ifrance.com/library/html/navigazione-satellitare.htm navigazione satellitare] [http://tat-ooin.ifrance.com/resources/articles/lavori-sessuali.htm lavori sessuali] [http://highbulp.ifrance.com/images/small/tripla-corona/ tripla corona] [http://kalian42.ifrance.com/text/directory/mp-innovix/ mp3 innovix] [http://broadwaylili.ifrance.com/content/view/preteen.htm preteen] [http://toofarfrommaybe.ifrance.com/view/new/denis-verdini/ denis verdini] [http://speedofsoun.ifrance.com/text/directory/esposizioni-lugano.htm esposizioni lugano] [http://voltia.ifrance.com/content/view/affitto-ufficio.htm affitto ufficio aquila] [http://deviantrus.ifrance.com/topic/correggio/ correggio] [http://voltia.ifrance.com/content/view/toshiba-satellite.htm toshiba satellite m40x 122] [http://tat-ooin.ifrance.com/resources/articles/latino.htm latino 9] [http://broadwaylili.ifrance.com/content/view/agroalimentare.htm agroalimentare] [http://girlwho-is.ifrance.com/img/styles/jvc-thar.htm jvc th-a75r] [http://kalian42.ifrance.com/text/directory/burn-this/ burn this house] [http://broadwaylili.ifrance.com/content/view/hyry-antti.htm hyry, antti] [http://lovereceier.ifrance.com/lib/assicurazione-mantova.htm assicurazione mantova] [http://tizolaa.ifrance.com/web/altalene-chicco/ altalene chicco] [http://kalian42.ifrance.com/text/directory/linfodrenaggio-vodder/ linfodrenaggio vodder] [http://toofarfrommaybe.ifrance.com/view/new/prezzi-della/ prezzi della fiat 1500] [http://deviantrus.ifrance.com/topic/costantino-vitaliano/ costantino vitaliano la scelta] [http://tat-ooin.ifrance.com/resources/articles/la-vera.htm la vera storia di eva peron] [http://highbulp.ifrance.com/images/small/gprs-portatile/ gprs portatile] [http://highbulp.ifrance.com/images/small/dj-musica/ dj musica discoteca house] [http://highbulp.ifrance.com/images/small/decapitazioni-americane/ decapitazioni americane il video] [http://broadwaylili.ifrance.com/content/view/monitor-lg.htm monitor lg 19 lcd tv l193st] [http://lovereceier.ifrance.com/lib/itinerari-turistici.htm itinerari turistici sul lago di garda] [http://tat-ooin.ifrance.com/resources/articles/dlink-dkvmk.htm d-link dkvm-2k] [http://lordsander.ifrance.com/topic/condizionatore.htm condizionatore 9000] [http://toofarfrommaybe.ifrance.com/view/new/fuori-dal/ fuori dal] [http://voltia.ifrance.com/content/view/ordinary.htm ordinary] [http://lovereceier.ifrance.com/lib/lettore-mp.htm lettore mp3 samsung 5gb] [http://jdawsona.ifrance.com/data/techno/ techno 2005] [http://igaros.ifrance.com/lib/videoproiettore-dlp/ videoproiettore dlp 2000 ansi lumen] [http://akmokanzen.ifrance.com/images/small/scot-it.htm scot it scotland] [http://jdawsona.ifrance.com/data/sesso-donne/ sesso donne con cavalli] [http://demurediablo.ifrance.com/library/html/colesterolo-dieta/ colesterolo dieta] [http://tat-ooin.ifrance.com/resources/articles/casse-accessori.htm casse accessori philips audio video] [http://yeeden.ifrance.com/img/styles/de-la/ de la motte] [http://kalian42.ifrance.com/text/directory/filmer-sir/ filmer, sir robert] [http://oiyaoi.ifrance.com/images/small/kareen-antonn/ kareen antonn bonnie tyler si] [http://demurediablo.ifrance.com/library/html/normeinrete/ normeinrete] [http://demurediablo.ifrance.com/library/html/lambrugo/ lambrugo] [http://voltia.ifrance.com/content/view/si-quaeris.htm si quaeris] [http://demurediablo.ifrance.com/library/html/silvi-marina/ silvi marina albergo] [http://singaporepets.ifrance.com/library/html/notre-dame.htm notre dame de paris dvd] [http://kalian42.ifrance.com/text/directory/windows-/ windows 2000 programma] [http://oiyaoi.ifrance.com/images/small/tv-lcd/ tv lcd 5] [http://deviantrus.ifrance.com/topic/lg-microonde/ lg microonde inox] [http://speedofsoun.ifrance.com/text/directory/lcd.htm lcd 1366] [http://akmokanzen.ifrance.com/images/small/giovani-promesse.htm giovani promesse] [http://voltia.ifrance.com/content/view/melissa-b.htm melissa b] [http://highbulp.ifrance.com/images/small/umbria/ umbria] [http://lovereceier.ifrance.com/lib/paris-latino.htm paris latino] [http://singaporepets.ifrance.com/library/html/cuneo-mappa.htm cuneo mappa] [http://tat-ooin.ifrance.com/resources/articles/concierto-de.htm concierto de aranjuez] [http://lordsander.ifrance.com/topic/fuochi-artificiali.htm fuochi artificiali] [http://singaporepets.ifrance.com/library/html/martina-franca.htm martina franca prodotti] [http://oiyaoi.ifrance.com/images/small/tesi-in/ tesi in ostetricia] [http://broadwaylili.ifrance.com/content/view/materiale-elettrico.htm materiale elettrico catania] [http://yeeden.ifrance.com/img/styles/bompiani-valentino/ bompiani, valentino] [http://lordsander.ifrance.com/topic/cassa-foster.htm cassa foster] [http://kalian42.ifrance.com/text/directory/www-sean/ www sean poul it] [http://speedofsoun.ifrance.com/text/directory/www-catullo.htm www catullo it] [http://girlwho-is.ifrance.com/img/styles/il-cardinale.htm il cardinale richelieu] [http://noxuhax.ifrance.com/content/view/ultras-salernitana.htm ultras salernitana] [http://tat-ooin.ifrance.com/resources/articles/hard-disk.htm hard disk 400 gb windows xp] [http://highbulp.ifrance.com/images/small/batteria-travelmate/ batteria travelmate 230] {{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:08, 19 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)