Reputation: 1048
I'm using Apache Commons Digester (with annotations) in order to load an XML file into a Java class. Everything works correctly. Now, I need to update the XML file. I have to change (in Java) the value of a property, and then to write out the new XML file. How could I do? As far as I can see, Digester API is not designed for this purpose.
Edit: reading the answers, I understand that I did not give enough informations. My XML file is a configuration file for a program A, so I really need its content when I launch program A. Then, I have another GUI program B that is able to modify this configuration file, it just takes some input from the user and modifies the relative fields on the XML file.
Upvotes: 0
Views: 572
Reputation: 2836
As you have found, Digester is a read-only tool - it provides a mapping from XML to Java classes, but not the reverse. If you need to read the XML into Java classes and then write it back to XML again, I would suggest either:
Don't know enough about what you are doing to really recommend one of those approaches over the other.
If you don't actually need the data in Java classes at all and are just trying to transform it, then XSLT as @sharonbn says is also a good solution.
Upvotes: 0
Reputation: 14373
XML modification (usually called XML transformation) is best handled in XSLT standard. Apache Xalan is (one of) the Java libraries that implement this standard
Upvotes: 0