Dataset::getPath returns the path to the dataset backing file on disk, not an XPath in an XML dataset.
To change an existing dataset, you go through a few steps:
1. obtain the dataset, e.g. var databaseDataset = job.getDataset("MPXMLdirect");
2. check the dataset type, e.g. if ( databaseDataset.getModel() == "XML" ) { ... }
3. if it's XML, use the functions in the XML scripting module to update and save the file; be sure to save it to the correct backing file path.
(this is untested pseudo code, don't take it as gospel)
Code: Select all
var databaseDataset = job.getDataset("MPXMLdirect");
if ( databaseDataset.getModel() != "XML" )
{
job.fail( "oops, not xml" );
}
// it's xml, create an xml Document:
var theXMLDoc = new Document( databaseDataset.getPath() );
// create a new element:
var theNewElement = theXMLDoc.CreateElement( "MyNewElement" );
// add the new element to the xml root:
theXMLDoc.getDocumentElement().appendChild( theNewElement );
// save the file; note that we save to the original dataset path!
theXMLDoc.save( databaseDataset.getPath() );