NaturalIntelligence / fast-xml-parser

Validate XML, Parse XML and Build XML rapidly without C/C++ based libraries and no callback.
https://naturalintelligence.github.io/fast-xml-parser/
MIT License
2.53k stars 303 forks source link

Parse text value with an included (sub-) node #558

Open araareon opened 1 year ago

araareon commented 1 year ago

Description

My source file has a text value which is "interrupted" bay another node . I would like to maintain that structure. The lib seems to wipe away the inner structure and creates a #text with the whole word "(Jahre)

Input

   <source> ( <x id="INTERPOLATION" equiv-text="{{ alter }}"/> Jahre ) </source>

Code

 const parserOptions = {
    parseTagValue: true, //default
    trimValues: true,
    ignoreAttributes: false,
    attributeNamePrefix : "@_"
}

Output

  <source>
          <x id="INTERPOLATION" equiv-text="{{ alter }}"></x>
(Jahre) </source>

expected data

I would like to keep the source data structure with the "(" before the <x..> and "Jahre )" after the </ x>

Just like the source

How can i achieve this?

Would you like to work on this issue?

Bookmark this repository for further updates.

github-actions[bot] commented 1 year ago

I'm glad you find this repository helpful. I'll try to address your issue ASAP. You can watch the repo for new changes or star it.

amitguptagwl commented 1 year ago

There can be multiple possibilities. And for each, different options. You can probably try preserveOrder option. Please read docs for more detail and options.

araareon commented 1 year ago

preserveOrderworks but the everything else gets ugly. This would be cool: #462 Perhaps it is possible with tagvalueProcessor/attributeValue processor..i will try