I was wondering how you would go about writing and the reading from an .XML file using the Java library Slick2D.
I have googled for the last couple of days and have found nothing succinct and simple that explains what I'm looking for.
I am looking for 3 things:
How to create an .XML file (would be awesome to be able to search a directory to see if there is an existing file and only create a new file if one does not already exist.
How to write to the created .XML file.
How to read from the found .XML file.
The reason for this is that I'm trying to create a save/load class for a game.
Just a general snippet of code, that I'd be able to modify for my needs would be great even for a learning experience.
So now for my question, does anyone have any information that may help me on my quest to succeed in my above stated three goals?
For checking if a file exists you can use the exists() method of java.io.File. See this for more information.
I don't know if slick2d provides it own xml utilities but you should always be able to use the standard java ways of reading/writing xml. You can use the DocumentBuilder like shown in this tutorial or a sax parser like described here. If you need to work with complex xml structures it might be worth to look into jaxb.
Related
Using Java to write xml strikes me as perhaps not the best match. Is this just because it's new and unfamiliar, perhaps?
Rather than generating JAXB source code from xml might it not be more flexible to work with xml files directly? What I mean is, cannot the middle-man be cut out?
If JAXB can generate source code for the class files to manipulate xml might there a tool which uses JAXB without creating concrete boiler-plate?
If there's simply a mis-match making this impossible please elaborate. Or, if it's simply out of reach, what are the obstacles?
I'm looking for some info on how to create a .vsdx file in Java without any commercial libraries. According to other questions it seems to be pretty tough.
As a source we have a different, probably unknown file format called .epml that contains graphical information of EPCs which we should be able to convert to a .xml file. As far as I understand the .vsdx format so far, that's one of many files in the unzipped .vsdx required. I'd be glad if anyone could tell me about my options how to implement/create all the other files.
EDIT: The goal here is to be able to convert the graphic information of the .epml file so Visio is able to read & display it as in the source. Therefore, it doesn't have to be a .vsdx file if there are other possible options.
Thanks!
EPML is a not an unknown format, it is an interchange format for EPC tools. Just try to google it :)
I would suggest you convert your .epml files to .svg (there are free open source converters available, like epml2svg). Visio can read and show .svg files. Means - writing code does not seem to be required to achieve your goal (to convert .epml files to something Visio can show). AFAR there is online version of the tool as well - you upload EPML file, get back SVG, and just open it in Visio - that's it.
Side note - there are companies, like bpm-x for example, specializing in BPM tool-to-tool diagram conversion. Maybe they already have a solution for your original tool.
The .VSDX file is "office xml" format, that is also open and documented. But it's pretty tough to generate file from scratch, you are right. So in principle you could start with any code that is capable of handling open xml packages. Microsoft has OpenXML SDK, but that's .NET (MSDN HOWTO assumes you are using .NET, but explains basics of what the open xml package consists of)
AFAIK, for java, there are no open source visio libraries you could use. Java and Visio seem to live in parallel universes. The only viable commercial option I've heard of seem to be Aspose.
Interesting - whilst I cannot give a final answer, here are some thoughts:
Question 1: Why would you want to avoid commercial tools, when the final result file will require some - namely "Visio"?
1) Creating Visio files from XML:
Create template XMLs from a VSDX. Identify the files, that you need to edit. From what I've seen, these should be the masters and the pages files. Being able to make an XML from EPML, you should also know how to adapt it to a new structure.
This solution is probably by far the most tedious and less flexible.
2) Use Visio automation:
Presuming that the final document will need more than just graphics, namely shape data as well, an easier solution would consist of creating the graphics first
a) as SVG and import into Visio
b) even easier - automated drawing by Visio's automation capabilities (VBA, .Net, ...). The shapes to drop would already have been prepared as masters will all the relevant data and behaviour settings.
Then you would populate the data by means of one of the many data linking features (Wizard, Standard data linking, ODBC connections, etc.)
I have assignment to read XML file of University Schedule , there are class rooms, time , weeks, teachers and so on. And I have to read all of them and put them to Data Base. Edit: I have to read everything because that xml is messy and it is hard to recognize everything.
I am asking to you guys, because I am newb in Java and I would like if you guys will direct me in good way how to start everything, because I don't have any idea, from what I have to start.
Thank you.
A convenient way of reading xml-files with java is the JAXB(Java Architecture for XML Binding)
From there you could go with JDBC(Java Database Connectivity)
to save your Objects into a database.
Generally your question is very broad and should be divided into further sub-questions.
I'm a quite new to java world and I have a requirement of generating an .xml file from an .xsd file
I did some research and found that 'jaxb' could do it. And I found some example too, but the problem is, almost all the examples uses 'xjc' tool to do this. But I want a way to do this through my java code.
Os this possible?
if yes, I'm thinking something like this, from my java code
load the .xsd file
generate the .xml
save the .xml file
Can someone direct me to a good resource and or tell me if my thinking is wrong
I've had good experiences using XMLBeans, however I've always had the XSD available at compile time. It integrates nicely with Maven (plus potentially other build systems). The compilation produces a series of Java classes that can be used to construct an XML document that conforms to the XSD or process an XML file you've received.
You can potentially do some runtime processing of an XSD using the org.apache.xmlbeans.XmlBeans.compileXsd class, but I've never experimented with it. Just seen a reference from an FAQ.
I think the main problem is that to do it in a clean way you should have classes reflecting your xsd. Xsd defines a data model, so the important part is to recreate it with classes. If you want to do it dynamically it could be rather difficult. If you want to do it at compile time- jaxb is the way to go. There is very interesting article talking about problems related with parsing xml (it goes from a different perspective than you describe), but I think there is a wealth of knowledge to be learned from here:
http://elegantcode.com/2010/08/07/dont-parse-that-xml/
Good Afternoon in my timezone.
In my current web project, i have to write a flat file(with some fixed rules).After a web research i found a library which is called FlatWorm that help's me write flat files in a easy way.The problem is that there is a lack of information regarding the XML definition file.I have the FlatWorm API, but there is nothing related with the XML definition file and all the tags and attributes that build it.
Anyone that use and knows about this framework can give me a clue ?
With best regards.
Thanks in advance
I would start by RTFMing. There appears to be a fair amount of information on there that should get you kick started, including some examples you could start by modifying.
Google suggests some other examples, such as, http://javaconfessions.com/2009/04/writing-flat-files-in-java-with.html and http://andreamoz.blogspot.com/2010/12/meet-flatworm.html
Unfortunately the DTD for the XML descriptor either never existed, or at least doesn't any more. If needed, I would look through the XML parsing source to see what the flatworm library actually makes use of.