*
The moose likes XML and Related Technologies and the fly likes Working with XML files, using Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Working with XML files, using Java" Watch "Working with XML files, using Java" New topic
Author

Working with XML files, using Java

Rudy Rodriguez
Greenhorn

Joined: May 01, 2009
Posts: 29

Hi

I am working on a application that is reading in information from a excel file and updating a XML file with the data.
The XML file is in a specific fomat, that I want to keep after I modify it with the data from the Excel spreadsheet.

I am able to read in and modify that particular parameters of interest, however the new XML generated is of a generic XML file format that is unusable for another application.

I want to modify the XML file, but keep its original XML format.

Thanks


I am attaching my code to this email.



Original XML file format



Modified XML file format

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I don't see any difference between those two formats. Could you explain in a bit more detail what you think your problem is?
Rudy Rodriguez
Greenhorn

Joined: May 01, 2009
Posts: 29
Hi

The original XML file begins with :
<?xml version="1.0" standalone="no"?>
<!DOCTYPE entity PUBLIC "-//UC Berkeley//DTD MoML 1//EN"
"http://ptolemy.eecs.berkeley.edu/xml/dtd/MoML_1.dtd">

With the Property tags defined as <property name=>

For example :
<property name="_createdBy" class="ptolemy.kernel.attributes.VersionAttribute" value="8.0.1">
</property>

While the new XML file begins with :
<?xml version="1.0" encoding="UTF-8" standalone="no"?><entity class="ptolemy.actor.TypedCompositeActor" name="vehiclemodel_2">

Its property tags are defined as :
<property class="ptolemy.kernel.attributes.VersionAttribute" name="_createdBy" value="8.0.1">
</property>

I am using a program name Ptolemy simulation engine to process information, that will use this XML file.
However, when the XML file is modified this makes the XML file unable to be used by the Ptolemy software.

Rudy
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Well, the output document declares its encoding and the input document doesn't, but that's not a significant difference according to XML. And the attributes in the output document are in a different order to the attributes in the input document, but again that's not a significant difference either.

So you're going to have to find out from this Ptolemy product exactly what its problem is.
Rudy Rodriguez
Greenhorn

Joined: May 01, 2009
Posts: 29
Thanks

I would like to know when I modify a attribute in a XML, is it possible to keep the original format of the XML file.

Rudy
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Yes, it is. And as I explained, you are in fact doing that.

Remember that XML specifies the meaning of a document, and that many different documents may have the same meaning. For example section 3.1 of the XML Recommendation says

Note that the order of attribute specifications in a start-tag or empty-element tag is not significant.


In other words, two documents which differ only in the order of attributes in an element mean the same thing and must be treated as if they were equivalent. Software which requires a particular order of attributes is in violation of the XML Recommendation.

So I say again, if you're dealing with XML you don't have a problem. Some other software may have a problem, but then it's not XML-compliant.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Working with XML files, using Java
 
Similar Threads
Java XHTML DOM: Exception in getElementById with XPath
code to read the xml and also overide the value of certain attributes in xml at runtime itself
Deleting child nodes from an xml
problem in modification of the value in xml file
Getting the arraylist through session