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

What is the meaning of $t in reversible parsing? #196

Open
silversonicaxel opened this issue Aug 18, 2020 · 2 comments
Open

What is the meaning of $t in reversible parsing? #196

silversonicaxel opened this issue Aug 18, 2020 · 2 comments

Comments

@silversonicaxel
Copy link

I'm using this parser command parser.toJson(XMLContent, { reversible: true } and it is not yet totally clear to me why from this xml:

const xmlData = `<rss><title>example</title></rss>`

I reach this json:

const jsonData = { rss: { title: {"$t":"example"}}}

and not this json:

const jsonData = { rss: { title: "example"}}

Can someone explain me why, because documentation is lacking here, or at least, I was not able to understand the reason checking source code here

- reversible: If true, the parser generates a reversible JSON, mainly
              characterized by the presence of the property $t.

at line

* - reversible: If true, the parser generates a reversible JSON, mainly

thanks

@c4milo
Copy link
Contributor

c4milo commented Aug 18, 2020

It means text. When serializing it back to XML, it knows the value needs to be an element instead of an attribute.

@silversonicaxel
Copy link
Author

I guess it is not possible to remove it, right? Just checking, because the tree changes a according to the parameter reversible set to

false

- rss
  - title -> example

or

true

- rss
  - title
    - $t -> example

is there a way to have this documented maybe in README, including all small changes of the output JSON and make it crystal clear how the result is formatted?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants