#xml #validation #string #name #rxml #production #grammar

no-std rxml_validation

Plumbing crate for rxml and rxml_proc crates

12 releases (7 breaking)

0.11.0 Jun 15, 2024
0.10.0 Mar 16, 2024
0.9.1 Jan 25, 2023
0.8.2 Dec 17, 2022
0.4.0 Aug 18, 2021

#393 in Rust patterns

Download history 18643/week @ 2024-08-06 14907/week @ 2024-08-13 13936/week @ 2024-08-20 14626/week @ 2024-08-27 17274/week @ 2024-09-03 15719/week @ 2024-09-10 14941/week @ 2024-09-17 16379/week @ 2024-09-24 12954/week @ 2024-10-01 16154/week @ 2024-10-08 17675/week @ 2024-10-15 19502/week @ 2024-10-22 19393/week @ 2024-10-29 17387/week @ 2024-11-05 15170/week @ 2024-11-12 15838/week @ 2024-11-19

71,048 downloads per month
Used in 36 crates (3 directly)

MIT license

55KB
1.5K SLoC

rxml_validation — Utilities for validating strings against specific XML productions

This crate is an infrastructure/plumbing crate for the rxml and rxml_proc crates. It provides utility functions to validate that strings conform to the CData, Name and NCName grammars described in the XML 1.0 specification.

crate badge docs badge

Please see the rxml and rxml_proc crates for more information.


lib.rs:

Strongly-typed strings for use with XML 1.0 documents

This crate defines various string- and str-like types which represent pieces of text as they may occur in XML documents. These types are checked to contain only text which conforms to the respective grammar in the XML specifications.

This allows to carry information about the checking which already took place in the parser to the application, avoiding the need to execute checks multiple times.

This is a supplementary crate for rxml. It is factored out of the main crate to support rxml_proc, a crate of macros which allow compile-time validation and typing of XML strings. All types defined in this crate are re-exported in rxml; if you depend on rxml, you can use the types from there directly.

If the std feature is not enabled (it is enabled by default), this crate can be used in no_std environments.

Type Overview

  • Name and NameStr represent the Name production and can be used for element and attribute names before namespace prefix expansion.
  • NcName and NcNameStr represent the Name production but without a colon inside; they are used for localnames after prefix expansion and to carry the prefixes themselves.

Construction

In general, values are constructed using the std::convert::TryInto trait, from other string types or str. Supported source types are:

Note: If the compact_str feature is not enabled, all string types use the normal std::string::String type instead.

In addition, converting from NcName to Name is possible without extra checking and is thus possible through .into() (and likewise for the corresponding str types).

The inverse directions are only available through try_into.

When to use rxml_validation vs. rxml?

You should use this crate (rxml_validation) whenever you only need to validate strings against rules present in XML, without actually parsing or serialising XML data. In that case, this crate is a much lighter choice and it can be used in no_std environments.

Dependencies

~110KB