Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Buildin one XML String

Reply
Thread Tools

Buildin one XML String

 
 
[XaToA]
Guest
Posts: n/a
 
      07-31-2003
Hello i am trying to build one XML String with DOM but i don't get it.
tha bellow code is my code for generating it.
i don't know how, and in which code part, must i to put into one String.

can you help me?
Thanks

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

public class pruebaConstruirXML {

public void hagoXML(){
try{
DocumentBuilderFactory domFactory =
DocumentBuilderFactory.newInstance();
domFactory.setValidating(false);
domFactory.setCoalescing(true);
domFactory.setExpandEntityReferences(true);
domFactory.setIgnoringElementContentWhitespace(tru e);

DocumentBuilder domBuilder = domFactory.newDocumentBuilder();
Document doc = domBuilder.newDocument();
Element root = doc.createElement("registros");
doc.appendChild(root);

System.out.println(doc);
}catch(Exception e){
System.out.println(e.getMessage());
}
}
public static void main (String [] args){
pruebaConstruirXML p = new pruebaConstruirXML();
p.hagoXML();
}

}


 
Reply With Quote
 
 
 
 
[XaToA]
Guest
Posts: n/a
 
      07-31-2003
i have chage the code but appears this error:
pruebaConstruirXML.java [57:1] cannot resolve symbol
symbol : class DomSource
location: class pruebaConstruirXML
transformer.transform(new DomSource(doc), new
^
1 error

can you help me please? i have import:
import javax.xml.transform.dom.*;
import javax.xml.transform.dom.DOMSource;

the code is now:
import java.io.*;
import java.util.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.*;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.DOMException;



import java.text.SimpleDateFormat;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.hssf.usermodel.*;

public class pruebaConstruirXML {

/** Creates a new instance of pruebaConstruirXML */
public pruebaConstruirXML() {
}
public void hagoXML(){
try{
DocumentBuilderFactory domFactory =
DocumentBuilderFactory.newInstance();
domFactory.setValidating(false);
domFactory.setCoalescing(true);
domFactory.setExpandEntityReferences(true);
domFactory.setIgnoringElementContentWhitespace(tru e);

DocumentBuilder domBuilder = domFactory.newDocumentBuilder();
Document doc = domBuilder.newDocument();
Element root = doc.createElement("registros");
doc.appendChild(root);


Transformer transformer
=TransformerFactory.newInstance().newTransformer() ;
StringWriter result = new StringWriter();
transformer.transform(new DomSource(doc), new
StreamResult(result));
System.out.println(result.toString());

System.out.println(doc);
}catch(Exception e){
System.out.println(e.getMessage());
}
}

public static void main (String [] args){
pruebaConstruirXML p = new pruebaConstruirXML();
p.hagoXML();
}

}



 
Reply With Quote
 
 
 
 
Simon Fischer
Guest
Posts: n/a
 
      07-31-2003
Hi XaToA,

sorry, typo. Of course it's DOMSource, not DomSource. Well, actually, I
think you knew that, since you used the correct spelling in the import
statement

Cheers,
Simon

"[XaToA]" wrote:
>
> i have chage the code but appears this error:
> pruebaConstruirXML.java [57:1] cannot resolve symbol
> symbol : class DomSource
> location: class pruebaConstruirXML
> transformer.transform(new DomSource(doc), new
> ^
> 1 error
>
> can you help me please? i have import:
> import javax.xml.transform.dom.*;
> import javax.xml.transform.dom.DOMSource;
>
> the code is now:
> import java.io.*;
> import java.util.*;
> import javax.xml.parsers.*;
> import org.w3c.dom.*;
> import javax.xml.transform.*;
> import javax.xml.transform.dom.*;
> import javax.xml.transform.dom.DOMSource;
> import javax.xml.transform.stream.*;
>
> import javax.xml.parsers.DocumentBuilderFactory;
> import javax.xml.parsers.FactoryConfigurationError;
> import javax.xml.parsers.ParserConfigurationException;
> import javax.xml.parsers.DocumentBuilder;
> import org.w3c.dom.Document;
> import org.w3c.dom.DOMException;
>
> import java.text.SimpleDateFormat;
> import org.apache.poi.poifs.filesystem.POIFSFileSystem;
> import org.apache.poi.hssf.usermodel.*;
>
> public class pruebaConstruirXML {
>
> /** Creates a new instance of pruebaConstruirXML */
> public pruebaConstruirXML() {
> }
> public void hagoXML(){
> try{
> DocumentBuilderFactory domFactory =
> DocumentBuilderFactory.newInstance();
> domFactory.setValidating(false);
> domFactory.setCoalescing(true);
> domFactory.setExpandEntityReferences(true);
> domFactory.setIgnoringElementContentWhitespace(tru e);
>
> DocumentBuilder domBuilder = domFactory.newDocumentBuilder();
> Document doc = domBuilder.newDocument();
> Element root = doc.createElement("registros");
> doc.appendChild(root);
>
> Transformer transformer
> =TransformerFactory.newInstance().newTransformer() ;
> StringWriter result = new StringWriter();
> transformer.transform(new DomSource(doc), new
> StreamResult(result));
> System.out.println(result.toString());
>
> System.out.println(doc);
> }catch(Exception e){
> System.out.println(e.getMessage());
> }
> }
>
> public static void main (String [] args){
> pruebaConstruirXML p = new pruebaConstruirXML();
> p.hagoXML();
> }
>
> }

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ElementTree.XML(string XML) and ElementTree.fromstring(string XML)not working Kee Nethery Python 12 06-27-2009 06:06 AM
XML schema validation of one xml block based on values from another xml block Andy XML 0 11-18-2004 11:04 PM
problems buildin python interface to fuse JiggaHertz Python 0 09-28-2004 12:19 AM
Help on including one XML document within another XML document using XML Schemas Tony Prichard XML 0 12-12-2003 03:18 PM
Using One XSLT and multiple XML Problem (One is XML and another one is XBRL) loveNUNO XML 2 11-20-2003 06:47 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57