Comments (8)
What result are you expecting? I'm getting the same result in previous versions of xml2json
and nodejs. The reason is that the parser doesn't know how to treat that object, it could be handled as an attribute or as an element value. You can give the parser a hint by changing your object like:
{ foo: {$t: 'bar'} };
from node-xml2json.
Yeah that's what I've been using so far with this library. I was hoping for a cleaner way to handle regular Object -> XML conversion, because in order to use this library I need to transform all my Objects before converting them to XML. Is there no cleaner way to do this?
from node-xml2json.
How do you think that cleaner way would be?
from node-xml2json.
why not like this:
{
foo: {
'$attr': 'attributes go here',
bar: 'baz'
}
}
that way objects without attributes don't require any extra work.
from node-xml2json.
What is the xml that you would expect as output for
{ foo: 'bar' }
from node-xml2json.
<foo>bar</foo>
from node-xml2json.
json2xml parser was designed to get along with xml2json. As I said above, there is no way for the parser to know that
{ foo: 'bar' }
should be translated to
<foo>bar</foo>
For that purpose you need to hint the json2xml parser using this form instead:
{ foo: {$t: 'bar'} };
which I consider compatible with xml2json and cleaner than
{
foo: {
'$attr': 'attributes go here',
bar: 'baz'
}
}
That said, I'll close this issue and considerer it invalid unless you have a better proposal to disambiguate the json string and at the same time get along with the xml2json parser.
from node-xml2json.
BTW, this parser behaves like you want: https://gist.github.com/3738875
from node-xml2json.
Related Issues (20)
- Not able to install npm i xml2json HOT 3
- Xml2json library throw error window object in node
- r
- Using a Webassembly port of expat instead of compiling the expat binary
- import instead of require? HOT 2
- Feature proposal: support for tag name processors
- Feature proposal: exclude tags
- ToJson options lost comma
- toJson exception - "not well formed"
- not building with nodejs 12 HOT 43
- upgrade angular version HOT 1
- TypeError when i use it in a vue project HOT 3
- CDN
- toXml converts all the child nodes to attributes HOT 1
- documentation for arrayNotation individual fields HOT 1
- npm ERR! [email protected] install: `node-gyp rebuild` HOT 5
- invalid ELF header HOT 1
- Deprecated Dependencies Joi and Hoek
- What is the meaning of $t in reversible parsing? HOT 2
- Options reversible and alternateTextNode are not compatible
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-xml2json.