hunt-xml 1.1.0-rc.7
A xml parsing library for D programming language.
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
Hunt-XML
A XML library for D Programming Language.
Features
- DOM parser: parse XML Document
- DOM writer: to string and to file
- Object serialization/deserialization
Examples
String parse/write
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
}
}
File load/save
import hunt.xml;
void main()
{
Document document = Document.load("resources/books.xml");
document.save("output.xml");
}
Simple object serialization/deserialization
@XmlRootElement("GreetingBase")
abstract class GreetingSettingsBase {
string city;
string name = "HuntLabs";
}
@XmlRootElement("Greeting")
class GreetingSettings : GreetingSettingsBase {
@XmlAttribute("ID")
int id = 1001;
@XmlElement("Color")
string color;
}
void objectToXml() {
auto settings = new GreetingSettings;
settings.name = "hunt";
Document doc = toDocument(settings);
writeln(doc.toString()); // print xml text
writeln(doc.toPrettyString()); // print pretty xml text
}
void xmlToObject() {
string text = `
<Greeting ID='1003'>
<GreetingBase>
<city/>
<name>hunt</name>
</GreetingBase>
<Color>Red</Color>
</Greeting>
`;
auto obj = toObject!(GreetingSettings)(text);
assert(obj.id == 1003);
assert(obj.name == "hunt");
assert(obj.color == "Red");
}
Complex object serialization/deserialization
See SerializerTest.
<Greeting>
<GreetingBase ID='123'>
<content>Hello</content>
</GreetingBase>
<privateMember>private member</privateMember>
<settings ID='1001' __metatype__='test.SerializerTest.GreetingSettings'>
<Greeting-SettingsBase>
<city/>
<name>name in base</name>
</Greeting-SettingsBase>
<Color>Red</Color>
<name/>
</settings>
<content>Hello, world!</content>
<creationTime format='std'>637110507901821669</creationTime>
<nullTimes/>
<times>
<SysTime format='std'>637110507901821729</SysTime>
<SysTime format='std'>637110507901821731</SysTime>
</times>
<bytes/>
<members>
<string>Alice</string>
<string>Bob</string>
</members>
<guests>
<Guest>
<name>guest01</name>
<age>25</age>
</Guest>
</guests>
<languages>
<en-us>English</en-us>
<zh-cn>中文</zh-cn>
</languages>
</Greeting>
- Registered by zoujiaqing
- 1.1.0-rc.7 released 3 years ago
- huntlabs/hunt-xml
- www.huntlabs.net
- Apache-2.0
- Copyright (C) 2018-2020, HuntLabs
- Dependencies:
- hunt-extra
- Versions:
-
1.1.0-rc.7 2021-Nov-22 1.1.0-rc.6 2021-Nov-22 1.1.0-rc.5 2021-Apr-08 1.1.0-rc.2 2020-Nov-07 1.0.0-rc.7 2021-Nov-22 - Download Stats:
-
-
0 downloads today
-
2 downloads this week
-
3 downloads this month
-
308 downloads total
-
- Score:
- 0.5
- Short URL:
- hunt-xml.dub.pm