Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-10-28
1
Medium Priority
?
1,115 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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…
This video teaches viewers about errors in exception handling.
Suggested Courses

730 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