RemoveChildren Method

Removes the children of the elment as the specified XPath.

Syntax

xml.removeChildren([callback])

Callback

The 'callback' parameter specifies a function which will be called when the operation completes (or an error is encountered). If the 'callback' parameter is not specified, then the method will block and will not return until the operation completes (or an error is encountered).

The callback for this method is defined as:

function(err){ }

'err' is the error that occurred. If there was no error, then 'err' is 'null'.

'err' has 2 properties which hold detailed information:

err.code
err.message

Remarks

This method removes the children of the element specified by XPath.

When called the class will remove the children of the element from the internal representation of the XML (the DOM). The element itself remains, with no children. This may be used at any time after Parse returns, or from within the EndElement event as a document is parsed in order to remove sections of a document that will not be needed later. By removing unnecessary elements from the DOM memory consumption is reduced and overall performance is improved.

RemoveChildren Example:

Given the XML

<food>
	<fruits>
		<apple>
			<color>red</color>
		</apple>
		<banana>
			<color>yellow</color>
		</banana>
	</fruits>
</food>

This code removes the children of the apple element while leaving the apple element in place.


xml.XPath = "/food/fruits/apple";
xml.RemoveChildren(); 

The XML stored in the DOM is now:

<food>
	<fruits>
		<apple>
		</apple>
		<banana>
			<color>yellow</color>
		</banana>
	</fruits>
</food>

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks 2020 Node.js Edition - Version 20.0 [Build 8307]