File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes Xinclude, read 2 xml files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Xinclude, read 2 xml files" Watch "Xinclude, read 2 xml files" New topic

Xinclude, read 2 xml files

Zachi Kochman

Joined: Jun 18, 2006
Posts: 1
I have two xmls:
<?xml version='1.0'?>
<document xmlns:xi="">
<xi:include href="test2.xml"/>

i use the following java-DOM and my output include all nodes from first xml, and only first node from second xml (test2.xml), why???

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class XMLTest {
public static void main (String args[]) {

File docFile = new File("test1.xml");
Document doc = null;
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
doc = db.parse(docFile);
} catch (Exception e) {
System.out.print("Problem parsing the file.");

try {
Element root = doc.getDocumentElement();
NodeList children = root.getChildNodes();
for (Node child = root.getFirstChild(); child != null; child = child.getNextSibling())
if (child.getNodeName() != "#text")
System.out.println("childName=" + child.getNodeName() + ", childType=" + child.getNodeType());
} catch (Exception e) {
I agree. Here's the link:
subject: Xinclude, read 2 xml files
It's not a secret anymore!