Skip to main content

Posts

Showing posts with the label XML

DOM Parser Vs. SAX Parser

Many developers sometimes confuse which is better to parse the XML document. Ofcourse myself also got doubt which parser I can use for this situation.  Since I have read about DOM and SAX very long back. Just refreshing it again DOM (Document Object Model) Parser: Tree model parser(Object based) (Tree of nodes). DOM loads the file into the memory and then parse the file. Has memory constraints since it loads the whole XML file before parsing. DOM is read and write (can insert or delete the node). If the XML content is small then prefer DOM parser. Backward and forward search is possible for searching the tags and evaluation of the information inside the tags. So this gives the ease of navigation. Slower at run time.

Solution For Error: " Current configuration of the parser doesn't allow a maxOccurs attribute value to be set greater than the value 5,000."

Currently I am working on a project where I need to transform Excel sheet data to an XML format in compliance with XSD given by my client. When I am trying to parse the XSD using JAXB I got this error when doing mvn clean install. Error: ""Current configuration of the parser doesn't allow a maxOccurs attribute value to be set greater than the value 5,000." I found many solutions and route cause for this issue. You can find some information on Oracle site the route cause for the issue . It is because of the feature enabled for secure XML processing. This feature was enable in JAXP 1.3 which instructs parsers, transformers to behave in a secure fashion. You can find more information here: https://jaxp.java.net/1.4/JAXP-Compatibility.html#JAXP_security. For me 2 solutions worked out: Solution 1: With code change or implemenetation: //Create SchemaFactory using XSD file SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_UR...

WebServices & It's Features

What are web services? A web service is a business function that is self-contained and operates over the internet. The W3C defined web service as "a software system designed to support interoperable machine-to-machine interaction over a network". XML is the base for the web services. They communicate using open protocols. Web services are more frequently like Web APIs. These services accessibility can be from internet. A remote system can host these services for different web services. A web service can convert a stand alone / desktop application into a web based / web application. A web services are published or found and utilized through the internet. The web services works on the XML + HTTP platform. Explain each web service technologies - SOAP, WSDL, UDDI, eBXML and JAX pack.

What is JAXP? How to Read and Write XML Document Using JAXP

The Java API for XML Processing (JAXP) is for processing XML data using applications written in the Java programming language. JAXP leverages the parser standards Simple API for XML Parsing (SAX) and Document Object Model (DOM) so that you can choose to parse your data as a stream of events or to build an object representation of it. JAXP also supports the Extensible Stylesheet Language Transformations (XSLT) standard, giving you control over the presentation of the data and enabling you to convert the data to other XML documents or to other formats, such as HTML. JAXP also provides namespace support, allowing you to work with DTDs that might otherwise have naming conflicts. Finally, as of version 1.4, JAXP implements the Streaming API for XML (StAX) standard. Designed to be flexible, JAXP allows you to use any XML-compliant parser from within your application. It does this with what is called a pluggability layer, which lets you plug in an implementation of the SAX or DOM API. The...

What are Different Web Services Technologies and Tools

There are a variety of tools available for the Web Services. Microsoft Has C# as the development language for Web services and .NET framework. Sun Microsystems has JAX/RPC (Java API for XML Remote Procedure Calls) and JAXR (Java API for XML Registries). IBM also has Web Services Toolkit (WSTK), WSDL Toolkit, and Web Services Development Environment (WSDE). Apache Axis is an implementation of the SOAP ("Simple Object Access Protocol")

How to Load Java Properties from the XML File?

-- The java.util.Properties class represents a persistent set of properties. The Properties can be saved to a stream or loaded from a stream. Each key and its corresponding value in the property list is a string. In Java 5.0, the java.util.Properties class allows you not only to use it to specify key-value pairs on a single line separated by an equal sign, but also to use XML files to load and save those key-value pairs. The loadFromXML(InputStream) and storeToXML(OutputStream, String, String) methods load and store properties in a simple XML format. By default the UTF-8 character encoding is used, however a specific encoding may be specified if required. An XML properties document has the following DOCTYPE declaration: Note that the system URI (http://java.sun.com/dtd/properties.dtd) is not accessed when exporting or importing properties; it merely serves as a string to uniquely identify the DTD, which is:...

Generating an XML Document with JAXB

An XML Schema represents the structure of an XML document in XML syntax. J2EE developers may require an XML document to conform to an XML Schema. The Java Architecture for XML Binding (JAXB) provides a binding compiler, xjc , to generate Java classes from an XML Schema. The Java classes generated with the JAXB xjc utility represent the different elements and complexType s in an XML Schema. (A complexType provides for constraining an element by specifying the attributes and elements in an element.) An XML document that conforms to the XML Schema may be constructed from the Java classes. In this tutorial, JAXB is used to generate Java classes from an XML Schema. An example XML document shall be created from the Java classes. This article is structured into the following sections. Preliminary Setup Overview Generating Java Classes from XML Schema Creating an XML Document from Java Classes Preliminary Setup To generate Java classes from an XML Schema with the JAXB , the JAXB...

Web Services Tutorial

Introduction to Web Services Web Services became a hot new technology in 2002. Microsoft first coined the term "Web Services" in June of 2000 when it introduced Web Services as a major component of its .NET technology aimed at revolutionizing distributed computing. I see it as a new vision for using the Internet in the development, engineering and use of software. Web services standards are emerging. Several technologies combine to make up "Web Services". The main standard is Extensible Markup Language, XML. XML was developed by the World Wide Web Consortium ( W3.org ) It is a meta-language for describing data and creating additional markup languages. XML tags form individual pieces of data. An XML document is text-based and is made up of XML tags. XML is portable and has been rapidly adopted throughout the industry, thus making it the preferred choice for enabling cross-platform data communication in Web Services. XML provided the basis for many core W...

Processing XML with Java

A book by Elliotte Rusty Harold, is a complete tutorial about writing Java programs that read and write XML documents. This is the most comprehensive and up-to-date book about integrating XML with Java (and vice versa) you can buy. It contains over 1000 pages of detailed information on SAX, DOM, JDOM, JAXP, TrAX, XPath, XSLT, SOAP, and lots of other juicy acronyms. This book is written for Java programmers who want to learn how to read and write XML documents from their code. Read..

XML Binding with JAXB 2.0 - Tutorial

Java Architecture for XML Binding (JAXB) is an API/framework that binds XML schema to Java representations. Java objects may then subsequently be used to marshal or unmarshal XML documents. Marshalling an XML document means creating an XML document from Java objects. Unmarshalling means creating creating a Java representation of an XML document (or, in effect, the reverse of marshaling). You retrieve the element and attribute values of the XML document from the Java representation. The JAXB 2.0 specification is implemented in JWSDP 2.0. JAXB 2.0 has some new features, which facilitate the marshalling and unmarshalling of an XML document. JAXB 2.0 also allows you to map a Java object to an XML document or an XML Schema. Some of the new features in JAXB 2.0 include: Smaller runtime libraries are required for JAXB 2.0, which require lesser runtime memory. Significantly, fewer Java classes are generated from a schema, compared to JAXB 1.0. For each top-level complexType, 2.0 generates a v...

XUL Tutorials & Resources

XUL Questions and Examples - This tutorial gives answers to the following questions. How do I hide and show a XUL element? How do I get the mouse position on a element? How do I get the content loaded in an iframe? How do I parse a string of XUL? -  How do I create a form and submit it? Is there a way to show a simple message box? How do I sort content? How do I retrieve and modify Mozilla preferences? How do I get the text of the currently selected item in a tree? How do I put arbitrary elements in a tree? How do I add an image to a treecell?  How do I add a progress meter to a treecell? Do I need to load XUL from the chrome directory? Is XUL security different than HTML? How do I load XUL from a Web site? How do I use a tree with RDF stored on a remote server?

Use XML in Java to Write Save Documents

An explanation on how to use xml in java to write and save documents. This java program will help you to read xml value from xml file. Also you have to download two jar file: 1 xerces_1_0_3.jar 2 xmlparserv2.jar and set class path for above jar files after compile the below java file ================start============================= import java.io.File; import org.w3c.dom.Document; import org.w3c.dom.*; import java.util.*; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilder; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; public class ReadAndPrintXMLFile{ public static void main(String arg[]) { Vector vcrs = null; try { vcrs = null ; vcrs = new Vector() ; DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); Document doc = docBuilder.parse (new File("interest.xml")); // normalize text representation doc.g...