oozcitak / xmlbuilder-js

An XML builder for node.js
MIT License
921 stars 110 forks source link

get elements value #163

Closed 1nternerd closed 7 years ago

1nternerd commented 7 years ago

Hey,

sorry to bother you, but I cant seem to find a way to get the text value of some already created node. im trying to append text in a parsing process, so it would be great to be able to just append or rewrite this one element.

my current situation:

lets say i find an observation block in a flatfile, i create the corresponding xml representation and it contains a tag like so:

<observation-text>text</observation-text>

after some lines in this flatfile, there might be the need to add text to this element:

<observation-text>text more text concerning this observation</observation-text>

is there a way to do this or would it be better if i cached all the text belonging to one observation and when im done i create the element?

thanks in advance!

oozcitak commented 7 years ago

You could keep a reference to the node and modify it later:

var root = builder.create('mydoc');
var item = root.ele('observation-text');
item.text('text');
//
// later
//
item.text('more text concerning this observation');
1nternerd commented 7 years ago

Thanks @oozcitak that did the trick! 👍