Building an XML editor in java and RichFaces - java

I'm building an XML editor using the above technologies. In essence, I want to read in a whole XML file to a java object, and refer using this object to each element in the XML node tree (grouped into entries) to display the content locked, have separate padlocks for the user to click to 'unlock' an entry allow overwriting of the data, and to submit this entry. 'Add entry', 'Duplicate entry', 'Delete entry' are also functions I'd like to add.
I already use dom4j and XPath to access areas of the XML file so some of the work in theory is already done. Given the above, I was going to use these two together with inplaceInputs to allow the user to edit the XML and JSF validators to check the data coming in.
Is this the best way to approach this problem, or is there a more straightforward route than XPathing a whole record? I started looking at jaxb but I'm new at java and jsf but I've got the feeling I won't be by the end..
Thanks

You can try using SIMPLE FRAMEWORK API in java.It is dedicated for XML in java and will certainly suit your needs.You can access the entire xml BASED ON NODE,TRESS,CHILD.Morever writing and reading an XML is equally easy by using serializer and persister which will store the values in repsective setters and gettters.

Related

Is there any way to create a dynamic word document to an existing template in Java?

I need to automatically generate 4 different types of CVs using Java/Spring. The information is already in the database in a structured way. However, we need to generate a Word Document for 4 different types of CVs. If you have noticed in the Europass format there are sections like work-experience and education and training that need to be duplicated more than once.
I have seen a docx4j version , where creating an XML file and adjusting the word document to comply with that XML can make it work. However, what I can't seem to be figuring out for now, is how to add repeating sections, for example a list of experiences. Not only do I have to repeat the actual data, but I also have to duplicate the text in the existing template.
If any of you guys knows any other library/plug-in/tech that might help me to dynamically create a word document (the CV) using Java, please let me know.

Modify Wicket's XML Resource Bundle with Java internationalization (i18n)

In the resource XML there are all these values associated with keys.I want to modify a value associated with a key directly from Java.
For instance,I have <entry key="greetingMessage">Welcome to my app</entry> and this is displayed in the view,but also the message can be modified from the view and I want to be automatically updated in the XML.
I have managed to do this by parsing and changing the XML with javax.xml and org.w3c but I feel I am missing something.Does Java internationalization or Wicket framework have a method to achieve this?
Wicket only has facilities to read i18n resources (for example, XmlFilePropertiesLoader). Properties.storeToXML() is not used in Wicket 6 code, while Properties.loadFromXML() is used to read those XML properties files.
To store those translations back to XML files you need to be cautious. At least, synchronization has to be implemented to make sure that simultaneous edits are not lost.
I'd not recommend to store the edits in XML (especially in the original XML files). It seems better to have two levels of properties:
First, immutable, level, is based on the original (and immutable) XML files.
Second level consisting of 'edits' acts like a patch over the first level. It may be stored in a database which is much more convenient for storing a constantly updating data (like such edits).

Writing a format updater in java?

I have an application that reads an input xml file and builds an emf/ecore model (which can be stores as a xmi file).
The input format file is "locked" meaning that no new tags, attributes etc not already defined in the file can appear. But the number of existing tags or values of attributes can change.
Now I would like to support the following scenario:
1) User imports xml_01 and an emf model is build.
2) User modifies the model and store it to disk.
3) User imports xml_02 which is almost identical to xml_01 but with some additional nodes.
4) During the second import the existing model should be updated based on the additional content from xml_02 and possible conflicts reported to the user.
Now I have an idea on how to get started with this - basically writing the updater from scratch.
But are there any tools/libraries that can be used to help writing this kind of updater - especially when it comes to modifying an emf model?
I do not know of any third party libraries that can directly do this. But from what I understand you can use SAX parsers to parse the XMLs and implement your own Handler for the required functionality.

Searching XML through Java Codes

I have around 30 xml files with proper formatting and huge amount of data. I want to search these xml files for specific data retrival. Can you suggest any site or blog which i can use as aguideline to solve my problem.
I need to search inside of each tag for the keyword provided by the user. And also sometime the specific tag name which will return the content inside the tag according to the user request.
example : a.xml, b.xml, c.xml
inside a.xml
<abc>
some content
</abc>
User may search for abc the tag or some keyword inside the content. In both cases it should return the content or if more than one match then it should return the link for both by clicking which the user can see them one by one.
I'd recommend using XPath, which is a SQL-like language for searching in XML documents
http://www.ibm.com/developerworks/library/x-javaxpathapi.html
Use a SAX parser (no need to go back and forth within the documents plus huge amount of data hence don't use a DOM parser).
See this link for a tutorial.
You may store your XMLs into an XML database (for example eXist), and then query it using XQuery.

validating xml in java as the document is built

I am working on converting an excel spread sheet into an xml document that needs to be validated against a schema. I am currently building the xml document using the DOM api, and validating at the end using SAX and a custom error handler. However, I would really like to be able to validate the xml produced from each Cell as I parse the excel document so I can indicate which cells are problematic in a friendlier way.
The problem that I am currently encountering, is that after validating the xml for the simple types, once they are built into a complex type, all the children nodes get validated again, producing redundant errors.
I found this question here at SO but it is using C# and the Microsoft API.
Thoughts? Thanks!
Sorry, but I don't see the problem. You are producing the XML, so what's the point in validating the XML while you produce it?
Are you looking to validate the cell contents? If yes, then write validation logic into your code. This validation logic may replicate the schema, but I suspect that it will actually be much more detailed than the schema.
Are you looking to validate your program's output? If yes, then write unit tests.
You could try having your parsing code fire SAX events instead of directly constructing a DOM. Then you could just register a validating SAX ContentHandler to listen to it and have that build your DOM for you. That should detect validation errors as they're encountered.
So the solution that I decided to go with and am almost finished implementing, was to use XSOM to parse the XSD. Than when parsing the Excel file, I looked up the column name in the parsed XSD to pull out the restrictions (since the column headers map to simple types in the XSD) and than did manual validation against the restrictions. I am still building the tree so that at the end of it I can validate the entire XML tree against the XSD since there are some things that I can't catch at the Cell level.
Thanks for all of your input.
Try building schemas at multiple levels of granularity. Test the simple (Cells) ones against the most granular, and the complex ones (Rows?) against a less granular schema that doesn't decompose the complex types.

Categories

Resources