Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Nirman
DOM API
2 Answer(s)      6 years and 5 months ago
Posted in : Java Beginners



Advertisement
View Answers

May 26, 2008 at 7:39 PM


Hi friend,

import org.w3c.dom.*;
import javax.xml.parsers.*;
import java.io.*;

public class GetNodeExample{
public static void main(String[] args) {
try{
BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter xml file name: ");
String str = buff.readLine();
File file = new File(str);
if(file.exists()){
DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
DocumentBuilder build = fact.newDocumentBuilder();
Document doc = build.parse(str);
Node node = doc.getDocumentElement();
String root = node.getNodeName();
System.out.println("Root Node: " + root);
}
else{
System.out.println("File not found!");
}
}
catch(Exception e){
System.out.println("Exception file not fount" +e);

}
}
}

----------------------------------------------

Read for more information.

http://www.roseindia.net/xml/dom/index.shtml



May 26, 2008 at 7:47 PM




<cfscript>

document = parse("http://127.0.0.1/test/kitten.xml";);
WriteOutput( "(" & getNodeType(document) & ") " & getNodeName(document) & "<br />");
// Root Element (rootElement)
rootElement = getDocumentElement(document);
rootElementAttrs = getAttributes(rootElement);
children = getChildNodes(rootElement);

WriteOutput("(" & getNodeType(rootElement) & ") <code>" & getNodeName(rootElement) & "</code> ");
WriteOutput("(attrs: " & getLength(rootElementAttrs) & ", children: " & getLength(children) & ") <Br />");

// Children of Root Element (thisChild, grandchildren)
WriteOutput("<ol>");
for(i = 0; i LT getLength(children) ; i = i + 1) {
thisChild = getChild(children,i);
thisChildAttrs = getAttributes(thisChild);
grandchildren = getChildNodes(thisChild);

if ( getNodeType(thisChild) is "ELEMENT_NODE" ) {
WriteOutput("<li>");
WriteOutput("(" & getNodeType(thisChild) & ") <code>" & getNodeName(thisChild) & "</code> ");
WriteOutput("(attrs: " & getLength(thisChildAttrs) & ", children: " & getLength(grandchildren) & ") <Br />");
WriteOutput("</li>");
}
}
WriteOutput("</ol>");
</cfscript>


Related Tutorials/Questions & Answers:
DOM API - Java Beginners
DOM API  How can i go through each and every node of an xml file Each and everyChild? my xml file is given below: 810 32 141 22
DOM API - Java Beginners
DOM API  How can i go through each and every node of an xml file Each and everyChild? my xml file is given below...); } } } ---------------------------------------------- Read for more information. http://www.roseindia.net/xml/dom
Advertisements
Implementing the createTextNode() method in DOM API.
Implementing the createTextNode() method in DOM API In this illustration, we... new DOM parsers and  DocumentBuilder is used in code given below for creating an Blank DOM Document. The following code is used to create a textNode. Text
Example of getDocType method in DOM API.
getDocType() Example in DOM API In this section, we will discuss about the implementation of the getDocType() method. This method checks that DTD(Document... parse the xml file using parse() method and create a DOM Tree. Invoke the object
Implementing the setAttribute() method of DOM API
Implementing the setAttribute() method of DOM API In this illustration, we will discuss about the appending the node to the existing XML document. In this program, we create the object of DocumentBuilderFactory to parse the xml
Example of getTagName() method in xml dom api.
the element. In this example, we create the Dom parser by create the instance
DOM
DOM  package name for Document class?   Hi Friend, The package is known as dom api. For more information, visit the following links: http://www.roseindia.net/xml/ http://www.roseindia.net/xml/dom/ Thanks
DOM
DOM  hello, What is DOM?   hii, DOM is stands for Document object Model. DOM is an interface-oriented Application Programming Interface. We can use it for navigation of the entire document
DOM Parser Tutorial
. It is available in package org.w3c.dom. Dom is a cross-language API. It provides many... tree elements. With the help of Dom api, user  can add, delete.... DOMImplementation It is a inter face of DOM API.  It provides various method
DOM to SAX and SAX to DOM - XML
Java DOM to SAX and SAX to DOM  Simple API for XML and Document Object Model
API
API  what means API in java?   Hi Friend, The Application Programming Interface (API) is a library of functions that allow programmers... for building software applications in java. If you want to know about java api, please
api
api  WHAT IS THE DEFINITON OF API,EXPLAIN IN DETAIL?   An API is the interface implemented by an application which allows other... of it by a computer program. An API differs from an application binary interface
DOM to SAX and SAX to DOM - XML
DOM SAX Parser Java  What is the Difference between SAX and DOM parsers
Creating Blank DOM Document
Creating Blank DOM Document       This tutorial shows you how to create blank DOM document. JAXP (Java API for XML Processing) is a Java interface that provides a standard approach
DOM - XML
DOM  Hi... I created an xml file through java by using DOM Now..I need to get the prompt for download when i clicked the button... I used downloadaction...for this But it didn't worked.. Its jus viewing the xml file
Dom in java
Dom in java  Exception in thread "main" org.w3c.dom.DOMException: INVALIDCHARACTERERR: An invalid or illegal XML character is specified... Create XML using DOM import java.io.*; import org.w3c.dom.*; import
JAXP API using DOM Parser
JAXP API using DOM Parser      ... based on the structure type.   DOM (Document Object Model) The XML Document Object Model (XML DOM) defines a standard way to access
DOM - XML
DOM  Hello.... I'm creating an xml file from java using DOM... from the database values... and saving it in a file But the created xml file is generating all its files in a single line.. But i need to get the next tag
Javascript DOM
generate a fixture list. I was knocking about using DOM techniques but with minimal
javascript dom error-message
javascript dom error-message  javascript dom error-message
dom to xml string
dom to xml string  Hi, I am writing a program in java that reads... have save the dom document into xml file. How to convert dom to xml string... for converting DOM object into string data. Please check the thread dom to xml
Create an Empty DOM Document
Create an Empty DOM Document       This Example shows how to create an empty DOM Document . JAXP (Java API for XML Processing) is an interface which provides parsing of xml
Java dom from string
Java dom from string  Hi, How to create dom tree from string data? I am trying to search the example for java dom from string. Thanks   Hi, Following code might be useful: import java.io.StringReader; import
jUSB api
jUSB api  How can i access the USB using jUSB api and also hw to add this api to the netbeans
Java-XML-DOM - XML
Java-XML-DOM  Hi! I need some help. I have to make java program that loads an xml file and from it builds DOM(later i will have to work with it - like using xpath in java find some value and replace it...). Since i'm new to java
Collections API
Collections API  hello, What is the Collections API?   hi The Collections API is a set of classes and interfaces that support operations on collections of objects
API for beginners
API for beginners  what is api? why api is needed in java?   Hi Friend, The Application Programming Interface (API) is a library... to know more about java api, please visit the following link: Java API Thanks
DOM paring problem
DOM paring problem  Hi My code always show arrayindexoutofbound here is my code i am using arraylist to display and DOM parser to retrieve XML value. I am searching the value by attributes equals 2. this error i am getting
DOM paring problem
DOM paring problem  Hi My code always show arrayindexoutofbound here is my code i am using arraylist to display and DOM parser to retrieve XML value. I am searching the value by attributes equals 2. this error i am getting
java api
java api  what is work of api in java   An application programming interface (API) is a library of functions that Java provides.... For more information,visit the following link: Java API
java API
java API  hello What is the Java API?   hello, The Java API is a large collection of ready-made software components that provide many useful capabilities, such as graphical user interface (GUI) widgets
 

 

 

DMCA.com