Using XML in Java

Started by Home, 01-21-2011, 02:10:10

Previous topic - Next topic

HomeTopic starter

Please tell me how to implement this.
  •  


ravi

i have no knowledge about this....plz mentioned it.......


navkesh

XML is an enabling technology for the virtuous programmer. A basic XML parser does a great deal of work for the programmer, recognizing tokens, translating encoded characters, enforcing rules on XML file structure, checking the validity of some data values, and making calls to application-specific code, where appropriate. In fact, early standardization, combined with a fiercely competitive marketplace, has produced scores of freely available implementations of standard XML parsers in many languages, including C, C++, Tcl, Perl, Python, and, of course, Java.

The java.util.Properties class has build-in functionality to convert properties file into XML file or vice verses.

Example:
Convert properties file into XML file in JAVA

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Properties;

public class PropertiesXMLExample
{
    public static void main(String[] args) throws IOException
    {   
       Properties props = new Properties();
       props.setProperty("email.support", "donot-spam-me@nospam.com");
       OutputStream os = new FileOutputStream("c:/email-configuration.xml");
       props.storeToXML(os, "Support Email","UTF-8");
       System.out.println("Done");
    }
}

The above example will write the properties detail into a XML file "c:/email-configuration.xml" as:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
   <properties>
      <comment>Support Email</comment>
      <entry key="email.support">donot-spam-me@nospam.com</entry>
   </properties>

netedge12

#3
XML could be a all-purpose specification for making custom mark-up languages. Its primary purpose is to assist info systems share structured knowledge, significantly via the net, and it's used each to code documents and to set up knowledge.
  •  

raghuramastrologer

Java XML Tutorial. XML (Extensible Markup Language) is a very popular simple text-based language that can be used as a mode of communication between different applications. It is considered as a standard means to transport and store data.
  •  


Lishmalinyjames

We must have followed the process to read an XML file in Java: Instantiate XML file: DOM parser loads the XML file into memory and consider every tag as an element. Get root node: The document class provides the getDocumentElement() method to get the root node and the element of the XML file.

saravanan28

XML (Extensible Markup Language) is a very popular simple text-based language that can be used as a mode of communication between different applications. It is considered as a standard means to transport and store data.
  •  

Lishmalinyjames

XML (eXtensible Markup Language), like HTML, is a markup language for marking up the structure of a text document. It is a subset of Standard General Markup Language (SGML).