Revision 479 tmp/org.txm.groovy.core/src/groovy/org/txm/importer/SetNewXmlDocumentRoot.groovy

SetNewXmlDocumentRoot.groovy (revision 479)
1 1
package org.txm.importer
2 2

  
3
import javax.xml.parsers.*
4
import javax.xml.transform.*
5
import javax.xml.xpath.*
3
import java.io.File;
6 4

  
7
import org.txm.importer.PersonalNamespaceContext
8
import org.txm.utils.xml.DomUtils
9
import org.w3c.dom.Document
10
import org.w3c.dom.Element
11
import org.w3c.dom.Node
5
import org.w3c.dom.Document;
6
import java.io.File;
12 7

  
8
import org.w3c.dom.Document;
9
import org.w3c.dom.Element;
10
import org.w3c.dom.Node;
11

  
12
import javax.xml.parsers.*;
13
import javax.xml.xpath.*;
14
import javax.xml.transform.*;
15
import javax.xml.transform.dom.DOMSource;
16
import javax.xml.transform.stream.StreamResult;
17
import org.txm.importer.graal.PersonalNamespaceContext;
18

  
13 19
class SetNewXmlDocumentRoot {
14 20
	public static boolean process(File xmlfile, String xpath) {
15 21
		DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
16 22
		domFactory.setNamespaceAware(true); // never forget this!
23
		domFactory.setXIncludeAware(true);
17 24
		DocumentBuilder builder = domFactory.newDocumentBuilder();
25
		
18 26
		Document doc = builder.parse(xmlfile);
19 27
		Element root = doc.getDocumentElement();
20 28
		
......
31 39
			document.setXmlStandalone(true);
32 40
			Node adopted = document.adoptNode(node)
33 41
			document.appendChild(adopted)
34
			return DomUtils.save(document, xmlfile);
42
			return org.txm.utils.xml.DomUtils.save(document, xmlfile);
35 43
		}
36 44
		return false;
37 45
	}

Also available in: Unified diff