Buildin one XML String

Discussion in 'Java' started by [XaToA], Jul 31, 2003.

  1. [XaToA]

    [XaToA] Guest

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

    }
     
    [XaToA], Jul 31, 2003
    #1
    1. Advertising

  2. [XaToA]

    [XaToA] Guest

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

    }
     
    [XaToA], Jul 31, 2003
    #2
    1. Advertising

  3. 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(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();
    > }
    >
    > }
     
    Simon Fischer, Jul 31, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. loveNUNO
    Replies:
    2
    Views:
    934
    loveNUNO
    Nov 20, 2003
  2. Tony Prichard
    Replies:
    0
    Views:
    746
    Tony Prichard
    Dec 12, 2003
  3. Andy
    Replies:
    0
    Views:
    542
  4. JiggaHertz
    Replies:
    0
    Views:
    316
    JiggaHertz
    Sep 28, 2004
  5. Kee Nethery
    Replies:
    12
    Views:
    2,100
    Stefan Behnel
    Jun 27, 2009
Loading...

Share This Page