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

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 Tutorials/Questions & Answers:
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... static void main(String[] args) { String url="http://www.roseindia.net
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
Advertisements
Removing HTML from a Java String
Removing HTML from a Java String  Removing HTML from a Java String
remove punctuation from string in java
remove punctuation from string in java  Hi, I want to remove punctuation in text from Java program. How to remove punctuation from string in java... String str = "Welcome to the Java Programming,; ???? .. Here you
Java: Searching a string from doc files
Java: Searching a string from doc files   I want to search a string from DOC, DOCX files in java. Can anyone please help me
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
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
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
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 Write To File From String
Java Write To File From String In this tutorial you will learn how to write to file from string. Write to file from string using java at first we will have... { public static void main(String args[]) { String str = "
Extarct string from PDF
Extarct string from PDF  how can i search a particular character from pdf? also extarct string from a pdf document
Removing characters from a string
Removing characters from a string  Removing characters from a string...(String []args){ String str="Hello 123.you are At 3456"; String...() method removes all blank spaces in the string
jsonelement from string
jsonelement from string  Hi, I have to create jsonelement from string in Java. How to do this? Thanks   Hi, You can use following code: Gson gson = new Gson(); String data ="Hello"; JsonElement ele
Find Longest Word from the string using Java
Find Longest Word from the string using Java Here we are going to find the longest word from the string. For this, we have specified the string which is then splitted into string array using  split() method. Then we have created
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
remove a substring from a string
remove a substring from a string  Please I jave an arraylist composed as follwoing [w1, w2, w3, w4, w1.w2.w3, w2.w3.w4, w3.w4, w2.w4, w1.w3, w1.w2] w2.w4 is a subset of w2.w3.w4 ?how I recognize it also ADS_TO_REPLACE_1 w1.w3
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
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
remove comma from string php
remove comma from string php  How to remove the last comma from the string in PHP
Removing character from a string in sql.
Removing character from a string in sql.  How to remove or replace character from a string
Removing character from a string in sql.
Removing character from a string in sql.  Removing special characters from a string in sql
Stripping of unwanted characters from string
Stripping of unwanted characters from string  how to strip off unwanted characters from a string   Hi Friend, Try this: public class StripCharacters { public String strip(String s) { String st
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
remove comma from string php
remove comma from string php  How to remove the last comma from the string in PHP?   remove last comma from string names = names.replaceAll(",$", ""); //Or a simple substring: if (names.endsWith(",")) { names
Reading string from file timed
Reading string from file timed  So I want to make a file reader/ buffered reader that reads a new line of the textfile, lets say every 30 second. Like it reads the first line, waiting 30 seconds, read the next line and so one
Count Palindromes from the string
Count Palindromes from the string In this section, we are going to find out the number of palindromes from the string. For this, we have allowed the user to input a sentence or string. This string is then break down into tokens using
write a java program for inserting a substring in to the given main string from a given position
write a java program for inserting a substring in to the given main string from a given position  write a java program for inserting a substring in to the given main string from a given position
Remove duplicate characters from the string
Remove duplicate characters from the string In this tutorial, you will learn how to remove duplicate characters from the string. Java has provide several.... Here we are going to remove duplicate characters from the string
PHP get character from String
PHP Get Character From String To get sub string from a String we can use substr() method. Structure of this method is :ADS_TO_REPLACE_1 string substr (string $var, int $initial [, int $len]  ) In the above example we want
How to evaluate the mathematical expression from the string in J2ME.
How to evaluate the mathematical expression from the string in J2ME.  How to evaluate the mathematical expression from the string in J2ME. For example a string containing "24".From the string i want evaluate the mathematical
How to evaluate the mathematical expression from the string in J2ME.
How to evaluate the mathematical expression from the string in J2ME.  How to evaluate the mathematical expression from the string in J2ME. For example a string containing "24".From the string i want evaluate the mathematical
Java convert string to date from format yyyy-mm-dd hh mm ss
Java convert string to date from format yyyy-mm-dd hh mm ss  Hi, I...; /* * Convert String from yyyy-mm-dd hh mm ss * to date object in Java */ public... date into the date format. How to convert string to date from format yyyy-mm-dd
create a string from an array using JavaScript
create a string from an array using JavaScript  How to use "join()" to create a string from an array using JavaScript
How to Remove Repeated Characters from the String?
How to Remove Repeated Characters from the String?  Hi, I trying to develop an application which will remove the repeated characters from... the example of how to remove repeated characters from the string. Please visit
Extracting position of a particular string from a PDF
Extracting position of a particular string from a PDF  I have a pdf form. I want to knw the exact position(location) of a particular string of that form. Using iText I have extracted all the string from the PDF form, but nt able
ModuleNotFoundError: No module named 'nums-from-string'
ModuleNotFoundError: No module named 'nums-from-string'  Hi, My... named 'nums-from-string' How to remove the ModuleNotFoundError: No module named 'nums-from-string' error? Thanks   Hi, In your
Java string
Java string  Strings are immutable.But String s="Hello"; String s1=s+"World"; S.O.P(s1); means printing "Hello World". How
how to get date format in string from date object containing real date in java
how to get date format in string from date object containing real date in java  i want to get data string format from date object where date object containing real date. date frequently vary in from of only month & year
how to get date format in string from date object containing real date in java
how to get date format in string from date object containing real date in java  i want to get data string format from date object where date object containing real date. date frequently vary in from of only month & year
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
how to pass a string from one class to another
how to pass a string from one class to another  hi all, Good morning. I am trying to develop a coding pass a string from one class and declare in other class. the string which i need to pass is the data from an file and i want
Get Character from String
Get Character from String       In this example we will see that how to convert string to array... toCharArray() to convert string to character array. 3. Retrieve character from
Select string from array in objective c
Select string from array in objective c  Hi, I wanted to select a string from the database table in objective c. But somehow it is not working..can...:@"SELECT ic, district, age, race, referralSource, DMRelatedAdmin, postalCode FROM
Radio button with values from a String ArrayList in JSP?
Radio button with values from a String ArrayList in JSP?  Radio button values in JSP ArrayList<String> cs = CourseAssignments.getInstance().getStudentCoursesByName(sname); %> <
to retrieve from radiobox and comparing with a string - Struts
to retrieve from radiobox and comparing with a string  im creating a exam application in jsp which makes students to attend java questions.. created an array of radio buttons below is the code
DOM
DOM  hello, What is DOM?   hii,ADS_TO_REPLACE_1 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 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
Count Characters from the input string Java
Count Characters from the input string of Java In this section, you will learn how to count the occurrence of each character in the string. For this, we have... the string from the console. Firstly we have removed all the spaces between the string
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
How To Read String From Command Line In Java
How To Read String From Command Line In Java In this section we will discuss about how string can be read through the command line. In Java command line... giving from the command line. Command line arguments are passed

Ads