SimpleXMLD XML Parser 0.0.1
Brian Hsu
brianhsu.hsu at gmail.com
Mon Oct 1 07:08:28 PDT 2007
Hello, everybody
I've wrote an simple XML DOM-like parser, because I could not found an appropriate one that more comprehensive.
I think may be there are others seeking for an library which could retrieve information from XML file easily, so here is my pieces of work.
SimpleXMLD is a library which inspired by PHP's SimpleXML functions, it cloud load XML file into memory and build a tree structure of it. It is suitable when you just want to quickly access an small XML file.
For example, if you have following XML file:
------------------ test.xml ---------------------
<root isRoot="true">
<hello>text</hello>
<node key1="1">node 1</node>
<node key2="2">node 2</node>
</root>
--------------------------------------------------
And you cloud use SimpleXMLD access them easily:
--------------------------------------------------
import SimpleXMLD.all;
void main ()
{
// Just load XML from disk file an build an tree structure
SimpleXML root = SimpleXML.loadFile ("test.xml");
// Get node attribute
char [] isRoot = root.attributes["isRoot"]; // Now isRoot="true"
// Get node data of hello
SimpleXML [] hello = root["hello"];
// This will output "text"
Stdout (hello[0].data);
// Iterate over all child
foreach (SimpleXML node; root) {
char [] tagname = node.tag;
char [] textdata = node.data;
}
// Iterate over all olny child named "node"
foreach (SimpleXML node; root["node"]) {
char [] tagname = node.tag;
char [] textdata = node.data;
}
}
--------------------------------------------------
Currently I am waiting dsource approve hosting this project on it, so I only have API document instead of official website. But I tried make API documents comprehensive and clearly, although my English is not my native speaking language, so it may be look a little weired.
The SimpleXMLD library download could be found at API documents too. (http://bone.twbbs.org.tw/SimpleXMLD)
It is first time I wrote library for D, and in fact I'm not really familiar with XML standard, so this library may be buggy, and the design is not very pretty too, so any suggestion are welcome.
--
Brian Hsu
More information about the Digitalmars-d-announce
mailing list