Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Java XML Document Problem

Options
  • 29-05-2006 12:37pm
    #1
    Registered Users Posts: 29


    Hi,
    I'm having a problem when I create an xml
    document and set the appropriate attributes I'm getting a 'null'
    output. The code and output are as follows:
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = dbf.newDocumentBuilder();
    Document doc = docBuilder.newDocument();
    
    Element root = doc.createElement("status_tracking");
    root.setAttribute("string","test");
    System.out.println(root);
    
    ==================================

    Outputs: [status_tracking: null]

    Any help appreciated.


Comments

  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    That code works fine for me on 1.4.2 JVM.

    What JVM are you using and make sure your Imports are correct.


  • Registered Users Posts: 29 steve04


    Thanks hobbes,

    The code is running on Java 1.4.

    Are you getting the same debug displayed as: "[status_tracking: null]" or is the value that was inserted into the node being displayed?


  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    I get this as output...
    <status_tracking string="test" />
    

    Here is the code I did.
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    
    public class docXmlSample {
    
    	public static void main(String[] args) throws Exception {
    		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    		DocumentBuilder docBuilder = dbf.newDocumentBuilder();
    		Document doc = docBuilder.newDocument();
    
    		Element root = doc.createElement("status_tracking");
    		root.setAttribute("string","test");
    		System.out.println(root);
    
    	}
    
    }
    


  • Registered Users Posts: 29 steve04


    Thanks Hobbes,
    I realised i was missing a jar when i saw you were getting the correct output :)


Advertisement