Programming

 

Generating sample XML from XSD or DTD in Eclipse

XMarks XML schema diagram v1.1
Image by carol shergold via Flickr

Feature is useful if you are writing your XSD schema files or you have XSD schema files and want to create sample XML files for schema elements. Process is the same for generating sample XML files from DTD files.

How to do it. Simple.

  1. Create a project and add, import or somehow see created, generated XSD files in Project Explorer.
  2. Select your desired XSD file.
  3. Right-click and choose Generate->XML File
  4. New XML File wizard will pop-up where you define where generated file should be saved and what should be it’s name. When desired information is input-ed press Next.
  5. In Select Root Element window choose root element of your sample XML file. Root element can be any element defined in XSD file you choose to use for generation of the sample XML.
  6. Set content options and pay special attention to optional attributes & optional elements. Check those if you would like a complete XML sample.
  7. Name-space information is populated with name-spaces defined in chosen XSD file. You can manipulate the existing name-space information by changing prefix, adding additional name-space or create new name-space.
  8. Once you are satisfied click Finish.

And presto you have your blank sample XML. Edit it with the information you wish to present and your sample XML is ready. No XMLSpy or any other commercial tools required.

 

XMLbeans scomp fails with “java.io.IOException: CreateProcess error=2, The system cannot find the file specified”

Beans Alubia pinta alavesa. Álava, Spain.
Image via Wikipedia

If you are using xmlbeans on Windows to bind your schema to Java types then you are probably using a tool bundled with the distribution called scomp or Schema Compiler. For schema compiler to work you will need to correctly setup computer environment by installing JDK. You can follow through the following check-list to detect if any additional installation steps are required on your machine setup:

  • Start->Run->type cmd and type java in the command line. If no error then your setup is correct; otherwise setup JAVA_HOME and add %JAVA_HOME%/bin to your Path environment variable and try again.
  • Start->Run->type cmd and type scomp in the command line. If no error then your setup is correct; otherwise setup XMLBEANS_HOME and add %XMLBEANS_HOME%/bin to your Path environment variable and try again.

Then run scomp. Depending on your wishes you will probably wan’t to create a .jar file of the Java types scomp compiles from schema files. I used the following command line:

scomp -d schema -src src -out my_schema_1_0_0.jar ./schema/mySchema.xsd

where mySchema.xsd file was stored in ./schema folder.

If you get my_schema_1_0_0.jar, by some coincidence then kudos to you, but most likely you will end up with something similar to this error:

Time to build schema type system: 1.282 seconds
Time to generate code: 18.687 seconds
java.io.IOException: Cannot run program "C:\your current path\javac": CreateProcess error=2, The system cannot find the file specified
java.io.IOException: CreateProcess error=2, The system cannot find the file specified
java.io.IOException: Cannot run program "C:\your current path\javac": CreateProcess error=2, The system cannot find the file specified
 at java.lang.ProcessBuilder.start(Unknown Source)
 at java.lang.Runtime.exec(Unknown Source)
 at java.lang.Runtime.exec(Unknown Source)
 ... 6 more
BUILD FAILED

Read on to solve this problem.

READ MORE

 

Workaround – IE6+ local script restrictions

Internet Explorer Mobile
Image via Wikipedia

In the early years of internet growth I had the opportunity to work as a web designer. As web designer I designed a web page. Simple not too complicated. And it rocked. Literally. Admired by many. By today’s standards web page was LAME. Totally. But it used an interesting JavaScript. As now I was using Linux at the time and I replaced the default mouse cursor with cool animated Linux penguin. The penguin was fabulous. The animation was interesting. The script was flawless. It did not bother me that the script was not working in IE because at that time netscape ruled the web and Microsoft did not bother to make it work on Linux1.
READ MORE

  1. strange, that they still live with the same delusion []
 

Sketchy musical factory

The Abstract Factory pattern illustration, UML...
Image via Wikipedia

Today we will take a look at the abstract factory design pattern. This design pattern continues the series of creational patterns.

In previous article we have talked about factory pattern. We have learned that factory pattern deals with creation of other objects. Now we will extend that knowledge with the abstract factory pattern which provides a way to group together or rather encapsulate a group of individual factories that create objects with common theme.

Normally we would code a client software to create a concrete implementation of the abstract factory and then use generic interfaces to create concrete objects that are tuned to specific theme but, the client does not know about which concrete object will it get from each of the internal factories since it uses generic interfaces of the factory product in question. Details of the implementation of concrete objects are hidden by the internal factories.

READ MORE

 

Fungi Factory without abstraction

Next creational pattern that we will have a closer look at – is Factory pattern. There are at least two different Factory patterns, Factory method and Abstract Factory. In this installment we will be looking at the Factory method pattern.

READ MORE

Support Us