Buildin one XML String

X

[XaToA]

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(true);

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();
}

}
 
X

[XaToA]

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(true);

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();
}

}
 
S

Simon Fischer

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top