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



Home Answers Viewqa Java-Beginners Java dom from string
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Deepak Kumar
Java dom from string
1 Answer(s)      3 years and 8 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


Advertisement
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   ... 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
Advertisements
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 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
Removing HTML from a Java String
Removing HTML from a Java String  Removing HTML from a Java String
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
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
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
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
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
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
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
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
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... main(String args[]) { String str = "This example demonstrates
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
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
Question about parsing XML document with DOM in JAVA.
Question about parsing XML document with DOM in JAVA.  Hi, I need to parse a XML file witch has info about classes. So i have for each class to have its methods and for each method to get its parameters. I'm trying to do
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
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
DOM to SAX and SAX to DOM - XML
Java DOM to SAX and SAX to DOM  Simple API for XML and Document Object Model
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 w1.w3 is a subset
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
how to scrape the data from one website another website using html dom parsing in php
how to scrape the data from one website another website using html dom parsing in php  " how to scrape the data from one website another website using html dom parsing in php" i'm trying this one .please provide code for me
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
Java string
Java string  Strings are immutable.But String s="Hello"; String s1=s+"World"; S.O.P(s1); means printing "Hello World". How
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
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
 

 

 

DMCA.com