Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within XML
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
XML and Related Technologies
xml parser configuration file
avinash nk
Greenhorn
Posts: 1
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I'm writing a simple xml parser in
java
,
please explain how can i read xml tag names from a properties file?
here is code i'm currently working on, I'm using an test.xml file to read data, How can i set up a .properties file to read xml tags?
public class xml2 { public void xmlR(File f) { try { FileInputStream IF=new FileInputStream(f); DataInputStream data=new DataInputStream(IF); BufferedReader buf=new BufferedReader(new InputStreamReader(data)); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(f); doc.getDocumentElement().normalize(); NodeList nList = doc.getElementsByTagName("test"); File file=new File("xml.txt"); BufferedWriter writer = new BufferedWriter(new FileWriter(file)); for (int temp = 0; temp < nList.getLength(); temp++) { Node nNode = nList.item(temp); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; writer.write("ID : " + getTag("id", eElement)); writer.newLine(); writer.write("Name : " + getTag("Name", eElement)); writer.newLine(); writer.write("AGE: " + getTag("age", eElement)); writer.newLine(); writer.flush(); writer.write("-----------------------");writer.newLine(); } } } catch(Exception e) { e.printStackTrace(); } } private static String getTag(String sTag, Element eElement) { NodeList nlList = eElement.getElementsByTagName(sTag).item(0).getChildNodes(); Node nValue = (Node) nlList.item(0); return nValue.getNodeValue(); } public static void main(String args[]) { xml2 x=new xml2(); x.xmlR(new File("test.xml")); } }
Jaikiran Pai
Sheriff
Posts: 10445
227
I like...
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
What exactly do you mean by use a properties file for reading xml tags? Why do you need a properties file and what content do you expect in that properties file?
[
My Blog
] [
JavaRanch Journal
]
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You do realize that the java.util.Properties class has read from XML and store to XML methods, right?
Bill
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Parsing xml, Results missing
Connection refused: connect in faces-config.xml
XML file Location
Read xml file placed on localhost
XML Parsing
More...