eminence / xmltree-rs

Reads an XML file into a simple tree structure
MIT License
39 stars 31 forks source link

Comments #17

Closed dyst5422 closed 4 years ago

dyst5422 commented 4 years ago

It seems that comments are currently skipped. Would you be open to discussions of handling those comments?

eminence commented 4 years ago

Sure, that definitely sounds like a good idea. Do you have any ideas about how the API should handle comments? The current Element type isn't currently well suited for this right now

dyst5422 commented 4 years ago

Yeah. I've written some similar style parsers before. I think you should have other types alongside the element type for comments, text, and cdata. And the children of any element is an enum of those and elements. That way you can preserve order and have multiple of the comment and cdata types.

enum XMLItem {
  Element(Element),
  Text(String),
  Comment(String),
  CData(String),
}

struct Element {
  children: Vec<XMLItem>
  ..
}
dyst5422 commented 4 years ago

I recognize this would be a breaking change, but currently, you can't preserve order for text as it is - which can be a problem in some xml use cases (though probably not a good guarantee for people to bet on). Personally, I think an XML lib should produce identical output (save whitespace) to what it takes in.

dyst5422 commented 4 years ago

Perhaps also processing instructions

dyst5422 commented 4 years ago

Opened #18 to cover this. Would love to know if this looks like an appropriate solution to you