#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

#367 in Rust patterns

Download history 16479/week @ 2024-07-26 21203/week @ 2024-08-02 15127/week @ 2024-08-09 14670/week @ 2024-08-16 13946/week @ 2024-08-23 16252/week @ 2024-08-30 16541/week @ 2024-09-06 14789/week @ 2024-09-13 15868/week @ 2024-09-20 14988/week @ 2024-09-27 13849/week @ 2024-10-04 17576/week @ 2024-10-11 18568/week @ 2024-10-18 19636/week @ 2024-10-25 19182/week @ 2024-11-01 15632/week @ 2024-11-08

76,351 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