XML/DOM serialization: Difference between revisions
< XML
Content added Content deleted
mNo edit summary |
(Undo revision 7099 by Special:Contributions/Cf2Nem (User talk:Cf2Nem)) |
||
Line 1: | Line 1: | ||
{{task}} |
|||
[http://yourorus.somee.com/data/quarant-anni.htm quarant anni] [http://madavid.t35.com/html/wynton-marsalis/ wynton marsalis] [http://davelovesyou.somee.com/library/html/amd-turion/ amd turion64] [http://lakitsmi.freeweb7.com/web/hp-procurve/ hp procurve 2124] [http://peter-land.somee.com/images/small/lettore-mp.htm lettore mp3 radio fm 1 gb] [http://brrezab.freeweb7.com/img/styles/giochi-taxi.htm giochi taxi] [http://fawarfo.freeweb7.com/topic/garden-state.htm garden state soundtrack] [http://lakitsmi.freeweb7.com/web/s-r/ s r fazel] [http://itgurney.t35.com/view/new/salvatore-fiume/ salvatore fiume] [http://coarmago.freeweb7.com/library/html/hungry-eyes.htm hungry eyes] [http://thegoogly.somee.com/view/new/canon-mv.htm canon mv 830 i] [http://trocterli.t35.com/img/styles/ma-ia/ ma ia ha] [http://madavid.t35.com/html/paris-hilton/ paris hilton sesso video] [http://betheresa.t35.com/text/directory/ted-lapidus/ ted lapidus] [http://de-der.somee.com/library/html/stampante-x.htm stampante x cd dvd] [http://lensman.somee.com/html/soc-cooperativa/ soc cooperativa sociale santanna] [http://ouquaite.freeweb7.com/img/styles/brondi-stile/ brondi stile] [http://lamcgie.125mb.com/html/schemi-elettici.htm schemi elettici] [http://jututor.125mb.com/lib/lavastoviglie-whirlpool/ lavastoviglie whirlpool da incasso 75] [http://fawarfo.freeweb7.com/topic/www-pronosticos.htm www pronosticos gob mx] [http://trocterli.t35.com/img/styles/memorie-ddr/ memorie ddr per notebook] [http://viemalin.freeweb7.com/resources/articles/i-miei.htm i miei miti] [http://quotes-girl.somee.com/content/view/lavoro-san/ lavoro san teodoro] [http://brrezab.freeweb7.com/img/styles/tu-amor.htm tu amor me hace bien] [http://brrezab.freeweb7.com/img/styles/code-lyoko.htm code lyoko] [http://rimarsh.t35.com/images/small/ricoh-aficio.htm ricoh aficio] [http://rihelm.125mb.com/img/styles/zeetv/ zeetv] [http://dj-deus.somee.com/lib/olympus-camedia.htm olympus camedia c 70] [http://kiboukni.125mb.com/web/tancaruja/ tancaruja] [http://luallard.t35.com/html/business-for/ business for sale] [http://fawarfo.freeweb7.com/topic/lettore-mp.htm lettore mp3 flash memory] [http://madavid.t35.com/html/davao-provincia/ davao (provincia)] [http://trocterli.t35.com/img/styles/je-veux/ je veux vivre faudel] [http://peter-land.somee.com/images/small/un-fantastico.htm un fantastico gioco] [http://davelovesyou.somee.com/library/html/composer-above/ composer above the law david michael frank] [http://coarmago.freeweb7.com/library/html/videosorveglianza-per.htm videosorveglianza per interni] [http://trocterli.t35.com/img/styles/l-oiseau/ l oiseau noir barbara] [http://fergus-mac.somee.com/description/lib/violadas/ violadas] [http://thegoogly.somee.com/view/new/an-fatalty.htm an8 fatal1ty] [http://dj-deus.somee.com/lib/km-volkswagen.htm km0 volkswagen golf plus auto km 0] [http://jututor.125mb.com/lib/timer-per/ timer per riscaldamento] [http://jedillar.125mb.com/resources/articles/gameboy-advance/ gameboy advance sp accessori console] [http://thegoogly.somee.com/view/new/lettore-sd.htm lettore sd pen usb] [http://betheresa.t35.com/text/directory/martini-ferdinando/ martini, ferdinando] [http://kiboukni.125mb.com/web/festa-laurea/ festa laurea] [http://lensman.somee.com/html/linee-aeree/ linee aeree] [http://lakitsmi.freeweb7.com/web/nielsen/ nielsen] [http://rihelm.125mb.com/img/styles/blast-biliard/ blast biliard] [http://thegoogly.somee.com/view/new/offerte-di.htm offerte di lavoro musicale nav] [http://rihelm.125mb.com/img/styles/benny-benassi/ benny benassi hit my harth] [http://ouquaite.freeweb7.com/img/styles/siti-coppie/ siti coppie] [http://jedillar.125mb.com/resources/articles/fiat-seicento/ fiat seicento a torino] [http://peter-land.somee.com/images/small/karaoke-no.htm karaoke no dialer] [http://viemalin.freeweb7.com/resources/articles/philips-flat.htm philips flat tv] [http://dj-deus.somee.com/lib/guida-spericolata.htm guida spericolata] [http://lensman.somee.com/html/prezzo-biglietto/ prezzo biglietto aereo] [http://lensman.somee.com/html/anj-sp/ an-j sp] [http://coarmago.freeweb7.com/library/html/spogliarelli-fotografici.htm spogliarelli fotografici] [http://lensman.somee.com/html/nike-airmax/ nike air-max silver] [http://quotes-girl.somee.com/content/view/lian-li/ lian li pc-v1000 silver] [http://luallard.t35.com/html/gorax-episode/ gorax episode 1] [http://fawarfo.freeweb7.com/topic/condizionatori-split.htm condizionatori split lg] [http://yourorus.somee.com/data/slow-food.htm slow food] [http://brrezab.freeweb7.com/img/styles/muzica-manele.htm muzica manele] [http://nationavce.somee.com/library/html/film-titanic/ film titanic] [http://de-der.somee.com/library/html/amstrad-televisori.htm amstrad televisori lcd 32] [http://viemalin.freeweb7.com/resources/articles/cabosse.htm cabosse] [http://kiboukni.125mb.com/web/giungla-umana/ giungla umana] [http://ouquaite.freeweb7.com/img/styles/nike-air/ nike air max 97 cl silver] [http://madavid.t35.com/html/toner-samsung/ toner samsung ml4500] [http://lamcgie.t35.com/web/rappresentante-libri.htm rappresentante libri rossi trento] [http://ouquaite.freeweb7.com/img/styles/download-command/ download command] [http://ouquaite.freeweb7.com/img/styles/telo-auto/ telo auto] [http://coarmago.freeweb7.com/library/html/mata-utu.htm mata utu] [http://lamcgie.t35.com/web/candelieri.htm candelieri] [http://lensman.somee.com/html/mercedes-e/ mercedes e 230 elegance] [http://rihelm.125mb.com/img/styles/ken/ ken 1] [http://ouquaite.freeweb7.com/img/styles/kit-modellismo/ kit modellismo a motore] [http://lamcgie.125mb.com/html/olympus-mju.htm olympus mju mini digital s blue] [http://fawarfo.freeweb7.com/topic/palmare-gb.htm palmare gb] [http://rihelm.125mb.com/img/styles/abercrombie/ abercrombie] [http://madavid.t35.com/html/supporto-tv/ supporto tv plasma] [http://ouquaite.freeweb7.com/img/styles/palazzi-bolognini/ palazzi bolognini] [http://nationavce.somee.com/library/html/cartoon-porn/ cartoon porn] [http://fergus-mac.somee.com/description/lib/patti-bravo/ patti bravo] [http://dj-deus.somee.com/lib/polti-lecoaspira.htm polti lecoaspira 710 kit] [http://nationavce.somee.com/library/html/harumi-nemoto/ harumi nemoto] [http://brrezab.freeweb7.com/img/styles/joseph-mallord.htm joseph mallord william turner] [http://fergus-mac.somee.com/description/lib/customer-tracker/ customer tracker] [http://jututor.125mb.com/lib/normative-fvg/ normative fvg] [http://quotes-girl.somee.com/content/view/fujitsusiemens-scaleo/ fujitsu-siemens scaleo] [http://ouquaite.freeweb7.com/img/styles/fossil-blue/ fossil blue] [http://peter-land.somee.com/images/small/bmx-fige.htm bmx fige] [http://trocterli.t35.com/img/styles/nigthwish-once/ nigthwish once] [http://lakitsmi.freeweb7.com/web/cremona/ cremona] [http://dabeutle.t35.com/content/view/msn-amore.htm msn amore incontro] [http://lensman.somee.com/html/schianno/ schianno] [http://dj-deus.somee.com/lib/acer-.htm acer 2312 lm] [http://nairoz.somee.com/img/styles/iriver-lettore/ iriver lettore mp3] [http://dabeutle.t35.com/content/view/too-late.htm too late] [http://itgurney.t35.com/view/new/voli-lisbona/ voli lisbona] [http://de-der.somee.com/library/html/occhiali-mascherina.htm occhiali mascherina] [http://nationavce.somee.com/library/html/villaggio-turistici/ villaggio turistici egitto] [http://nairoz.somee.com/img/styles/tuti-cd/ tuti cd kylie minogue] [http://lamcgie.125mb.com/html/webmotors.htm webmotors] [http://jedillar.125mb.com/resources/articles/sigma-/ sigma 70-300 4-5 6 dg macro] [http://lamcgie.125mb.com/html/confessioni-di.htm confessioni di porno casalinghe] [http://itgurney.t35.com/view/new/canon-cbc/ canon cbc nb1] [http://madavid.t35.com/html/moncler/ moncler] [http://peter-land.somee.com/images/small/peter-north.htm peter north] [http://kiboukni.125mb.com/web/corso-azienda/ corso azienda] [http://dj-deus.somee.com/lib/hotels-.htm hotels - austria] [http://lamcgie.125mb.com/html/vendita-materiale.htm vendita materiale elettrico milano] [http://fergus-mac.somee.com/description/lib/lunedi/ lunedi] [http://yourorus.somee.com/data/packard-bell.htm packard bell mp3 audio star] [http://nairoz.somee.com/img/styles/pube-femminile/ pube femminile] [http://fawarfo.freeweb7.com/topic/i-ll.htm i ll fly with you] [http://dj-deus.somee.com/lib/amstrad-home.htm amstrad home] [http://rihelm.125mb.com/img/styles/range-rover/ range rover 4.0] [http://dabeutle.t35.com/content/view/istituti-religiosi.htm istituti religiosi cz] [http://viemalin.freeweb7.com/resources/articles/www-comune.htm www comune di gemmano rn it] [http://lamcgie.125mb.com/html/infradito-havaianas.htm infradito havaianas] [http://thegoogly.somee.com/view/new/turion-.htm turion 64 mt] [http://luallard.t35.com/html/hotel-marsa/ hotel marsa alam] [http://itgurney.t35.com/view/new/prt/ prt 41] [http://fergus-mac.somee.com/description/lib/vendo-fiat/ vendo fiat 124 spider] [http://davelovesyou.somee.com/library/html/www-ici/ www ici verona it] [http://rimarsh.t35.com/images/small/houdini.htm houdini] [http://yourorus.somee.com/data/gabri-ponte.htm gabri ponte la danza delle streghe] [http://coarmago.freeweb7.com/library/html/come-loggare.htm come loggare] [http://madavid.t35.com/html/alps-gorizia/ alps gorizia] [http://fergus-mac.somee.com/description/lib/otis/ otis] [http://flheddina.t35.com/web/www-fotos/ www fotos de perros] [http://thegoogly.somee.com/view/new/giorgia-video.htm giorgia video] [http://betheresa.t35.com/text/directory/convertitore-amr/ convertitore amr mmf] [http://nairoz.somee.com/img/styles/cartoonnetwork-com/ cartoonnetwork com] [http://coarmago.freeweb7.com/library/html/master-billy.htm master billy plus] [http://peter-land.somee.com/images/small/eufemismo.htm eufemismo] [http://jututor.125mb.com/lib/arpav-veneto/ arpav veneto] [http://peter-land.somee.com/images/small/christiane-f.htm christiane f. - noi i ragazzi dello zoo di berlino] [http://yourorus.somee.com/data/la-vita.htm la vita di emil nolde] [http://lensman.somee.com/html/scopate-con/ scopate con cani] [http://fawarfo.freeweb7.com/topic/pensioni-per.htm pensioni per cani] [http://madavid.t35.com/html/our-operetor/ our operetor] [http://nationavce.somee.com/library/html/rodo-veneziano/ rodo veneziano] [http://dabeutle.t35.com/content/view/iss-pro.htm iss pro] [http://lamcgie.125mb.com/html/una-calda.htm una calda serata d estate] [http://jedillar.125mb.com/resources/articles/renegade/ renegade] [http://jedillar.125mb.com/resources/articles/calendario-santarelli/ calendario santarelli 2006] [http://dj-deus.somee.com/lib/musica-free.htm musica free] [http://dj-deus.somee.com/lib/francesco-totti.htm francesco totti] [http://lamcgie.125mb.com/html/rexel.htm rexel 250] [http://itgurney.t35.com/view/new/jbl-creature/ jbl creature white] [http://am-i-bird.somee.com/img/styles/kodak-easyshare.htm kodak easyshare] [http://flheddina.t35.com/web/freeze/ freeze] [http://de-der.somee.com/library/html/desktop-atx.htm desktop atx case] [http://peter-land.somee.com/images/small/mr-magoo.htm mr. magoo] [http://viemalin.freeweb7.com/resources/articles/lavagno.htm lavagno] [http://lensman.somee.com/html/ljubavi-zbogom/ ljubavi zbogom] [http://itgurney.t35.com/view/new/hotel-maiori/ hotel maiori] [http://de-der.somee.com/library/html/diva.htm diva] [http://viemalin.freeweb7.com/resources/articles/f-i.htm f i g c sassari] [http://thegoogly.somee.com/view/new/ho-chi.htm ho chi minh hotel] [http://jututor.125mb.com/lib/archos-av/ archos- av700 40gb] [http://luallard.t35.com/html/placido-fois/ placido fois] [http://de-der.somee.com/library/html/logo-amici.htm logo amici] [http://fawarfo.freeweb7.com/topic/seven-nation.htm seven nation] [http://jedillar.125mb.com/resources/articles/il-figlio/ il figlio di robin hood] [http://rihelm.125mb.com/img/styles/infogest/ infogest] [http://itgurney.t35.com/view/new/kiapicanto/ kiapicanto] [http://lamcgie.125mb.com/html/concorsi-ordine.htm concorsi ordine architetti] [http://rihelm.125mb.com/img/styles/colori-dello/ colori dello arcobaleno] [http://nationavce.somee.com/library/html/www-tommaso/ www tommaso vianello com] [http://lamcgie.125mb.com/html/corsair-twinx.htm corsair twinx 3200llpt] [http://itgurney.t35.com/view/new/ballo/ ballo] [http://yourorus.somee.com/data/jet-lab.htm jet lab 600] [http://luallard.t35.com/html/partouze/ partouze] [http://betheresa.t35.com/text/directory/terratec-/ terratec - grabster av400] [http://lakitsmi.freeweb7.com/web/beach-soccer/ beach soccer] [http://jututor.125mb.com/lib/immobiliare-magia/ immobiliare magia ascoli p] [http://betheresa.t35.com/text/directory/ts-t/ ts t43] [http://coarmago.freeweb7.com/library/html/estelle-laurence.htm estelle laurence] [http://kiboukni.125mb.com/web/letra-dragoste/ letra dragoste din tei ozone] [http://trocterli.t35.com/img/styles/files-seca/ files seca2] [http://thegoogly.somee.com/view/new/screwdriver.htm screwdriver] [http://itgurney.t35.com/view/new/famous-artist/ famous artist] [http://am-i-bird.somee.com/img/styles/lenceria.htm lenceria] [http://jututor.125mb.com/lib/cancion-de/ cancion de andi lucas] [http://de-der.somee.com/library/html/pubblicita-tim.htm pubblicita tim foto] [http://jututor.125mb.com/lib/piccolo-capo/ piccolo capo indiano] [http://fawarfo.freeweb7.com/topic/millie.htm millie] [http://jedillar.125mb.com/resources/articles/jaguares/ jaguares] [http://brrezab.freeweb7.com/img/styles/copertina-striscia.htm copertina striscia la compilation 2004] [http://de-der.somee.com/library/html/kiss-lettore.htm kiss lettore dvd divx hard disk dp-558] [http://thegoogly.somee.com/view/new/line-spider.htm line6 spider] [http://kiboukni.125mb.com/web/papa-leone/ papa leone xiii] [http://nairoz.somee.com/img/styles/siemens-scaleo/ siemens scaleo l] [http://madavid.t35.com/html/biglietto-augurali/ biglietto augurali] [http://dj-deus.somee.com/lib/philipe-monteiro.htm philipe monteiro] [http://lensman.somee.com/html/rc-cars/ r.c. cars completato] {{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 15:45, 22 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)