Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How can I split an xml file into two based on contents?

Posted on 2008-10-28
1
Medium Priority
?
1,116 Views
Last Modified: 2013-11-23
I have one XML file  and I want to create two files out of it based on contents. Is there a way I can use Java and xslt to split one xml into two. Please look at the attached sample xml. I want to create two xml files out of it. One with type=city and the other with type=village
<main>
<item name="address" type="city">
<street>
  422 N California Dr
</street>
<city>
  San Francisco
</city>
</item>
<item name="address" type="village">
<street>
  422 Walrus Way
</street>
<town>
  Modesto
</town>
</item>
</main>

Open in new window

0
Comment
Question by:ddas_auth
1 Comment
 
LVL 8

Accepted Solution

by:
n_sachin1 earned 1500 total points
ID: 22828940
There are multiple ways of doing it (depending upon your choice of parsers), but the base workflow would be:
1. Parse the DOM tree using java. Write two DOM documents based on the type.
2. Use XPath to retrieve nodes of type 'City', flush it as a document. repeat the same with type 'Village'.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question