xml-js icon indicating copy to clipboard operation
xml-js copied to clipboard

XML > JSON: How do I 'intercept' processing of a specific node?

Open blaasvaer opened this issue 1 year ago • 0 comments

I need to strip a node for HTML tags ... how would I go about doing that? I've spent a couple of hours trying to 'figure' out the docs and trying all sorts of things by basically guessing, as the docs are clearly written by the same guy who wrote the lib. But I have had absolutely no success in using any of that information.

I have a node that looks like this:

<text>Ya da <grouptext>Ga Ba</grouptext>.</text>

I need to strip the text node for grouptext nodes (leaving out that 'level').

Now, from the docs I'm getting the impression I can add a custom function to the config:

var xmljs_options = {
	compact: true,
	spaces: 2,
	textFn: function ( value, parentElement  ) {
		// How can I access the text node on the parent element
		// and modify the value?
		if ( parentElement.nodeName? === 'text') {
			// strip tags and return modified value
		}
	}
};

blaasvaer avatar Sep 25 '23 13:09 blaasvaer