In this section, you will learn to retrieve the attributes and their value from a XML document using the SAX APIs.
Description of program:
This program helps you in retrieving attributes and
their values. The parse() method is invoked by the SAXParser
object. Override
startElement() method in
SAXHandler
class to provide functionality to get the attribute and its
value from a xml file.
Here is the XML File: sample.xml
| <Employee-detail > <Employee name="Amit" > <address>My address</address> </Employee> <issued-items> <item code="111" type="CD" label=" music" /> <item code="222" type="DVD" label=" video"/> </issued-items> </Employee-detail> |
Here is the Java File: ReadAttributes.java
import java.io.*;
|
Output of this program:
| C:\vinod\xml\sax1>javac ReadAttributes.java C:\vinod\xml\sax1>java ReadAttributes Enter a xml file name: sample.xml Name: Value: name Amit code 111 type CD label music code 222 type DVD label video |
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Getting Attributes And its Value
Post your Comment