This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Convert Data to XML File Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Convert Data to XML File" Watch "Convert Data to XML File" New topic
Author

Convert Data to XML File

JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
I am really new to XML technologies and need lots of quidance.

If I have some data that come in the format shown below (only one record is shown):


1. What technology I should use to convert that record to a XML file?
2. Is there an example I may see and study?

Thank you.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
The eXtensible Markup Language (XML) is a language used for creating "markup languages", e.g. WSDL, SOAP, FpML, XMI, etc. A good starting point would be to learn what a "markup language" actually is. XML is a simplified version of SGML.

In regards to technologies for creating XML-based documents (data), there are many. Basically, any programming language can be used to programatically create an XML-based document (data). However, before you start to think about creating documents in a particular markup language, you first need to create the language itself. This can be accomplished with either a XML DTD or an XML Schema. There is a lot to learn. So I suggest that you take it slowly.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12760
    
    5
This free on-line book is very complete and is loaded with examples.

Bill
JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
Thanks for your feedbacks.

I cannot take it slowly. I have a task at work to perform. I have gone through a quick JAXB tutorial.

The XML file to which I convert the data, which are either in text or in bean, has its own schema. Do you have any suggestion of the technology to use? Is it the XSLT processor? Are there any code examples?

Thank you.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
I would suggest that you inform the individual that assigned you this task that you are really new to XML and don't know how to write XML data conversion code. This is not something simple that can be quickly learned via forum postings. It is best to be honest about your abilities. Good luck!
JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
Nobody is dishonest.

The entire development team is entering a new territory. None of us is expected to know the technology. However, nobody is supposed to take it slowly.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Sounds good. Perl is a strong tool for writing data manipulation software. If you want to attempt to write code for your stated requirements using Java, you should learn the java.util.regex package. Regardless of the technology used for creating the XML-based document, you still have to either (1) create a markup language that defines elements, attributes and a structure, or (2) choose an existing markup language.

Aside, the Java Architecture for XML Binding is an API for accessing data that is already in an XML-based format.

An XSLT Engine is also for typically processing data that is already in an XML-based format.

Good luck!
JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
Is this the right approach? -- Convert the Java bean object to XML using JAXB, and then use XSLT to convert this XML to the format I actually want.

Please correct me if I am wrong - JAXB “forces” the Java class to use the exact element names defined in the target XML file. However, the element names in target XML file may not be exactly the same as those defined in the data model. XSLT enters the picture because XSLT can do element to element mapping.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Is this the right approach? -- Convert the Java bean object to XML using JAXB, and then use XSLT to convert this XML to the format I actually want.


First, there is no single "right" approach to anything. In software design there are many approaches to a requirement. Design skill is measured by an individual's ability to select one that is "best" for a particular situation and to do this on a consistent basis.

In regards to creating a CSV record (as shown above) using data from an object, you can simply create the record using the data directly from the object. There is no need or purpose to create an XML version.

This is not the same as the topic of this post. This post is about creating a XML-based document from the CSV record (as shown above.) Not creating a CSV record from an object's data.

Keep in mind that writing code with XSLT is no simple task and typically will required seasoned programming skills for complex conversions. It looks like your group needs to hire a consulting team to guide you as you begin to learn XML programming. Also, if you rush through this without taking it slow, you will most likely get it wrong and waste time and money.

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Convert Data to XML File
 
Similar Threads
Parsing BLOB datatype
Checking EOF with raf.readShort()
issue with special characters with sax parser
URLyBird search for the database records issue - advice needed
Converting CSV to XML