0

I'm trying to modify a method from a program make it y JAVA 6.3 and I getting the following error "Malformed URL Exception".

I'm using this code.

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        try{
            DocumentBuilder builder = factory.newDocumentBuilder();
            DOMImplementation implementation = builder.getDOMImplementation();
            Document document=implementation.createDocument(null, "xml", null);
           //  Document document=implementation.;
            Element raiz = document.createElement("Correos");// creamos el elemento raiz
            Element elemento = document.createElement("Correo");//creamos un nuevo elemento
            Text text = document.createTextNode("pepito@email.com");//Ingresamos la info

            document.setXmlVersion("1.0");// asignamos la version de nuestro XML
            document.getDocumentElement().appendChild(raiz);  //pegamos la raiz al documento
            raiz.appendChild(elemento); //pegamos el elemento hijo a la raiz
            elemento.appendChild(text); //

            Source source = new DOMSource(document);

            String datos="";

            Result console= new StreamResult(System.out);
            Result result = new StreamResult(new java.io.File("resultado.xml"));//nombre del archivo
            Transformer transformer = TransformerFactory.newInstance().newTransformer();
            transformer.transform(source, result);
            transformer.transform(source, console);
            //transformer.t
           // DocumentBuilder db = new DocumentBuilder();
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db =  dbf.newDocumentBuilder();

            //db.parse(datos) ;
            String xmlX =("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<xml>\n<Correos>\n<Correo>pepito@email.com</Correo>\n</Correos>\n</xml>");
            db.parse(xmlX);
                    //document;
        }catch(Exception e){
            System.err.println("Error:" +e);
        }

As you can see on line 31 I'm "wiring" the XML sending an String.

The XML that I'm using I already test it on several Web navigators and I never get such error as in JAVA.

Basically what I need is to create a "Document" variable because is that type of variable that is returned by the method that I need to modify.

In the original method, not in the upper code, that code(the upper one) is another project that I'm use in order to debug a bigger code, is a method that returns a "Document".

Here the original code that I need to modify.(The following code is inside of a try catch)

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputStream input = HTMLTools.inputStream_GET(url, timeoutMS);
InputStreamReader reader = new InputStreamReader(input, ENCODING_UTF8);
InputSource inSrc = new InputSource(reader);
inSrc.setEncoding(ENCODING_UTF8);

return db.parse(inSrc);

I don't understand very well the purpose of the method parse of the db variable.

I thinking too that maybe I didn't need the db variable since I'm already have a variable type "Document" from the upper code.

I already read the JavaDoc but I don't figure out how this codes works, basically the XML part.

So basically I think that I'm getting messy, Can anyone clarify me what I doing wrong?

Thanks.:-)

E_Blue
  • 1,021
  • 1
  • 20
  • 45
  • What does the url variable contain? That is probably related given that you have a MalformedURLException. – BlackVegetable Jun 14 '12 at 16:32
  • The URL get an string and I need to parse it and convert into a Document type variable. – E_Blue Jun 14 '12 at 17:38
  • Originally the URL answer with an XML but the original server was changed with a internal server and that server answer with an string, so I need to parse it an create a Document variable type with those data. – E_Blue Jun 14 '12 at 17:41

0 Answers0