Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't working #1

Closed
triple1 opened this issue Aug 3, 2012 · 1 comment
Closed

Don't working #1

triple1 opened this issue Aug 3, 2012 · 1 comment

Comments

@triple1
Copy link

triple1 commented Aug 3, 2012

My steps:

  1. sudo apt-get install node
  2. sudo apt-get install npm
  3. npm install asyncxml

So i try run exmaple:

asyncxml = require('asyncxml')
xml = new asyncxml.Builder({pretty:true})
xml.on('data', function (chunk) {
console.log(chunk);
})
// build some xml
xml.tag("xml", {version:"1.0"})
.tag("list")
.tag("entry", function () {
this.attr('id', 1)
}).up()
.tag("entry", {id:2}, "foo").up()
.up()
.up()
.end()

  1. node example.js

but i can't see xml text in my terminal.

@dodo
Copy link
Owner

dodo commented Aug 3, 2012

you're listening for the 'data' event, which is never emitted, because you don't use the write method. :P
you can find a list of all events here: https://github.com/dodo/node-asyncxml#events

if you want to use it just like a nodejs stream, you should have a look at: https://github.com/dodo/node-dt-stream

in your case this would look like:

asyncxml = require('asyncxml')
streamify = require('dt-stream')
xml = new asyncxml.Builder({pretty:true});
streamify(xml).stream.on('data', function (chunk) {
    console.log(chunk);
});
// build some xml
xml.tag("xml", {version:"1.0"})
    .tag("list")
       .tag("entry", function () {
            this.attr('id', 1)
        }).up()
        .tag("entry", {id:2}, "foo").up()
    .up()
.end()

please note that it will raise a warning because of the this.attr('id', 1) because the time its used the open tag of the first entry is already rendered and emitted as data, so its not possible to change it.

i did this to be able to stream faster (streaming can already start with the element opener).
i'm open for any suggestions to do this in a better way.

if you have any question, feel free to just shot them :)

@dodo dodo closed this as completed Mar 8, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants