Last update May 19, 2012

Doc Comments / Phobos /
Std Xml



std.xml

Comments

I cannot get either of the examples at the top to compile in DMD 2.059.

I can't edit the page to put in new code, because the link to Github gives me a 404 error! https://github.com/D-Programming-Language/phobos/edit/master/std/xml.d

The following code does the same as the first example, and compiles (for me at least):

 import std.xml;
 import std.stdio;
 import std.string;
 import std.file : read;

// books.xml is used in various samples throughout the Microsoft XML Core // Services (MSXML) SDK. // // See http://msdn2.microsoft.com/en-us/library/ms762271(VS.85).aspx

void main() { string s = cast(string) read("book.xml");

// Check for well-formedness check(s);

// Make a DOM tree auto doc = new Document(s);

// Plain-print it write(doc); }

Alternatives to std.xml

dom.d by Adam D. Ruppe

This is a JavaScript? compatible DOM parser for XML.

Example code:

 /*
  *  read all the titles from book.xml
  *
  *  uses dom.d and characterencodings.d by alex d ruppe:
  *   https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff
  */

import arsd.dom; import std.file; import std.stdio; import std.conv;

void main() { // http://msdn2.microsoft.com/en-us/library/ms762271(VS.85).aspx auto document = new Document(readText("book.xml"), true, true);

auto map = document.requireSelector("catalog");

foreach (book; document.getElementsByTagName("book")) { string title = book.getElementsByTagName("title")[0].innerText();

writeln(title); } }

Links


FrontPage | News | TestPage | MessageBoard | Search | Contributors | Folders | Index | Help | Preferences | Edit

Edit text of this page (date of last change: May 19, 2012 2:12 (diff))