JDOM Parser and Namespace how to get clean Content

Posted by senzacionale on Stack Overflow See other posts from Stack Overflow or by senzacionale
Published on 2012-10-04T15:13:34Z Indexed on 2012/10/04 15:38 UTC
Read the original article Hit count: 313

Filed under:
|

MY xml:

<?xml version="1.0"?>
<company xmlns="http://www.xx.com/xx">
    <staff>
        <firstname>yong</firstname>
        <lastname>mook kim</lastname>
        <nickname>mkyong</nickname>
        <salary>100000</salary>
    </staff>
    <staff>
        <firstname>low</firstname>
        <lastname>yin fong</lastname>
        <nickname>fong fong</nickname>
        <salary>200000</salary>
    </staff>
</company> 




 Reader in = new StringReader(message);
            Document document = (Document)saxBuilder.build(in);
            Element rootNode = document.getRootElement();
            List<?> list = rootNode.getChildren("staff", Namespace.getNamespace("xmlns="http://www.infonova.com/MediationFeed""));

            XMLOutputter outp = new XMLOutputter();
            outp.setFormat(Format.getCompactFormat());

            for (int ii = 0; ii < list.size(); ii++) {
                Element node = (Element)list.get(ii);                 

                StringWriter sw = new StringWriter();
                outp.output(node.getContent(), sw);
                StringBuffer sb = sw.getBuffer();

                String xml = sb.toString();
            }

but my xml object looks like this

 <firstname xmlns="http://www.xx.com/xx">yong</firstname>
            <lastname xmlns="http://www.xx.com/xx">mook kim</lastname>
            <nickname xmlns="http://www.xx.com/xx">mkyong</nickname>
            <salary xmlns="http://www.xx.com/xx">100000</salary>

every elemnt has namespace. why this? i don't want namespace... I want the same output as is in xml example like

<firstname>yong</firstname>
            <lastname>mook kim</lastname>
            <nickname>mkyong</nickname>
            <salary>100000</salary>

© Stack Overflow or respective owner

Related posts about Xml

Related posts about jdom