Comments (7)
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.
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.
@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.
@masklinn, you're right, of course. I think that at first something like Json
ADT will do fine.
from xml-rs.
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.
This crate provides this functionality and is built on top of xml-rs: https://github.com/eminence/xmltree-rs
from xml-rs.
I'll leave DOM construction to other crates.
from xml-rs.
Related Issues (20)
- Overflow in lexer when parsing malformed doctype HOT 1
- Fails to parse /> as part of XML body HOT 7
- Implement the position trait for the Events Iterator
- panicked at 'attempt to add with overflow' HOT 2
- Feature request: common Error enum for read/write
- Restricted XmlEvent? HOT 1
- [Question] How to implement streaming parsing? HOT 1
- deprecation warnings HOT 1
- Is this crate abandoned? HOT 3
- Parsing of comments <!-- <!-->
- Maintenance of xml-rs HOT 10
- EventReader never return Result::Err after document end HOT 1
- Version 0.8.9 broke deserialization behavior HOT 2
- 0.8.12's field types in xml::common::TextPosition break existing code HOT 1
- Panic in `PullParser::push_pos()` HOT 1
- You've found a bug in xml-rs, caused by calls to push_pos() HOT 3
- Profile-Guided Optimization (PGO) results HOT 2
- Simple way to remove whitespaces HOT 1
- Deal with files that start with empty line HOT 2
- Add default "xmlns" on ParserConfig2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xml-rs.