tags:

views:

23

answers:

3

Hello everybody,

I have an XML file, let's call it file A, and another XML file, B.

I need to make an import tool which will permit me to take the content of the file A, and put it in the file B. The two syntaxes are totally different. The file A is used in a web app, that will integrate an other tool which describe the same thing with the syntax of the B file. Converting the old file to the new format need to be done so it can still be read after integrating the new tool.

For exemple I would say that file A is like:

<house> <windows>3</windows> <doors>2</doors> </house>

And the file B is like:

<house windows="3" doors="2"/>

How could I handle this? There is even some attributes or tags that are in the first file and not in the other.

I thought about using something like ATL, that I used during my studies for a research program, I don't know if it is the best way to do this.

Please excuse my english, which is not very good, I am working on it.

Thank you

+1  A: 

Look at XSL - it is designed exactly for this kind of scenario, translating one XML dialect to another.

Most platforms and modern languages have tools to load source XML and use an XSL file to transform it to another XML dialect.

Here is a tutorial for using XSLT in java.

Oded
Thank you very much I will see that right now. I will use Java to write my tool so yes I will have the tools to load the XML at less. For using XSL I never did it with Java. I will look into it.Thank you!
Duke
@Duke - added a link to a java XSLT online book/tutorial
Oded
+1  A: 

XSLT should be able to help you here. The w3schools tutorial should give you a good start.

XSLT stands for XSL Transformations. In this tutorial you will learn how to use XSLT to transform XML documents into other formats, like XHTML.

ChrisF
Hello, thank you very much for your answer. I need to translate XML to XML in fact, but with a different syntax. I will have a look anyway on XSLT. Thank you again!
Duke
@Duke - you define the output of the XSLT, it can be XHTML or it can be other XML.
ChrisF
My bad, it is XSLT that I need to use.
Duke
@ChrisF - Thank for your help, I will read the doc right now.
Duke
A: 

This might help :

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  <xsl:template match="/">
    <xsl:for-each select="house">
      <house windows="{windows}" doors="{doors}" />
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>
hoang