std.xml
Types
struct XmlError
Functions
[src]
pub fn parse<T>(input: string | Bytes | Read): T throws XmlError {
switch (let input = input.(type)) {
case string:
return try _xml.parse::<T>(_create_native_read(Cursor.new(input)));
case Bytes:
return try _xml.parse::<T>(_create_native_read(Cursor.new(input)));
case Read:
return try _xml.parse::<T>(_create_native_read(input));
}
}
Parse a XML into specific type.
[src]
pub fn parse<T>(input: string | Bytes | Read): T throws XmlError {
switch (let input = input.(type)) {
case string:
return try _xml.parse::<T>(_create_native_read(Cursor.new(input)));
case Bytes:
return try _xml.parse::<T>(_create_native_read(Cursor.new(input)));
case Read:
return try _xml.parse::<T>(_create_native_read(input));
}
}
Parse a XML into specific type.
Parse a XML into specific type.
nv
use std.xml;
struct User {
name: string,
id: int,
}
let user = try! xml.parse::<User>(`
<user>
<name>Sunli</name>
<id>123456</id>
</user>
`);
assert_eq user.name, "Sunli";
assert_eq user.id, 123456;
[src]
pub fn to_string<T>(value: T): string throws XmlError {
let buf = Bytes.new();
try _xml.to_writer(_create_native_write(buf), value);
return buf.to_string();
}
Serialize the given value as XML into a string.
[src]
pub fn to_string<T>(value: T): string throws XmlError {
let buf = Bytes.new();
try _xml.to_writer(_create_native_write(buf), value);
return buf.to_string();
}
Serialize the given value as XML into a string.
Serialize the given value as XML into a string.
nv
use std.xml;
struct User {
name: string,
id: int,
profile: Profile
}
struct Profile {
city: string
}
let user = User {
name: "Sunli",
id: 123456,
profile: Profile {
city: "Wuhan"
}
};
let result = try! xml.to_string(user);
assert_eq result, "<?xml version=\"1.0\" encoding=\"utf-8\"?><name>Sunli</name><id>123456</id><profile><city>Wuhan</city></profile>";
[src]
pub fn to_writer<T>(writer: Write, value: T) throws XmlError {
try _xml.to_writer(_create_native_write(writer), value);
}
Serialize the given value as XML to std.io.Write
.
[src]
pub fn to_writer<T>(writer: Write, value: T) throws XmlError {
try _xml.to_writer(_create_native_write(writer), value);
}
Serialize the given value as XML to std.io.Write
.
Serialize the given value as XML to std.io.Write
.
nv
use std.io.Bytes;
use std.xml;
struct User {
name: string,
}
let buf = Bytes.new();
let user = User { name: "Jason Lee" };
try! xml.to_writer(buf, user);
assert_eq buf.to_string(), "<?xml version=\"1.0\" encoding=\"utf-8\"?><name>Jason Lee</name>";