Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

XML AST #2

Closed
revolunet opened this issue Mar 19, 2018 · 17 comments
Closed

XML AST #2

revolunet opened this issue Mar 19, 2018 · 17 comments
Labels
🧘 status/waiting This may go somewhere but needs more information 💬 type/discussion This is a request for comments

Comments

@revolunet
Copy link

Hi,

Playing with some awesome mdast/hast unist stuff recently, when i went through XML again i wondered if we could use unist tools to play with XML trees, but looks like its not yet possible ?

To implement, the steps are :

a) create the syntax-tree

i guess this is defining the tree "model" and it will be very much like this one ? https://github.com/syntax-tree/hast#ast

b) create the parser/stringifier

I guess this is something like https://github.com/rehypejs/rehype/tree/master/packages/rehype-parse and https://github.com/syntax-tree/hast-util-to-html ?

@wooorm
Copy link
Member

wooorm commented Mar 19, 2018

a) create the syntax-tree

Yup! Mostly like HAST. But with some added nodes for processing instructions, cdata, and whatnot!

b) create the parser/stringifier

Probably built on some other XML parser. Depends on how far you’d like to go. There’s some weird stuff (like custom entities) in XML!

@wooorm
Copy link
Member

wooorm commented Apr 30, 2018

@revolunet Are you into working on this?

@revolunet
Copy link
Author

nope, didnt had a chance yet :/

@wooorm
Copy link
Member

wooorm commented May 2, 2018

Oh that's okay! I think it's pretty interesting tho!

@wooorm wooorm added the 🧘 status/waiting This may go somewhere but needs more information label May 11, 2018
@Tsabrandon
Copy link

Is there any update on this one? @revolunet

@revolunet
Copy link
Author

nothing new on my side sorry

@ChristianMurphy
Copy link
Member

https://github.com/nashwaan/xml-js looks promising as a starting point.

@wooorm
Copy link
Member

wooorm commented Jan 5, 2019

Nice, but can’t see anything about positional info?

And how about the naming:

  • processor: rexml?
  • st: xast?

@ChristianMurphy
Copy link
Member

ChristianMurphy commented Jan 7, 2019

processor: rexml?

that may cause confusion with: https://github.com/ruby/rexml

@wooorm
Copy link
Member

wooorm commented Jan 9, 2019

Hmm, different ecosystem plus not many stars, I think it’s fine to reuse that name?

@wooorm wooorm added the 💬 type/discussion This is a request for comments label Aug 10, 2019
@ChristianMurphy
Copy link
Member

https://github.com/syntax-tree/xast

@wooorm
Copy link
Member

wooorm commented Feb 16, 2020

Parsing can now be done with syntax-tree/xast-util-to-xml and serialising with syntax-tree/xast-util-to-xml, so that means the building blocks for rexml (working title?) are there.

However, I’m not sure how well rexml fits in the list of remark, rehype, retext (, redot), and thus unified. I think that’s because XML is data, the others are content. A rehype plugin has knowledge of the semantics of nodes, what they mean, to do a task (find all headings, sluggify them, add the slug as an id)—but XML doesn’t really have this.

So, I’m seeing use cases for xast and xast utilities:

  1. to parse and inspect data (I was recently parsing unicode-cldr)
  2. to construct and serialize data (EPUB files have lots of manifests in XML)

…and I do see a case of going from HTML -> XML with rehype-parse, rehype-rexml, rexml-stringify or so (EPUB books use XHTML)

But I don’t really see the case where a whole unified pipeline would be useful:

unified()
  .use(rexmlParse)
  // …what plugins are useful here?
  .use(rexmlStringify)

I’m wondering, what use cases do you folks have for rexml? Should it exist?

@revolunet
Copy link
Author

Thanks for the addition !

My use case was simply to parse some XML and store it as AST so i can use select or other utils to play with the tree

@loganpowell

This comment has been minimized.

@ChristianMurphy

This comment has been minimized.

@loganpowell

This comment has been minimized.

@ChristianMurphy
Copy link
Member

this was added with https://github.com/syntax-tree/xast, https://github.com/syntax-tree/xast-util-from-xml, and https://github.com/syntax-tree/xast-util-to-xml this idea is now implemented. 🎉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🧘 status/waiting This may go somewhere but needs more information 💬 type/discussion This is a request for comments
Development

No branches or pull requests

5 participants