GithubHelp home page GithubHelp logo

xml-builder's People

Contributors

bugeats avatar cafce25 avatar cocool97 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

xml-builder's Issues

add_text should escape "'<>&

This code generate bad XML

use xml_builder::{XMLBuilder, XMLElement, XMLVersion};

fn main() {
    let mut xml = XMLBuilder::new()
        .version(XMLVersion::XML1_1)
        .encoding("utf-8".into())
        .build();

    let mut text = XMLElement::new("text");
    text.add_text(r#"&"'<>"#.into()).unwrap();

    xml.set_root_element(text);
    let mut writer = Vec::new();
    xml.generate(&mut writer).unwrap();

    let _str = String::from_utf8(writer).unwrap();
    print!("{}", _str)
}

result:

<?xml version="1.1" encoding="utf-8"?>
<text>&"'<></text>

expect:

<?xml version="1.1" encoding="utf-8"?>
<text>&amp;&quot;&apos;&lt;&gt;</text>

I think it is not reasonable behavior for users to have to perform escaping manually.

Use `fmt::Write` instead of `io::Write` for `generate` and `render`?

Hi! I've been wondering whether the data written to the writer passed to generate/render only contains valid UTF8. I couldn't find any documentation, but from briefly looking at the code, it does seem like it? In that case, could one change the trait bound to fmt::Write? That would allow passing Strings to the methods.

I suppose this has something to do with #7?

Handle document encoding

Currently encoding attribute exists, but its value does not make changes on final XML document

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.