|
Archives
D Programming
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.ide
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger
D.gnu
D
C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows
digitalmars.empire
digitalmars.DMDScript
electronics
|
digitalmars.D.announce - SimpleXMLD XML Parser 0.0.1
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
Brian Hsu Wrote:
The SimpleXMLD library download could be found at API documents too.
(http://bone.twbbs.org.tw/SimpleXMLD)
Sorry the above hyper link is broken: http://bone.twbbs.org.tw/SimpleXMLD
And just in case above URL doesn't work, here is a mirror site:
http://stu.im.ncnu.edu.tw/~brianhsu/SimpleXMLD
--
Brian Hsu
Brian Hsu wrote:
The SimpleXMLD library download could be found at API documents too.
(http://bone.twbbs.org.tw/SimpleXMLD)
Thanks! Can you also please add the phrase "D programming language" to
your web page somewhere so google will associate it with D?
Walter Bright Wrote:
Thanks! Can you also please add the phrase "D programming language" to
your web page somewhere so google will associate it with D?
Thanks for your reminding, this is indeed a very important thing that I forget
to do. ;)
BTW, Now this project is hosting on dsource, people who interested in this
project could see http://dsource.org/projects/simplexmld as official website.
Subversion repository of source code and API documents are also available on
that page now.
--
Brian Hsu
Looks nice; I'll take a closer look at it when I get the chance.
AFAIK, the only other person working on an XML parser for D is JimPanic.
That said, I've got work-in-progress implementations of DOM Level 1, SAX
2 and a D-specific PullDOM inspired by Python up at
<http://drk.is-a-geek.net/~drk/d/xml.7z>. It uses a binding to Expat as
the parser currently.
Basically, just haven't had time to work on it lately; it's all BSD v2,
so feel free to borrow bits if you want :)
-- Daniel "oh how I hate the W3C"
I know of another that is /insanely/ fast. Not public yet, but it royally
kicks some 'enterprise' ass
;)
"Daniel Keep" <daniel.keep.lists gmail.com> wrote in message
news:fdsn0t$2k32$1 digitalmars.com...
Looks nice; I'll take a closer look at it when I get the chance.
AFAIK, the only other person working on an XML parser for D is JimPanic.
That said, I've got work-in-progress implementations of DOM Level 1, SAX
2 and a D-specific PullDOM inspired by Python up at
<http://drk.is-a-geek.net/~drk/d/xml.7z>. It uses a binding to Expat as
the parser currently.
Basically, just haven't had time to work on it lately; it's all BSD v2,
so feel free to borrow bits if you want :)
-- Daniel "oh how I hate the W3C"
Kris wrote:
I know of another that is /insanely/ fast. Not public yet, but it royally
kicks some 'enterprise' ass
;)
Well, the goal of my XML stuff is to provide implementations of the
various API standards, not implement the actual parsing. I used Expat
basically because it was there, and fairly simple to hook up.
-- Daniel
Kris schrieb:
I know of another that is /insanely/ fast. Not public yet, but it royally
kicks some 'enterprise' ass
;)
will this "damned fast piece of code" become part of Tango ?
Thanks for clarification.
Bjoern
"Daniel Keep" <daniel.keep.lists gmail.com> wrote in message
news:fdsn0t$2k32$1 digitalmars.com...
Looks nice; I'll take a closer look at it when I get the chance.
AFAIK, the only other person working on an XML parser for D is JimPanic.
That said, I've got work-in-progress implementations of DOM Level 1, SAX
2 and a D-specific PullDOM inspired by Python up at
<http://drk.is-a-geek.net/~drk/d/xml.7z>. It uses a binding to Expat as
the parser currently.
Basically, just haven't had time to work on it lately; it's all BSD v2,
so feel free to borrow bits if you want :)
-- Daniel "oh how I hate the W3C"
A high probability :)
"BLS" <nanali nospam-wanadoo.fr> wrote in message
news:fdt5g9$125k$1 digitalmars.com...
Kris schrieb:
I know of another that is /insanely/ fast. Not public yet, but it royally
kicks some 'enterprise' ass
;)
will this "damned fast piece of code" become part of Tango ?
Thanks for clarification.
Bjoern
Kris wrote:
I know of another that is /insanely/ fast. Not public yet, but it royally
kicks some 'enterprise' ass
Even the not-so-insanely fast version kicks ass and essentially does
exactly the same I am trying to achieve - damn. As Lars said on IRC, the
XML market is flourish these days. ;P
Alexander Panek wrote:
Kris wrote:
I know of another that is /insanely/ fast. Not public yet, but it royally
kicks some 'enterprise' ass
Even the not-so-insanely fast version kicks ass and essentially does
exactly the same I am trying to achieve - damn. As Lars said on IRC, the
XML market is flourish these days. ;P
Well, is there as fast s-expression parser yet for D? I bet that could be
useful for people who know xml is a bit too verbose. :)
Jari-Matti Mäkelä wrote:
Alexander Panek wrote:
Kris wrote:
I know of another that is /insanely/ fast. Not public yet, but it royally
kicks some 'enterprise' ass
exactly the same I am trying to achieve - damn. As Lars said on IRC, the
XML market is flourish these days. ;P
Well, is there as fast s-expression parser yet for D? I bet that could be
useful for people who know xml is a bit too verbose. :)
There's the dead dLisp project. http://www.dsource.org/projects/dlisp
I would hope they at *least* got as far as parsing s-exps before
abandoning the project.
--bb
Hi Brian,
So nice to see a /simple/ DOM ;)
Are you considering XPath query also?
- Kris
Brian Hsu Wrote:
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
fumanchu Wrote:
Are you considering XPath query also?
- Kris
Yes, but I'm just starting reading some XPath tutorial, so it may take an while
before I could implement it.
And there is also a high probabilities that I would just implement a subset of
it instead of all operator of XPath query.
For Example:
// Access Select middle BBB element(s) :
BBB[position() = floor(last() div 2 + 0.5) or position() = ceiling(last() div 2
+ 0.5) ] may not be implemented.
Because currently I think the goal of SimpleXMLD is let user easily access XML
as a tree structure without having to much knowledge about so many standard,
parsing method or jargon that they do not know.
So XPath in my current thought, it is just a way that user could easily access
nodes in XML tree structure when they are already know the structure of XML
tree in SimpleXMLD.
They could use query like '/AAA/BBB/CCC' to access third level child and //BBB
to access all child named BBB instead of writing much D code to do lots of
tedious things like search the whole tree for nodes that are named BBB.
Since it is very easy when you could get all BBB node in an array and calculate
the middle of array index to get the middle BBB node, using above XPath query
will not save much computation time or memory space(because all node object are
already in system memory), but just an overhead for library to process the
query.
--
Brian Hsu
Makes a lot of sense; thanks :)
"Brian Hsu" <brianhsu.hsu gmail.com> wrote in message
news:fdv00n$1hp0$1 digitalmars.com...
fumanchu Wrote:
Are you considering XPath query also?
- Kris
Yes, but I'm just starting reading some XPath tutorial, so it may take an
while before I could implement it.
And there is also a high probabilities that I would just implement a
subset of it instead of all operator of XPath query.
For Example:
// Access Select middle BBB element(s) :
BBB[position() = floor(last() div 2 + 0.5) or position() = ceiling(last()
div 2 + 0.5) ] may not be implemented.
Because currently I think the goal of SimpleXMLD is let user easily access
XML as a tree structure without having to much knowledge about so many
standard, parsing method or jargon that they do not know.
So XPath in my current thought, it is just a way that user could easily
access nodes in XML tree structure when they are already know the
structure of XML tree in SimpleXMLD.
They could use query like '/AAA/BBB/CCC' to access third level child and
//BBB to access all child named BBB instead of writing much D code to do
lots of tedious things like search the whole tree for nodes that are named
BBB.
Since it is very easy when you could get all BBB node in an array and
calculate the middle of array index to get the middle BBB node, using
above XPath query will not save much computation time or memory
space(because all node object are already in system memory), but just an
overhead for library to process the query.
--
Brian Hsu
|
|