Coder Social home page Coder Social logo

Dom Tree about xml-rs HOT 7 CLOSED

Binero avatar Binero commented on June 3, 2024 1
Dom Tree

from xml-rs.

Comments (7)

linkmauve avatar linkmauve commented on June 3, 2024 2

In addition to xmltree-rs mentioned above, we now have https://crates.io/crates/minidom and https://crates.io/crates/elementtree, Iā€™d suggest closing this issue as out of scope.

from xml-rs.

netvl avatar netvl commented on June 3, 2024

Yes, you're correct on that the library needs a DOM tree building. I want just to finish XML writing first.

As for your suggestions, I think that encapsulating existing events is a no-go. Events and DOM trees are way too different. A separate data type will be needed.

One of the best XML DOM libraries I've ever used is JDOM2. It may be used as a source of inspiration. It is a Java library, so its approach can't be used directly in Rust, though; I believe we have the same troubles here as the Servo team has with HTML DOM nodes.

I was also thinking about using a zipper structure. It may be more convenient to use given Rust ownership semantics and more extensive functional capabilities, but it may have the same problem with bidirectional references like in a regular DOM tree. This requires additional research.

from xml-rs.

masklinn avatar masklinn commented on June 3, 2024

@netvl not all DOMs have bidi links, and though bidirectional parent/child links are useful much can already be done with just parent -> child.

For instance Python's ElementTree API is reasonably well regarded and provides no child -> parent link (although lxml reimplementation does extend it with one such link, and numerous others, that capability might be added later on if somebody figures out how, alternatively the first DOM could be called Simple* and provide only a basic tree-ish API with a simple costs profile, with the ability to either extend it later on or add a separate more featureful treeish).

Servo must implement a W3C DOM with all its requirements and java-ish-based semantics, xml-rs doesn't necessarily have to.

from xml-rs.

netvl avatar netvl commented on June 3, 2024

@masklinn, you're right, of course. I think that at first something like Json ADT will do fine.

from xml-rs.

zonyitoo avatar zonyitoo commented on June 3, 2024

I think the DOM structure could be

// Attribute could be represented as a Map
type OwnedAttribute = BTreeMap<OwnedName, String>;

struct Node {
    parent: Weak<Node>,
    data: NodeData,
}

enum NodeData {
    Element {
        name: OwnedName,
        attributes: OwnedAttribute,
        namespace: Rc<Namespace>,
        children: DList<Rc<Node>>,
    },
    Text(String),
    CData(String),
    Comment(String),
    ProcInst {
        encoding: Encoding,
        target: String,
        version: Version,
    }
}

struct Document {
    root: Rc<Node>,
    encoding: Encoding,
    namespace: Rc<Namespace>,
}

from xml-rs.

rminderhoud avatar rminderhoud commented on June 3, 2024

This crate provides this functionality and is built on top of xml-rs: https://github.com/eminence/xmltree-rs

from xml-rs.

kornelski avatar kornelski commented on June 3, 2024

I'll leave DOM construction to other crates.

from xml-rs.

Related Issues (20)

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.