Solved

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

Posted on 2008-10-28
1
1,110 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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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 will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now