Home Answers Viewqa Java-Beginners Java dom from string

 
 


Deepak Kumar
Java dom from string
1 Answer(s)      2 years and 2 months ago
Posted in : Java Beginners

Hi,

How to create dom tree from string data? I am trying to search the example for java dom from string.

Thanks

View Answers

March 31, 2011 at 5:37 PM


Hi,

Following code might be useful:

import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.xml.sax.InputSource;


public class UpdateData
{
public static void main(String[] args) 
{


String url="http://www.roseindia.net";
String strData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    strData = strData+"<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" 
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 

xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 

http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">\n";

        strData = strData+" <url>\n";
        strData = strData+"     <loc><![CDATA[\"http://www.roseindia.net" + url +"\"]]></loc>\n";
        strData = strData+"     <changefreq>weekly</changefreq>\n";
        strData = strData+"     <priority>1.00</priority>\n";
        strData = strData+" </url>\n";

        strData = strData+"</urlset>\n";


System.out.println(strData);

    System.out.println("hello");



try {
  DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  DocumentBuilder builder = factory.newDocumentBuilder();
  InputSource is = new InputSource( new StringReader( strData ) );
  Document d = builder.parse( is );
}
catch( Exception ex ) {
  ex.printStackTrace();
}
}

}

Thanks









Related Pages:
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   ... UpdateData { public static void main(String[] args) { String url="http
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
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...*; public class CreateXML{ public static void createXmlFile(Document doc,String
Dom in java
Dom in java  Exception in thread "main" org.w3c.dom.DOMException...(CoreDocumentImpl.java:618) at CreatXMLFile.main(CreatXMLFile.java:29)   Java Create XML using DOM import java.io.*; import org.w3c.dom.*; import
XML DOM error - Java Beginners
XML DOM error  import org.w3c.dom.*; import javax.xml.parsers....(String[] args) { try { BufferedReader bf = new BufferedReader(new...: "); String xmlFile = bf.readLine(); File file = new File(xmlFile
Javascript DOM
generate a fixture list. I was knocking about using DOM techniques but with minimal...; **//This is the javascript code I used from an external file** var array = new Array...() { var string="<b>These are the chosen teams :</b><br>
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-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
DOM API - Java Beginners
DOM API  How can i go through each and every node of an xml file Each... main(String[] args) { try{ BufferedReader buff = new BufferedReader...: "); String str = buff.readLine(); File file = new File(str
Java XML Parsing Using DOM
Java XML Parsing Using SAX To Parse XML document using SAX parser method you... SAXParser object from AXParserFactory instance SAXParser saxParser... the startElement() methods of DefaultHandler @Override public void startElement(String
java code to create xml document from DOM object
java code to create xml document from DOM object  Hey! After knowing the way we can create DOM objects and add elements to it-> then displaying it on the console ;is there a way I can output the same in xml document
DOM importnode, Example of importnode method of document interface.
can make a program to import a node from another document to the current... in the document from another document, including its data. The sub nodes of the source... tree. The default attributes are not copied from the source document
string
string  a java program using string function that computes your initials from your full name and display them   Please visit the following links: http://www.roseindia.net/tutorial/java/core/printInitials.html http
string
string  how do i extract words from strings in java???   Hi... ExtractWords { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("Enter String
string
and also displaying that contain word? Like I want to find "a" in the string "This is example of java Programme" and also display word that contain "a" character.   Here is a java example that accepts a sentence from the user
DOM Parser Tutorial
. This is a indexed list similar to the array in java starting from 0 index and ends with one...DOM Parser Tutorial Introduction Dom stands for Document Object Model. It is a Java API(Application Programming Interface ) for XML Parsing
Java DOM Tutorial
Java DOM Tutorial      ... element from the XML document.  The JAXP (Java APIs for XML...; Accessing XML file from Java In this example we have provided you a simple java
DOM to SAX and SAX to DOM - XML
Java DOM to SAX and SAX to DOM  Simple API for XML and Document Object Model
Adding an Attribute in DOM Document
Adding an Attribute in DOM Document       This Example shows you how to adds an attribute in a DOM document. JAXP (Java API for XML Processing) is an interface which provides
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... in advance  Hi Friend, Do you want the code in jsp or in java? Please
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
Example for getElementsByTagName() method in DOM Document.
Example for getElementsByTagName() in DOM Document In this section ,we.... In this a tag name is passed as a string which is to be searched. The file name is given...;public static void main(String[] args)  throws 
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
Implementing the setAttribute() method of DOM API
Implementing the setAttribute() method of DOM API In this illustration, we...(String[] argv) throws Exception {   try{  ... C:\>java setattributeExample <?xml version="1.0
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
XML Error checker and locater (DOM)
XML Error checker and locater (DOM)   ... and locate (line and column number) an error in your XML document using the DOM APIs... are needed to get a dom parser. All the  parsers have inbuilt capability
Java Write To File Dom Document
Java Write To File Dom Document In this tutorial you will learn how to write to file dom document. Write to xml file you would be required to use the package... org.w3c.dom.Document; public class WriteToFileDomDocument{ public static void main(String
Getting Dom Tree Elements and their Corresponding XML Fragments
Getting Dom Tree Elements and their Corresponding XML Fragments... will learn to get the elements of a DOM tree and their corresponding XML fragments. Each element of dom tree has a node level starting with '0'. Here
Pass a dom object from jsp to servlet
Pass a dom object from jsp to servlet  I am creating a dom object in my jsp page. now i want to pass that object in a servlet through calling servlet in jsp. can anyone help me
Java String
Java String  You are given two strings S1 and S2,Delete from S2 all those characters which occur in s1 also and create a clean S2 with the relevant characters deleted..write a pgm for this..pls send as soon as possible Thank you
Example of getTagName() method in xml dom api.
the element. In this example, we create the Dom parser by create the instance...;ExamplegetTagName  {   public static void main(String.... C:\>javac ExamplegetTagName.java C:\>java
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
How to return a string from a JTextField
How to return a string from a JTextField  Hi, Am new to java, and am trying to get a string from a JTextField so that I can compare it with another String using either compare or equals or compareTo methods of the String class
how to write to file from string in Java
how to write to file from string in Java  Hi, Please any one help me for how to write to file from string in Java. I am beginner in Java... string in java? So, then visit this http://www.roseindia.net/java/examples/io
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
Reading XML from a File
a DOM document. JAXP (Java API for XML Processing) is an interface which provides... to create new DOM parsers. Some of the methods used for reading XML from a ... Reading XML from a File      
Java get Int from String
Java get Int from String     ... from String. For this, we have defined a string. The method  Integer.parseInt(st) converts the string into the integer. Here is the code
Java Remove a character from string
Java Remove a character from string In this tutorial, you will learn how to remove a character from the string. There are several methods for examining... to remove a particular character from the string. In the given example, we have
string
string   difference detween "public static void main (String[] args) " and "public static void main (String args[])" in java but it executes both ,in java which one is legal   The only difference is style, where
String
String  write down the code of remove any character from a given string without using any string function   please give me the code of remove any given character from a given string without using function
string
string  java prgm to find total occurence of a given string pattern in a sentence
string
string  java prgm to find total occurence of a given string pattern in a sentence
String
String  How to Convert sunnapu gopal to Sunnapu Gopal in java using String
string
string  a java program using string function to input any string... ArrangeStringAlphabetically { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("Enter string
Getting text values from a NodeList
Getting text values from a NodeList       This Example shows you how to Get Text values from the NodeList in a DOM document. JAXP (Java API for XML Processing) is an interface
string
string  a java program to input a string and display the string...*; import java.io.*; public class FirstLetter{ public static String capitalizeFirstLetter( String str ) { final StringTokenizer st = new StringTokenizer( str
string
string  program for String reverse and replace in c,c++,java e.g.Input:10,20,hello output:hello;20;10   Hi Friend, Try the following java...(String[] args) { String array[]=new String[5]; Scanner input
string
string  how we conunt the no. of words in java without using in pre defined method in java
string
string  a java program to replace all matching substrings
Remove Repeated Characters from the String
Remove Repeated Characters from the String In this we are going to remove repeated characters from the string. For this, we have allowed the user to enter the string. The class BufferedReader reads the string from the console. Then we

Ask Questions?

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.