XML

"Continuous effort - not strength or intelligence - is the key to unlocking our potential." ==> Winston Churchill

Name:
Location: Bangalore, India

Wednesday, March 29, 2006

How to restrict null values in XML tags

The following declartion will restrict the tag values to only a to z, A to Z and 1 to 9 and no other values can be entered into it.

<element name="first">
<simpleType>
<restriction base="string">
<pattern value="([a-zA-Z1-9])+"/>
</restriction>
</simpleType>
</element>

Tuesday, March 28, 2006

XML Document To Schema

The following article, "Validation by Instance", explores how one can translate an XML document into a Document Type Definition (DTD), a RELAX NG schema, and then into an W3C XML Schema (WXS) schema.

You can also use Stylus Studio Professional Edition (or) Stylus Studio Enterprise Edition XML Editor which integrates

XML instance Document to XML Schema
XML instance Document to DTD Schema

Monday, March 27, 2006

Articles

Here is a list of articles by Deepak Vohra.

XPath

Here is a XPath Tutorial from OnJava.com by Deepak Vohra.

XML Book

Processing XML with Java by Elliotte Rusty Harold

API [DOM, SAX, JAXP] Parsers[Crimson, Xerces] - How to relate all these

Here is a link from Processing XML with Java by Elliotte Rusty Harold which explains clearly about all the details of

1. What a parser is
2. what are the different API's with which you can access XML Document
3. What are the different parsers available to parse an XML Document

JAXP(SAX & DOM) vs JAXB

Find the discussion about it here

Sunday, March 26, 2006

Web Services Acronyms

Here is a list of acronyms used in Web Services.

XML: Extensible Markup Language
SOAP: Simple Object Access Protocol
UDDI: Universal Description, Discovery and Integration
ebXML: Electronic Business Extensible Markup Language
WSDL: Web Services Description Language
JAXM: Java API for XML Messaging
JAX-RPC: Java API for Remote Procedure Call
JAXR: Java API for XML Registry
JAXP: Java API for XML Processing
JAXB: Java Architecture for XML Binding
SAAJ: SOAP with Attachments API for JavaJava
WSDP: Java Web Services Developer Pack
WS-I: Web Services Interoperability Organization
W3C: World Wide Web Consortium
OASIS: Organization for the Advancement of Structured Information Standards
JCP: Java Community Process

Java Architecture for XML Binding(JAXB)

JAXB Basic Tutorial

What is JAXB.

About JAXB.

JAXB API

JAXB FAQ

XML - Java Mapping Tools

Best practices for creating java classes from xml schema (.xsd)

1. Apache XMLBeans
2.
(Java Architecture for XML Binding)JAXB/JaxMe

XML files to a Javabean

There are many tools out there which can be used to get the work done.

1. Jakarta Commons Digester.
2. Castor
3. XStream

While convert XML to Java objects when do you prefer Digestor over JAXB?

You can learn all about it here


Friday, March 24, 2006

Whats the difference in getElementsByTagName(String str)

Whats the difference between

getElementsByTagName(String str) of Document object and
getElementsByTagName(String str) of Element object.


Sample XML Document.

<scenariotemplate>
   <layout name="intro,quest,conc" width ="1" height="3">
      <textElement name="Introduction" position="1"></textElement>
      <listElement name="Questions" position="2"></listElement>
      <textElement name="Conclusion" position="3"></textElement>
   </layout>
</scenariotemplate>

A sample Program:

Document doc = null;
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();

try {
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
doc = docBuilder.parse(new File("component.xml"));
}catch(ParserConfigurationException e1) {
}catch(SAXException e2) {
}catch(IOException e3) {
}

/* Scenario I */
Element RootElement = doc.getDocumentElement();
NodeList templates = RootElement.getElementsByTagName("*");

/* Scenario II */
NodeList templates = doc.getElementsByTagName("*");

int totaltemplates = templates.getLength();
System.out.println("Total no of child elements : " + totaltemplates);

In Scenario I - OUTPUT will be
Total no of child elements : 4
This is excluding the ROOT element.

In Scenario II - OUTPUT will be
Total no of child elements : 5
This is including the ROOT element.

Thursday, March 23, 2006

XML Certification Worth?

XML Certification is worth for future.

SAX Tutorial

SAX - IBM Tutorial.


SAX Tutorial - DeveloperLife.com - Nazmul Idris

Friday, March 17, 2006

XML Introduction

XML Introduction - from XML Evangelist, IBM

Wednesday, March 15, 2006

How to specify an attribute for a child element.

Attribute declarations for child Elements in XML Schema

XML Tip

An element cannot contain both simpleType as well as complexType. If you use both then you end up will the following error

The content of an element information item does not match (annotation?, (simpleType | complexType)?, (unique | key | keyref)*)

Tuesday, March 14, 2006

XML Schema Tutorial

XML.com - XML Schema Tutorial

Here is link to a problem and relevant solution for Schema definition.

Sunday, March 12, 2006

DOM Parser

Here is a link that discuss about the advantages and disadvantages of DOM parser.

Thursday, March 09, 2006

Local elements and targetNamespace

XML Schema

?xml version="1.0"?>
xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://atw.co.in/vis" xmlns:tars="http://atw.co.in/vis"
>

xs:attributeGroup name="Agroup">
xs:attribute name="title" type="xs:string" />
/xs:attributeGroup>

xs:complexType name="NameType" >
xs:sequence>
xs:element name="first" type="xs:string" default="Hi"/>
xs:element name="last" type="xs:string" default="nu"/>
/xs:sequence>
xs:attributeGroup ref="tars:Agroup" />
/xs:complexType>

xs:element name="name" type="tars:NameType"/>
/xs:schema>



XML Document

?xml version="1.0"?>
vis:name
xmlns:vis="http://atw.co.in/vis"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://atw.co.in/vis name2.xsd"
title="Mr.">
vis:first>
vis:last>
/vis:name>

Error:

Element 'first' should be un-qualified
Element 'last' should be un-qualified


Reason for Error:

Look at your XML Schema document and the schema element. elementFormDefault attribute is missing. Hence, this attribute takes the default value, which is unqualified. Because of that, the local elements are not in the targetNamespace.


How to recify these errors?

Replace

-------------------------
vis:first>
vis:last>
--------------------------

With

-------------------------
first>
last>
--------------------------

OR include
elementFormDefault
attribute with "qualified" value in schema element.

XML Schema

?xml version="1.0"?>
xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://atw.co.in/vis" xmlns:tars="http://atw.co.in/vis"
elementFormDefault="qualified">


Why do the local elements do not come under targetNamespace when their parent element is?

That's by definition of the XML Schema recommentations.

XML Namespaces FAQ

Here you go

XML Namespace
s FAQ

Here is another link that has discussion about namespaces.

Element Type - Declaration

I have an XML document, with one structure nested inside another - e.g "manager" element nested inside a "company":
code:

company>
manager>
name> john /name>
/manager>
/company>



I'm trying to create a schema (xsd) for this.
Note my "manager" needs to be defined outside the scope of "company", so that it's re-usable (i.e. manager may be nested inside other structures, not just "company").

I get the impression there are 2 ways to do it:

1. Define "manager" as *element*, then let "company" declare a *ref* to it
code:

schema ...>
element name="company">
complexType>
sequence>
element ref="manager"/>
/sequence>
/complexType>
/element>
element name="manager">
complexType>
sequence>
element name="name" type="string"/>
/sequence>
/complexType>
/element>
/schema>



2. Define "manager" as *complex type*
code:

schema ...>
element name="company">
complexType>
sequence>
element name="manager" type="managerType"/>
/sequence>
/complexType>
/element>
complexType name="managerType">
sequence>
element name="name" type="string"/>
/sequence>
/complexType>
/schema>



Could anyone please tell what's the difference between the 2 approaches ? Why does XML define 2 syntaxes to achieve the same goal ?

Answer:

First XSD(Schema) is called Using a global Type.
Second
XSD(Schema) is called Referring to a existing global element.

Using a global Type:
Often many of our elements will have the same content. Instead of declaring duplicate local types throughout our schema, we can create a global type. Within our element declarations, we can refer to a global type by name (with type attribute).

Referring to a existing global element:
Referring to global types allows us to easily reuse content model definitions within our XML Schema. Often, we may want to reuse a particular element delcaration, instead of the type. XML Schemas allow you reuse global element declarations within your content model.

Check this link for better understanding.