XML is stand for EXtensible Markup Language and it is easy to use XML as a markup language. XML haven’t got any predefined tags as HTML. Therefor when we are using a XML content, we have to use a mechanism to read those tags and identify those tags separately.
For this mechanism there are XML parsers. Specially we can use SAX parser and DOM parser. In most web browsers they have an inbuilt XML parser.
DOM parser is effective than the SAX parser. SAX uses an event callback mechanism requiring you to code methods to handle events thrown by the parser as it encounters different entities within the XML document.
DOM parses an XML document and returns an instance of org.w3c.dom.Document
. This document object’s tree must then be “walked” in order to process the different elements.
JDOM is an open source API, designed specifically for Java programmers, that represents an XML tree as Elements and Attributes. JDOM can interact with SAX or DOM. With JDOM, you construct an instance of a builder.
Lets look at how to validate a XML string using java. I have used the DOM API for that. In this example I have used a XML string to validate
|
|