www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - Hunt XML released 1.0.0 rc! Support for parsing, encoding, serialize,

reply zoujiaqing <zoujiaqing gmail.com> writes:

A XML library for D Programming Language. Support for parsing, 
encoding, serialize, unserialize, object binding!


* DOM parser: parse XML Document
* DOM writer: to string and to file
* Object serialization/deserialization



```D
import hunt.xml;

void main()
{
     Document doc = Document.parse("<single-element attr1='one' 
attr2=\"two\"/>");

     if(doc.validate())
     {
         auto node = doc.firstNode();

         writeln(node.getName()); // print single-element
     }
}
```


```D
import hunt.xml;

void main()
{
	Document document = Document.load("resources/books.xml");

	document.save("output.xml");
}
```

Source code repository:
https://github.com/huntlabs/hunt-xml

DLang package:
https://code.dlang.org/packages/hunt-xml
Dec 05 2019
parent reply Joseph Rushton Wakeling <joseph.wakeling webdrake.net> writes:
On Thursday, 5 December 2019 at 15:55:29 UTC, zoujiaqing wrote:

 A XML library for D Programming Language. Support for parsing, 
 encoding, serialize, unserialize, object binding!


 * DOM parser: parse XML Document
 * DOM writer: to string and to file
 * Object serialization/deserialization
Cool, congratulations :-) Just based on a quick check, it looks like the `validate` method used in your example is just about strictly correct XML -- does the library provide any support for validating messages against a schema? And -- mostly out of curiosity -- what are the major differences compared to other D XML libraries such as experimental.xml <https://github.com/dlang-community/experimental.xml> and dxml <https://github.com/jmdavis/dxml> ... ?
Dec 05 2019
next sibling parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Thursday, 5 December 2019 at 16:14:01 UTC, Joseph Rushton 
Wakeling wrote:
 And -- mostly out of curiosity -- what are the major 
 differences compared to other D XML libraries
or my beloved dom.d
Dec 05 2019
parent reply Joseph Rushton Wakeling <joseph.wakeling webdrake.net> writes:
On Thursday, 5 December 2019 at 16:28:48 UTC, Adam D. Ruppe wrote:
 On Thursday, 5 December 2019 at 16:14:01 UTC, Joseph Rushton 
 Wakeling wrote:
 And -- mostly out of curiosity -- what are the major 
 differences compared to other D XML libraries
or my beloved dom.d
Indeed! Sorry for missing it out. I've found it friendly and helpful for a number of use-cases, but as they were all related to HTML parsing, my mental map of dom.d is a bit focused on that, and its broader uses skipped my mind.
Dec 06 2019
parent Adam D. Ruppe <destructionator gmail.com> writes:
On Friday, 6 December 2019 at 08:58:38 UTC, Joseph Rushton 
Wakeling wrote:
 as they were all related to HTML parsing
Indeed, it is biased toward that use case, but it actually does quite a few extra things too that I don't market as much (and takes some extra code to fully enable - like the embedded <% code %> support - but still).
Dec 06 2019
prev sibling parent reply zoujiaqing <zoujiaqing gmail.com> writes:
 Just based on a quick check, it looks like the `validate` 
 method used in your example is just about strictly correct XML 
 -- does the library provide any support for validating messages 
 against a schema?
Yes, we will add valid() function to check it.
 And -- mostly out of curiosity -- what are the major 
 differences compared to other D XML libraries such as 
 experimental.xml 
 <https://github.com/dlang-community/experimental.xml> and dxml 
 <https://github.com/jmdavis/dxml> ... ?
Hunt XML: Easier to use API. It's like dom4j.. Have comments like XmlElement, XmlAttribute, XmlIgnore and more .. ```D import hunt.xml; XmlRootElement("user") class User { XmlAttribute("ID") int id = 1001; XmlElement("USERNAME") string name; } void main() { auto user = new User; user.id = 10000; user.name = "Brian"; auto doc = toDocument(user); writeln(doc.toPrettyString()); } ``` ```xml <user ID="1002"> <USERNAME>Brian</USERNAME> </user> ```
Dec 05 2019
parent JN <666total wp.pl> writes:
On Thursday, 5 December 2019 at 16:48:01 UTC, zoujiaqing wrote:

 ```D
 import hunt.xml;

  XmlRootElement("user")
 class User
 {

      XmlAttribute("ID")
     int id = 1001;

      XmlElement("USERNAME")
     string name;
 }
I like the declarative API, can't wait to give it a go. Reminds me of JAXB :)
Dec 05 2019