Doc Comments / Phobos /
Std Xml
Difference (last edit) (Author, normal page display)
Added: 37a38,76
== Alternatives to std.xml = === dom.d by Adam D. Ruppe = This is a JavaScript? compatible DOM parser for XML. * Download dom.d and characterencodings.d from ![]() * Save them to C:\D\dmd2\src\phobos\arsd\ * When compiling, link them to your code using the command: dmd.exe yourCode arsd/dom.d arsd/characterencoding.d 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); } } |
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.
- Download dom.d and characterencodings.d from
https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff
- Save them to C:\D\dmd2\src\phobos\arsd * When compiling, link them to your code using the command: dmd.exe yourCode arsd/dom.d arsd/characterencoding.d
/* * 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
- Corresponding page in the D Specification:
- D 1.x: N/A
D 2.x
- See also: XML Libraries