Im trying to parse XLIFF file using xml2js library. All is working fine but if I have something like that: <source>Welcome to <x id="INTERPOLATION" equiv-text="{{ title }}"/> my friend</source>
I will get [{"_":"Welcome to my friend","x":[{"$":{"id":"INTERPOLATION","equiv-text":"{{ title }}"}}]}]
. I am basically loosing order for the parts of the sentence. I would expect to get an array of 3 parts:
"Welcome to "
[{"$":{"id":"INTERPOLATION","equiv-text":"{{ title }}"}}]
" my friend"
But instead Im getting:
"Welcome to my friend"
[{"$":{"id":"INTERPOLATION","equiv-text":"{{ title }}"}}]
If I would try to recreate string again I would get <source>Welcome to my friend<x id="INTERPOLATION" equiv-text="{{ title }}"/></source>
Any idea how to solve it with this XML parser or any other?
you also might like txml. When using it like
txml.parse(yourXMLString)
, you get an object like this:I think it looks absolutely as what you are looking for. The three children inside the
source
, are very clean to use. Also, this parser is only 4kb in size and there is no need for native c compiling that will cause difficulties when running your app on a different architecture.Disclaimer: I am the author of txml, and this opinion might not be objective ;-)