Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A XML parser written in Rust

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
NotificationsYou must be signed in to change notification settings

Florob/RustyXML

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

Documentation

RustyXML is a namespace aware XML parser written in Rust.Right now it provides a basic SAX-like API, and an ElementBuilder based on that.

The parser itself is derived from OFXMLParser as found in ObjFWhttps://webkeks.org/objfw/.

The current limitations are:

  • Incomplete error checking
  • Unstable API

The Minimal Supported Rust Version for this crate is Rust 1.40.0.

Examples

Parse a string into anElement struct:

use xml::Element;let elem:Option<Element> ="<a href='//example.com'/>".parse();

Get events from parsing string data:

use xml::{Event,Parser};// Create a new Parserletmut p =Parser::new();// Feed data to be parsedp.feed_str("<a href");p.feed_str("='//example.com'/>");// Get events for the fed datafor eventin p{match event.unwrap(){Event::ElementStart(tag) =>println!("<{}>", tag.name),Event::ElementEnd(tag) =>println!("</{}>", tag.name),        _ =>()}}

This should print:

<a></a>

BuildElements fromParserEvents:

use xml::{Parser,ElementBuilder};letmut p = xml::Parser::new();letmut e = xml::ElementBuilder::new();p.feed_str("<a href='//example.com'/>");for elemin p.filter_map(|x| e.handle_event(x)){match elem{Ok(e) =>println!("{}", e),Err(e) =>println!("{}", e),}}

BuildElements by hand:

letmut reply = xml::Element::new("iq".into(),Some("jabber:client".into()),vec![("type".into(),None,"error".into()),("id".into(),None,"42".into())]);reply.tag(xml::Element::new("error".into(),Some("jabber:client".into()),vec![("type".into(),None,"cancel".into())])).tag_stay(xml::Element::new("forbidden".into(),Some("urn:ietf:params:xml:ns:xmpp-stanzas".into()),vec![])).tag(xml::Element::new("text".into(),Some("urn:ietf:params:xml:ns:xmpp-stanzas".into()),vec![])).text("Permission denied".into());

Result (some whitespace added for readability):

<iqxmlns='jabber:client'id='42'type='error'>  <errortype='cancel'>    <forbiddenxmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>    <textxmlns='urn:ietf:params:xml:ns:xmpp-stanzas'>Permission denied</text>  </error></iq>

Attribute Order

By default the order of attributes is not tracked. Therefore during serialization and iterationtheir order will be random. This can be changed by enabling theordered_attrs feature.With this feature enabled the order attributes were encountered while parsing,or added to anElement will be preserved.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submittedfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without anyadditional terms or conditions.

About

A XML parser written in Rust

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Contributors3

  •  
  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp