nxml-rs
nxml-rs is a Rust rewrite of NXML.
NXML is a pseudo-XML parser that can read and write the oddly formatted and often invalid XML files from Noita. NXML (the C#/.NET version linked before) is itself a port of the XML parser from Poro, which is used by the custom Falling Everything engine on which Noita runs.
In short, nxml-rs is an XML parser that is 100% equivalent to Noita's parser. It is just as non-conformant to the XML specification as Noita itself. It can also produce semantically equivalent output in the form of a string.
Additionally (just for fun), nxml-rs provides an nxml!
macro that allows you
to create nxml elements by writing almost-XML (text content requires some extra
characters and is generally poorly supported and not really used by Noita
anyway) directly in your Rust code.
Because it's Rust and thus it was relatively easy to do, the parsing is almost
zero-copy - a single exception being non-continuous bare text,
<a>hello<b/>world</a>
, which is non-existingly rare and is a preserved quirk
of how noita parser handles that anyway, handled with Cow
.
Example
use *;
// Element::parse_* is a shortcut for ElementRef::parse_* followed by into_owned
let = parse_lenient;
// Some sugar, >> is alias for .child("name").unwrap(), and << is same for .attr
assert_eq!;
let a_lot = 0;
let speed = 0;
// make a new element through the builder
let extra = new
.with_attr
.with_attr
.with_attr;
// or use the macro
let extra = nxml! ;
// A modification - entity.children is just a vec ¯\_(ツ)_/¯
entity.children.insert;
assert_eq!;
Cargo features
indexmap
- UseIndexMap
from theindexmap
crate instead ofHashMap
for attributes. This is useful if you want to preserve the order of attributes in the output. Enabled by default, you can disable it to shake off that one dependency if you don't care about attrubute order.