Using of xml files in java programming - java

How to use .xml file in applet coding?
I want to save some context in .xml file in java-applet programming.....
I want to make the changes in that file through coding.
how to do this?

Your question is too broad, however if you are looking at how to process XML files with Java, then you should probably look at XML APIs for Java, for example jdom.
Tutorial: A good starting point to learn jdom

Try Apache XMLBeans. It converts between an XML file and a Java object so that you can work with the XML data in a simpler way.

You could also have a look at JAXB (http://jaxb.dev.java.net, http://en.wikipedia.org/wiki/JAXB) which also is a Java to XML binding component. Advantage: JAXB is part of SE version 1.6.

Related

How to convert the ConfigProperties_server1.props which is extracted from websphere using wsadmin to xml or json file?

This is the Jython script I have used to extract the ConfigProperties_server1.props file:
AdminTask.extractConfigProperties('[-propertiesFileName ConfigProperties_server1.props -configData Server=server1]')
Welcome to SO. The AdminTask.extractConfigProperties command has no option to control the format of the file. The option PortablePropertiesFile might sound promising, but instead it controls whether internal XMI ids are included in the props file. You're going to have to parse the properties file and convert it yourself, the syntax of the file is documented in this IBM KnowledgeCenter topic. Given the complexity of this task, you may want to edit your question and add some detail on what you're trying to accomplish by converting to xml or json format file, so perhaps the community might better help you.

Reading an XSD file to get all the elements and corresponding attributes in Java

My requirement is to read an XSD file and to get all its elements with corresponding attributes in java. I've been trying to convert my XSD file to a sample XML file as parsing an XML file to get all it's elements and attributes is easy. But so far I've been unable to find a good enough tool in java to programmatically convert my XSD to sample XML.
Is there any free and good java code available to convert an XSD to its sample XML?
Or else what is the way I can read all the elements and attributes that a sample XML would contain directly from the XSD file?
Thanks in advance!
Processing a raw XSD document as XML is quite tricky except in very simple cases.
Alternatives are:
(a) use an API for accessing a compiled schema (for example, there is such an API in Xerces)
(b) Saxon's schema processor can output an XML representation of the compiled schema, which is much easier to process than the raw XSD documents (for example, it combines everything into one document, and presents the relationship of elements to types in a uniform way).
The xsd format is perfectly valid XML, so you can parse an XML schema file with any xml parser.
Check this related post to get some code samples and ideas:
Java API to parse XSD schema file
Not sure if this solves the problem. I have similar requirement of accessing elements and attributes of xsd. Using Eclipse, the solution to create XML out of xsd is quite easy. I have a dynamic web project created and put my xsd in webcontent. Right click on XSD and there is option called 'Generate'. It shows 2 options to generate XML or JAXB classes. On clicking Generate XML, XML file is created from XSD. I hope you were looking for this solution.
There is a tool in java to convert my XSD to sample XML. You need to add jaxb-xjc (executable jar file) in the build path of your project.Once you are done with it just put the .xsd file in src, right click on it and find 'Generate' option, you can now find XML and Jaxb classes against 'Generate' option, Select Xml and get your XML file generated from .xsd.

How to get data from XSD file

I have an XML schema file. I want to use Java to open this file, find all elements, extract their names, and write them to a text file. I have tried various libraries, but I could not get this to work. Please suggest any libraries or other methods that will work.
XSD files are XML files so you can use any suitable XML processing library to parse it.
I don't think you'll find a library that exists for your purpose, you'll have to write one yourself. The XSD is simply an XML file that conform to the schema:
Traverse the file as normal using DOM or SAX or whatever your preference is.
I assume you are looking for the information conveyed by the XML Schema. I would recommend you the XSOM library, it takes away dealing with the XML itself; nonetheless, a basic understanding of what can be described by an XSD is most likely required.
Follow the user guide, there are some examples showing how to move towards what you need.

Generate HTML form based on XML

Is there any way apart of XSTL which dynamically generates HTML form based on metadata specified inside a XML? Take note that I'm developing a JAVA web application here. There won't be a lot of metadata inside the XML, which means that the XML is very simple. For worst case scenario, I would just build my own XML processor and generate HTML code with Java.
Consider JAXB to map your XML to Java objects. Once you have the data in Java, you can plug it into the templating engine of your choice.
One - less recommended - way is to display and style xml by use of css. See here for an example.
I would tend to go for XSLT if you need to go from one XML format to another one (HTML in this situation) in 99% of the cases. Not sure why you have that scratched as an option already ..
Cheers,
Wim
Its answered here : Generate HTML form dynamically using xml and reusable xslt.
And complete example is described here : http://ganeshtiwaridotcomdotnp.blogspot.com/2011/09/xslt-using-reusable-xsl-to-generate.html
You have to extend xsl file (answered there) for complex html forms

NSCoding to java

Hee,
I currently am using NSCoding to write my objects to data and save them to an file in objective-c.
Does anybody know if there is a way to use the same coding to decode the object structure in an Java application?
Thanks
Quite probably the easiest way is to use the third-party plist Java library.
Otherwise, you've got the problem that OS X supports two different types of property list — XML and binary. XML's easy enough and the relevant wikipedia page even includes a quick summary of the tags. You can use the command line tool plutil to convert any property list to XML format but the default is binary so that's not much help if you need there to be no manual step in between.
Apple don't seem to have a formal documentation of the binary format, but their code is open source so you can reverse engineer it from here.

Categories

Resources