aboutsummaryrefslogtreecommitdiff
path: root/textproc/jaxup/files/DOMXUpdater.java
blob: 7cae303e8c1a7cfe3ba74588f7d1394d636f2363 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
 * DOMXUpdater: a command-line XUpdate processor.
 */
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;
import org.jaxen.dom.DocumentNavigator;
import org.jaxup.dom.DOMDocumentUpdater;
import org.jaxup.xupdate.XUpdate;
import org.w3c.dom.Document;

public class DOMXUpdater
{
	public static void main(String[] args)
	{
		if (args.length != 2)
		{
			System.out.println("usage: DOMXUpdater <source document url> <XUpdate document url>");
			System.exit(1);
		}

		try
		{
			DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
			factory.setNamespaceAware(true);
			DocumentBuilder builder=factory.newDocumentBuilder();

			Document doc=builder.parse(args[0]);
			Document updateDoc=builder.parse(args[1]);

			XUpdate updater=new XUpdate(new DOMDocumentUpdater(), DocumentNavigator.getInstance());
			updater.runUpdate(doc, updateDoc.getDocumentElement());

			OutputFormat o=new OutputFormat("xml", "ISO-8859-1", true);
			o.setIndenting(true);
			o.setIndent(2);
			o.setPreserveSpace(true);
			XMLSerializer serial=new XMLSerializer(System.out, o);
			serial.serialize(doc);
			System.out.println();
		}
		catch (Exception e)
		{
			e.printStackTrace();
			System.exit(1);
		}
	}
}