DOM to string in C++ Parser

I see this has come up in various forms before, but what's the best way to convert from a DOM Document instance to a string (for saving to a file) using the C++ tools? I found Node::print(...) in the header file, but get a link error as if it's not really there. If you need a suggestion on what features to add, this would sure be one!

You found the right method so I'm not sure why you get a link error. Can you supply some sample code and the linker output?

Similar Messages

  • How to transform DOM into String

    Hi,
    Can any one provide an example of transforming DOM into String using TransformationFactory or any other API of JAXP?
    Regards...
    Shamit

    And for finer output:
          * Prints a textual representation of a DOM object into a text string..
          * @param document DOM object to parse.
          * @return String representation of <i>document</i>.
        static public String toString(Document document) {
            String result = null;
            if (document != null) {
                StringWriter strWtr = new StringWriter();
                StreamResult strResult = new StreamResult(strWtr);
                TransformerFactory tfac = TransformerFactory.newInstance();
                try {
                    Transformer t = tfac.newTransformer();
                    t.setOutputProperty(OutputKeys.ENCODING, "iso-8859-1");
                    t.setOutputProperty(OutputKeys.INDENT, "yes");
                    t.setOutputProperty(OutputKeys.METHOD, "xml"); //xml, html, text
                    t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
                    t.transform(new DOMSource(document.getDocumentElement()), strResult);
                } catch (Exception e) {
                    System.err.println("XML.toString(Document): " + e);
                result = strResult.getWriter().toString();
            return result;
        }//toString()

  • DOM to String & String to DOM too Complicated

    Hi Java Comunity,
    I'm just wondering why one of the simplest tasks on the XML development such as creating (parsing) a DOM from a String and viceversa (Obtaining the XML as String from a DOM Document) is so Complicated.
    Obviously I'm a newbie in JAXP, but not in XML, the common sense dictaminates that these tasks should be as simple as something like:
    String xmlString = "<mytag>...</mytag>";
    org.w3c.dom.Document xmlDoc = new org.w3c.dom.Document(xmlString);
    and
    String anotherXmlString = xmlDoc.getXmlString();
    I already know how to perform these conversions, but I'm just wondering why you Java Developers enjoy making suffer all the programmers in the world with such complicated (and not intuitive) ways to perform simple tasks.
    Comunity, what do you think???

    This needs some cleanup, but it transforms an org.w3c.dom.Document object to a String.
    import java.io.*;
    import java.util.*;
    import javax.xml.transform.*;
    import javax.xml.transform.dom.*;
    import javax.xml.transform.stream.*;
    import org.w3c.dom.*;
    import org.xml.sax.*;
    public static String DocumentToString(Document doc)
    try
    ByteArrayOutputStream out;
    Transformer transformer;
    TransformerFactory tFactory;
    tFactory = TransformerFactory.newInstance();
    transformer = tFactory.newTransformer();
    out = new ByteArrayOutputStream();
    transformer.transform(new DOMSource(doc.getDocumentElement()), new StreamResult(out));
    if (out != null)
    return new String(out.toByteArray());
    else
    return null;
    catch (TransformerException te)
    te.printStackTrace();
    return null;

  • Namespace prefix in created DOM document string

    Hello world,
    I am creating a DOM document using the standard JAXP APIs. The document is not parsed from anywhere, just created using the DOM API factory methods. This document is a SOAP message with the SOAP envelope, header and body elements. Now I need to have this document transformed to an XML string.
    I can manage all this. However, I want to have the SOAP namespace set for the SOAP elements, and I want it set using a prefix (such as "SOAP-ENV" or "env" as in the example below). I have set the envelope, header and body element namespaces to the soap namespace. The rest of the elements inside header and body I have set to null namespace. I want them without any prefix (and what namespace will that be then, default?).
    The problem is, when I transform the document to a string, the namespace is set on the envelope without a prefix, and not on the header or body. I guess this is because the child elements will all inherit the namespace? I tried with xalan and saxon.
    Here is an example of output that would look like what I want:
    <env:Envelope xmlns:env="http://www.w3.org/2002/12/soap-envelope">
    <env:Header>
      <foo>hello</foo>
    </env:Header>
    <env:Body>
       <bar>is open</bar>
    </env:Body>
    </env:Envelope>Here is an example of output that looks like what I got:
    <Envelope xmlns="http://www.w3.org/2002/12/soap-envelope">
    <Header>
      <foo>hello</foo>
    </Header>
    <Body>
       <bar>is open</bar>
    </body>
    </Envelope>So so what am I doing wrong, how should I do it? If my rambling makes no sense, even an example of constructing output like the example of what I want would solve this.. :)
    Thanks,

    You could just create the an attribute like this:
    root.setAttribute("xmlns:env", "http://www.w3.org/2002/12/soap-envelope"); where root is the Envelope element.
    Hello world,
    I am creating a DOM document using the standard JAXP
    APIs. The document is not parsed from anywhere, just
    created using the DOM API factory methods. This
    document is a SOAP message with the SOAP envelope,
    header and body elements. Now I need to have this
    document transformed to an XML string.
    I can manage all this. However, I want to have the
    SOAP namespace set for the SOAP elements, and I want
    it set using a prefix (such as "SOAP-ENV" or "env" as
    in the example below). I have set the envelope,
    header and body element namespaces to the soap
    namespace. The rest of the elements inside header and
    body I have set to null namespace. I want them
    without any prefix (and what namespace will that be
    then, default?).
    The problem is, when I transform the document to a
    string, the namespace is set on the envelope without
    a prefix, and not on the header or body. I guess this
    is because the child elements will all inherit the
    namespace? I tried with xalan and saxon.
    Here is an example of output that would look like
    what I want:
    <env:Envelope
    xmlns:env="http://www.w3.org/2002/12/soap-envelope">
    <env:Header>
    <foo>hello</foo>
    </env:Header>
    <env:Body>
    <bar>is open</bar>
    </env:Body>
    </env:Envelope>Here is an example of output that looks like what I
    got:
    <Envelope
    xmlns="http://www.w3.org/2002/12/soap-envelope">
    <Header>
    <foo>hello</foo>
    </Header>
    <Body>
    <bar>is open</bar>
    </body>
    </Envelope>So so what am I doing wrong, how should I do it? If my
    rambling makes no sense, even an example of
    constructing output like the example of what I want
    would solve this.. :)
    Thanks,

  • Exception on creation of DOM from string xml

    Hi everybody,
    I am creating Dom from a string cml but getting following exception
    org.xml.sax.SAXParseException: name expected
    XML file is < name > < age > 23 < /age > < /name >
    JSP page is:-
    <%@ page import="java.util.*" %>
    <%@ page import="java.net.*" %>
    <%@ page import="javax.xml.parsers.*" %>
    <%@ page import="org.xml.sax.*" %>
    <%@ page import= "org.w3c.dom.*;" %>
    <HTML>
    <BODY>
    <%
    String str= request.getParameter("user");
    out.print(str);
    try{
    Document XMLDoc=DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(str)));
    out.print(XMLDoc);
    catch( SAXParseException s){out.print("Parse excepttion occured   " + s + " Message is --> " + s.getMessage()   );}
    catch (SAXException sa){out.print("Sax Exception occured" + sa +"   " ) ;}
         catch (IOException fgh){out.print("IO Exception occured");}
         catch( ParserConfigurationException e) {out.print("Parser Configuration Exception occured"); }
    %>
    </BODY>
    </HTML>

    Hi Hamsa,
    Did you also create and configure an "Execution Destination"?
    You can test the Metadata destination configuration on Web Service Navigator.
    On the web service navigator (http://hostname:portnumber/wsnavigator) search in the metatda destination you have created for the service you imported in web dynpro as a model. If you can find it there test it on the ws navigator.
    Best regards,
    Yasar

  • Printing XML DOM to string

    When I create an xml document and print it to a string I find that I can only get 900 characters at a time from the output string (using substring) even though its length is reported as > 900
    Running on Oracle 8.1.7

    Sun's resources on XML (including JAXP):
    http://java.sun.com/xml/
    Parser with DOM and SAX support:
    http://xml.apache.org/xerces-j/
    http://www.alphaworks.ibm.com/tech/xml4j
    Of other interest:
    http://xml.apache.org/xalan/
    http://java.apache.org/ecs/index.html
    http://xml.apache.org/cocoon/index.html
    Cameron Purdy
    http://www.tangosol.com
    "Kevin Woo" <[email protected]> wrote in message
    news:[email protected]..
    Hi,
    Would anyone know where I could get a XML DOM to Java String parser,
    which does forward and backward parsing?
    Thanks a bunch,
    Kevin Woo

  • XML string to XML parsing in JCD

    I have stored an XML file as a CLOB in the Oracle DB. While fetching this data into JCD using Oracle OTD, I am getting this CLOB field as a string containing the XML. Now I want to parse this XML string to XML, as I need to map the individual fields to an XSD OTD, which will be my output.
    Kindly suggest a way to achieve this.

    An XSD OTD has an unmarshalFromString() method:
    inputFormat.unmarshalFromString( strData );
    When putting the XML into the CLOB it could be a good idea to wrap an outputstream into a Writer object in order to make certain that the encoding is correct, depending how the data is represented. When retrieving CLOB data using getCharacterStream() you will get a Reader object where the encoding is already given.

  • Problem casting org.w3c.dom.Document to oracle.xml.parser.v2.XMLDocument

    I have the following problem:
    I get my xml-documents as an XMLType from the database and want to compare these using the supplied Oracle class oracle.xml.differ.XMLDiff (i use the java version supplied with Oracle 9i r2).
    XMLType.getDOM() returns the xml-document as a org.w3c.dom.Document,
    what i need for oracle.xml.differ.XMLDiff is a oracle.xml.parser.v2.XMLDocument.
    How can i cast/convert between these two formats?
    thanks!
    p.s. cross-posting with Re: Casting/Converting XMLType to XMLDocument? (but i think this forum is more relevant).

    Hi,
    thanks for the suggestion: i have written the code shown below. It results in a casting error.
    As far as i know, i don't use a oracle.xdb.dom.XDBDocument, i only use a oracle.xdb.XMLType as the input parameter for my conversion-method:
    any new suggestions ???
    p.s. the second method which is commented does work, but is a bit verbose.
       private static oracle.xml.parser.v2.XMLDocument convert2XMLDocument(XMLType xml) {
         // simple version (should work according to tech. doc. 9i r2/ 10g r1 database)
         oracle.xml.parser.v2.XMLDocument doc = null;
         try {
            // n.b. probleem is dat XMLType.getDOM() een w3c.Document object teruggeeft ipv een oracle.XMLDocument.
            System.out.println("convert2XMLDocument(): casting w3c.Document naar oracle.XMLDocument.");
            doc = (oracle.xml.parser.v2.XMLDocument) xml.getDOM(); // public org.w3c.dom.Document getDOM()
            System.out.println("convert2XMLDocument(): done casting w3c.Document naar oracle.XMLDocument.");
         catch (Exception e) {
            e.printStackTrace(System.out);
        return doc;
       private static XMLDocument convert2XMLDocument(XMLType xml) {
         // complex version: works ok !!!
         XMLDocument doc = null;
         try{
            DOMParser parser  = new DOMParser();
            parser.setValidationMode(oracle.xml.parser.v2.XMLParser.NONVALIDATING);
            parser.setPreserveWhitespace (true);   
            parser.parse(new StringReader(xml.getStringVal()));
            doc = parser.getDocument();
        catch ( XMLParseException e ) {
          e.printStackTrace(System.out);
        catch ( SQLException e ) {
          e.printStackTrace(System.out);
        catch ( Exception e ) {
          e.printStackTrace(System.out);
        return doc;
    convert2XMLDocument(): casting w3c.Document naar oracle.XMLDocument.
        java.lang.ClassCastException: oracle.xdb.dom.XDBDocument
         at pnb.bdb.xml.testJDBC.convert2XMLDocument(testJDBC.java:305)
         at pnb.bdb.xml.testJDBC.main(testJDBC.java:187)

  • DOM to String

    Hi,
    I want to transform a xml document (org.w3c.dom.Document) into a String. I use Trax to do it, but it doesn?t work very well. The method I use for the transformation is the folowing one:
    public String toString()
    try
    TransformerFactory tFactory = TransformerFactory.newInstance();
    Transformer transformer = tFactory.newTransformer();
    DOMSource source = new DOMSource(mDocument);
    StringWriter sw = new StringWriter();
    StreamResult result = new StreamResult(sw);
    transformer.transform(source, result);
    return sw.toString();
    catch (Exception e) {
    System.out.println("Error in method toString: "+e.getMessage());
    return null;
    When I use this method to transform, for example, the next document:
    <?xml version="1.0" encoding="UTF-8">
    <Message><C&oacute;digo>3</C&oacute;digo></Message>
    I get the next String:
    <?xml version="1.0" encoding="UTF-8">
    <Message><C&#number;digo>3</C#&number;digo></Message>
    | |
    | |
    243 243
    when I would like to get a String like:
    <?xml version="1.0" encoding="UTF-8">
    <Message><C�digo>3</C�digo></Message>
    What I'm doing bad?

    I think so. I'm going to explain you what the 'program' (sorry, yesterday I wrote 'application' instead of 'program') do exactly.
    1) There is an applet which write a XML operation message that is sended to a servlet. For example:
    <?xml version="1.0" encoding="UTF-8"?>
    <Message><C&oacute;digo>2</C&oacute;digo></Message>
    2) The servlet recives the message, and get 'C&oacute;digo' which is used to write a database query.
    3) Once the servlet gets the results of the query, the servlet writes another XML message with the results of the query, and send it to the applet.
    <?xml version="1.0" encoding="UTF-8"?>
    <Message><C&oacute;digo>2</C&oacute;digo><Result>...</Result></Message>
    4) The applet receives the XML response message, and transformate it into a String, but the string is:
    <?xml version="1.0" encoding="UTF-8"?>
    <Message><C&#243;digo>2</C&#243;digo><Result>...</Result></Message>
    If I use the next code with the message received by the applet, I get 'c&oacute;digo':
    Node vMessageNode = mDocument.getDocumentElement();
    Node vCodeNode = vMessageNode.getFirstChild();
    String vCode = vMessageNode.getNodeName();
    But if I use the method toString (I wrote it yesterday) to convert the whole message into a string, the string contains "&#243;", when I'd like that it had "&oacute".
    What is very strange is that if I use the method toString in the servlet, I obtain the right string (with "&oacute"), while if I use the method toString in the applet, I obtain the wrong string (with"&#243;")
    I'm starting to think that perhaps the problem is in the methods I use to send and receive the xml message:
    public void send (OutputStream out)
    try
    TransformerFactory tFactory = TransformerFactory.newInstance();
    Transformer transformer = tFactory.newTransformer();
    DOMSource source = new DOMSource(m_documento);
    StreamResult result = new StreamResult (out);
    transformer.transform (source, result);
    catch (Exception e)
    System.out.println("Error in method send: " + e.getMessage());
    public Node receive (InputStream in)
    try
    TransformerFactory tFactory = TransformerFactory.newInstance();
    Transformer transformer = tFactory.newTransformer();
    StreamSource source = new StreamSource(in);
    DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
    mDocument = docBuilder.newDocument();
    transformer.transform(source, new DOMResult (m_documento));
    catch (Exception e)
    System.out.println("Error in method receive: " + e.getMessage));
    return null;
    return mDocument;
    What do you think? Thank you very much.

  • Double.parseDouble(String) : Problem to parse large String

    Hello,
    I need to convert A String to a Double in my application without rounding of digits.
    I have used the Double.parseDouble(String) method.
    The maximum string length can be 17 including dot(.)
    So if my String is (of length 17)
    Eg.
    S= �9999999999.999999� then I am getting the double value as
    d= 9999999999.999998(compare the last digit)
    If s = �9999999999.111111� then d = 9999999999.111110
    If s = �9999999999.555555� then d = 9999999999.555555 (result that I want)
    If s = �9999999999.666666� then d = 9999999999.666666 (result that I want)
    If s = �9999999999.777777� then d = 9999999999.777777 (result that I want)
    If s = �9999999999.888888� then d = 9999999999.888887
    If s = �9999999999.999999� then d = 9999999999.999998
    If s = �9123456789.123456� then d = 9123456789.123456
    But string length up to 16 is giving me the accurate result
    So any body can explain me that why it is happening? And how can i get the accurate result.
    Thanks in advanced.

    Hi,
    Thank You for your suggestion. By which i can store
    the big double number in Data base , but at some
    point i require to parse a double value from a Double
    reference.In that case if the Decimal value length
    => 16 then it the last digit changes or rounds.
    coverting 9999999999.999999 Decimal value to double
    value. It gives me 9999999999.999998 and
    9999999999.9999999 gives me the 10000000000.0000000.
    but the Double value 999999999.999999 is ok
    and 999999999.99999999 rounds.Err, is there a follow up question in there?

  • Is is possible to allow multiple date format strings pass DateFormat.parse?

    I'm trying to use DateFormat.parse to validate a date in the 20/12/08 format. I would like to allow users to input 20-12-08 or 20 12 08.
    The code currently looks like this:
    formatter = DateFormat.getDateInstance(DateFormat.SMALL, US);It is currently throwing an exception if 10-12-08 is sent in where as 10/12/08 works just fine.
    Is there a alternate us locale that is more lenient?
    setLenient(true) didn't solve the problem for me. I think that would accept 32/12/08 not 10-12-08.
    I could parse the date string and replace - or ' ' with a /.. Is that best practice?
    What other options do I have? Could I use SimpleDateFormat somehow?
    Thanks for the input

    That just doesn't seem clean. It will work, but I would rather not have a valid application flow use an exception to get its job done.
    The application is also international, so many locales on one format is valid. The US user base seems to think they can type in the date however they want. So passed into the method is the locale, I would have to modify a lot of code to send in a list of valid locales.
    The best solution for me would be to have a locale that would allow - or ' ' or /. That way I still only have to make one call to df.parse and an exception produces an invalid date message. Is that possible?
    Thanks

  • String expected by parse()

    Hi,
    Can someone please let me know the type of String expected by the parse function in java.util.date. When I passed the value 01012003, the parse function returned the exception Unparseable date : "01012003".
    Thanks.

    Can someone please let me know the type of String
    expected by the parse function in java.util.date.
    When I passed the value 01012003, the parse function
    returned the exception Unparseable date : "01012003".I think you need dashes or slashes in order for it to guess what your format is.
    But forget about that. Use the SimpleDateFormat class instead.
    /* dd = day, MM = month, yyyy = year */
    SimpleDateFormat format = new SimpleDateFormat("ddMMyyyy");
    Date date = format.parse("01012003");The format constructor is case sensitive.

  • Would like some help converting an array of strings into multiple parsed string arrays

    Hello everyone.
    this is a very novice question and I sincerely apologize for that, but i need some direction!
    i have an array of strings:
    (('J01',), ('0', '0', '0', '1'))
    (('J02',), ('0', '1', '0', '1'))
    (('J03',), ('0', '0', '0', '0'))
    ect...
    i would like to know what are some of the best ways to gain access to this information (aka, parse it). The field lengths are not static and all those ones and zeros could very possibly be two digits at times (0 = off state, 1-100 = on state), so simply pulling characters out of a given position of the string will not always work.
    what i would like to achieve is to make either separate arrays for each desirable element, eg:
    array one:
    J01
    J02
    J03
    array two:
    0
    0
    0
    array three:
    0
    1
    0
    and so on.
    or maybe even a matrix (if that’s feasible).
    other than that I am totally up for suggestions!!
    thank you very much,
    Grant.

    Assuming fixed structure (not necessarily length of the different numbers or names).

  • XML String to XML Parsing

    I have stored an XML file as a CLOB in the Oracle DB. While fetching this data into JCD in JavaCAPS using Oracle OTD, I am getting this CLOB field as a string containing the XML. Now I want to parse this XML string to XML, as I need to map the individual fields to an XSD OTD, which will be my output.
    Kindly suggest a way to achieve this.

    The forum itself is a good starting point : [http://forum.java.sun.com/thread.jspa?forumID=34&threadID=347151] is a result searching for "parse string"...

  • Oracle XML DOM parser - attribute values are not printing on the screen ??

    Hi Everyone,
    I am just trying to use oracle DOM parser to paerse one of my xml file, java file can be compiled and run agianst a xml file, But I cannot see any attribute values printing on the screen..
    Appreciate if anyone can help, where I have gone wrong please?
    Below is the java file:
    // menna puthe DOMSample eka - duwanawa 19/12/2005
    import java.io.*;
    import java.net.*;
    import org.w3c.dom.*;
    import org.w3c.dom.Node;
    import oracle.xml.parser.v2.*;
    public class DOMSample {  //public class eka ***
    static public void main(String[] argv){  // main method eka ###
    try {
    if (argv.length != 1){
    // Must pass in the name of the XML file...
    System.err.println("Usage: java DOMSample filename");
    System.exit(1);
    // Get an instance of the parser
    DOMParser parser = new DOMParser();
    // Generate a URL from the filename.
    URL url = createURL(argv[0]);
    // Set various parser options: validation on,
    // warnings shown, error stream set to stderr.
    parser.setErrorStream(System.err);
    parser.showWarnings(true);
    // Parse the document.
    parser.parse(url);
    // Obtain the document.
    Document doc = parser.getDocument();
    // Print document elements
    System.out.print("The elements are: ");
    printElements(doc);
    // Print document element attributes
    System.out.println("The attributes of each element are: ");
    printElementAttributes(doc);
    catch (Exception e){
    System.out.println(e.toString());
    } // main method eka ###
    static void printElements(Document doc) {
    NodeList nl = doc.getElementsByTagName("*");
    Node n;
    for (int i=0; i<nl.getLength(); i++){
    n = nl.item(i);
    System.out.print(n.getNodeName() + " ");
    System.out.println();
    static void printElementAttributes(Document doc){
    NodeList nl = doc.getElementsByTagName("*");
    Element e;
    Node n;
    NamedNodeMap nnm;
    String attrname;
    String attrval;
    int i, len;
    len = nl.getLength();
    for (int j=0; j < len; j++){
    e = (Element)nl.item(j);
    System.out.println(e.getTagName() + ":");
    nnm = e.getAttributes();
    if (nnm != null){
    for (i=0; i<nnm.getLength(); i++){
    n = nnm.item(i);
    attrname = n.getNodeName();
    attrval = n.getNodeValue();
    System.out.print(" " + attrname + " = " + attrval);
    System.out.println();
    static URL createURL(String filename) {  // podi 3 Start
    URL url = null;
    try {
    url = new URL(filename);
    } catch (MalformedURLException ex) { /// BBBBBB
    try {
    File f = new File(filename);
    url = f.toURL();
    } catch (MalformedURLException e) {
    System.out.println("Cannot create URL for: " + filename);
    System.exit(0);
    } // BBBBBB
    return url;
    } // podi 3 End
    } //public class eka ***
    // End of program
    output comes as below:
    Isbn:
    Title:
    Price:
    Author:
    Message was edited by:
    chandanal

    Hi Chandanal,
    I edited your code slightly and I was able to get the correct output.
    I changed the following line:
    for (int j=0; j >< len; j++)to:
    for (int j=0; j < len; j++)I have included the complete source below:
    // menna puthe DOMSample eka - duwanawa 19/12/2005
    import java.io.*;
    import java.net.*;
    import org.w3c.dom.*;
    import org.w3c.dom.Node;
    import oracle.xml.parser.v2.*;
    public class DOMSample {
        //public class eka ***
        public static void main(String[] argv) {
            // main method eka ###
            try {
                if (argv.length != 1) {
                    // Must pass in the name of the XML file...
                    System.err.println("Usage: java DOMSample filename");
                    System.exit(1);
                // Get an instance of the parser
                DOMParser parser = new DOMParser();
                // Generate a URL from the filename.
                URL url = createURL(argv[0]);
                // Set various parser options: validation on,
                // warnings shown, error stream set to stderr.
                parser.setErrorStream(System.err);
                parser.showWarnings(true);
                // Parse the document.
                parser.parse(url);
                // Obtain the document.
                Document doc = parser.getDocument();
                // Print document elements
                System.out.print("The elements are: ");
                printElements(doc);
                // Print document element attributes
                System.out.println("The attributes of each element are: ");
                printElementAttributes(doc);
            } catch (Exception e) {
                System.out.println(e.toString());
        // main method eka ###
        static void printElements(Document doc) {
            NodeList nl = doc.getElementsByTagName("*");
            Node n;
            for (int i = 0; i < nl.getLength(); i++) {
                n = nl.item(i);
                System.out.print(n.getNodeName() + " ");
            System.out.println();
        static void printElementAttributes(Document doc) {
            NodeList nl = doc.getElementsByTagName("*");
            Element e;
            Node n;
            NamedNodeMap nnm;
            String attrname;
            String attrval;
            int i, len;
            len = nl.getLength();
            for (int j = 0; j < len; j++) {
                e = (Element)nl.item(j);
                System.out.println(e.getTagName() + ":");
                nnm = e.getAttributes();
                if (nnm != null) {
                    for (i = 0; i < nnm.getLength(); i++) {
                        n = nnm.item(i);
                        attrname = n.getNodeName();
                        attrval = n.getNodeValue();
                        System.out.print(" " + attrname + " = " + attrval);
                System.out.println();
        static URL createURL(String filename) {
            // podi 3 Start
            URL url = null;
            try {
                url = new URL(filename);
            } catch (MalformedURLException ex) {
                /// BBBBBB
                try {
                    File f = new File(filename);
                    url = f.toURL();
                } catch (MalformedURLException e) {
                    System.out.println("Cannot create URL for: " + filename);
                    System.exit(0);
            // BBBBBB
            return url;
        // podi 3 End
    } //public class eka ***-Blaise

Maybe you are looking for