Last update May 19, 2012

Doc Comments / Phobos /
Std Xml



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!

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

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:

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

void main() { // 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); } }


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))