Wednesday, April 22, 2009

Smart and Simple XML Utility - v1.0

Smart and Simple XML Utility - v1.0

I have developed one small XML utility as well as eclipse plug-in that enables user to perform necessary operations on XML schema

Overview

A Smart and Simple XML utility performs following things,
1. XML validation with XSD schema.
2. Transform XML schema using XSL schema.
3. and Evaluate XPath Expressions.

This is an open source application that is written completely in Java SWT (Standard Widget Toolkit) which is fast, more responsive and lighter .

Standard Widget Toolkit (SWT) is a graphical widget toolkit for use with the Java platform. It was originally developed by IBM and is now maintained by the Eclipse Foundation in tandem with the Eclipse IDE. It is an alternative to the AWT and Swing Java GUI toolkits provided by Sun Microsystems as part of the Java Platform, Standard Edition.

SWT is written in Java. To display GUI elements, the SWT implementation accesses the native GUI libraries of the operating system using JNI (Java Native Interface) in a manner that is similar to those programs written using operating system-specific APIs. Programs that call SWT are portable, but the implementation of the toolkit, despite the fact that it is written in Java, is unique for each platform.

Release Notes :
This application still has a number of gaps in the functionality, but improvements are occurring all the time

Version 1.1.0
Feature:
Added Pretty Formatter to format the contents with correct indentation.

Version 1.0.0
Features:
1. XML validation with XSD.
2. XML Transformation using XSL.
3. XPath Evaluation.
4. Export all the data (XML, XSL/XSD & Result) to a file.

License:

1. Common Public License
2. Eclipse Public License 1.0

Download :

Version 1.1.0

https://xmlutility.dev.java.net/files/documents/10222/134058/XMLUtility_1.1.0.jar

Version 1.0.0

https://xmlutility.dev.java.net/files/documents/10222/132835/XMLUtility_1.0.0.jar

Requirements :

JDK 1.4 or higher installed on your system.

Help wanted!

mailto: xmlutility[at]dev[dot]java[dot]com

MySQL :: Supports XML Operations.

MySQL :: Supports XML Operations.

As of version 5.1.5, MySQL supports some functions for handling XML Data. Working with XML tends to be very data-oriented. In alot of cases, only a trivial mapping is required between the relational data and the xml representation. In these cases, it is certainly quite convenient to have all the tools that implement the mapping close at hand.

MySQL XML capabilities up to 5.0

In prior versions, MySQL XML support was limited to exporting data in XML format using the MySQL command line client. All you need to do is start the mysql client utilitiy with the --xml or -X option.
>mysql -u root -p root -X

This will shows you a query results in an XML format and its very convenient method for quick formatting. A possible disadvantage is that the mapping from relational data to XML is fixed - there is no way you can change the tagnames, control wheter data should be formatted as element content or as an attribute, set the namespace, etcetera.

MySQL XML capabilities as of 5.1.5

XML support in MySQL 5.1 has been extended with:
* ExtractValue(): Query and Retrieve data from XML formatted text strings
* UpdateXML(): Update data in XML formatted text strings

Both functions accept a string that represents fragment of XML, and an XPath expression. The XPath expression acts as a query operator on the xml, identifying the nodes (that is, the elements, attributes, text contents etc.) that the function needs to handle.

In the case of ExtractValue(), the text nodes specified by, or ocurring within the nodes identified by the XPath expression is returned:

mysql> select extractValue('text','tag') as `tag`
-> , extractValue('text','tag/text()') as `text()`
-> ;
+------+--------+
| tag | text() |
+------+--------+
| text | text |
+------+--------+
1 row in set (0.00 sec)

In first call to ExtractValue() the XPath expression, tag selects the text bit, but only the text content is returned. The XPath expression in second call to ExtractValue(), tag/text() explicitly specifies that text content should be selected. The result is the same in both cases.
If multiple nodes are identified, the text contents are concatenated, separated by a single space character:

mysql> select extractValue('text1text2','tag') as `tag`;
+-------------+
| tag |
+-------------+
| text1 text2 |
+-------------+
1 row in set (0.00 sec)

In the case of UpdateXML(), the selected node is replaced by the third supplied argument.

Importing XML using ExtractValue

We can write a single XPath expression for each field in both of the store records, and once we have the values, it's of course a piece of cake to write an insert around that:

set @xml := "text2";
insert into store values (extractValue(@xml,'/parent/child/text()'));

Even we can use these functions in the stored procedure where we have to deal with larger xml schema and do the extraction of data.