Forum Stats

  • 3,873,391 Users
  • 2,266,548 Discussions
  • 7,911,524 Comments

Discussions

Please Help me(R2D2 ur solution didn't work)

843834
843834 Member Posts: 49,972
edited Jul 16, 2001 4:22AM in Java Technology & XML
Please help me! Below is the XML file's content: <root>
<test>Algebraic&amp;Statistical Calculator 48G</test>
</root>

When I want to get the value of <test> using


String value = "";
NodeList children = node.getChildNodes();
for(int i = 0; i < children.getLength(); i++ ) {
Node ci = children.item(i);
if( ci.getNodeType() == Node.ELEMENT_NODE ) {
value = ci.getNodeValue(); }
}

it gives me only Algebraic (all other values get truncated after &)why can't I get the full text inside it?

Comments

  • 843834
    843834 Member Posts: 49,972
    This is example to parse XML file using DOM where the output is printing to screen
    ...
    
    case Node.ELEMENT_NODE: {
    				System.out.print("<");
    				System.out.print(node.getNodeName());
    				NamedNodeMap attrs = node.getAttributes();
    				for (int i = 0; i < attrs.getLength(); i++) {
    					Node attr = attrs.item(i);
    					System.out.print(" " + attr.getNodeName() +
    							 "=\"" + attr.getNodeValue() +
    							 "\"");
    				}
    				System.out.println(">");
    
    				NodeList children = node.getChildNodes();
    				if (children != null) {
    					int len = children.getLength();
    					for (int i = 0; i < len; i++)
    						printDOMTree(children.item(i));
    				}
    
    				break;
    			}
    			case Node.ENTITY_REFERENCE_NODE: {
    				System.out.print("&");
    				System.out.print(node.getNodeName());
    				System.out.print(";");
    				break;
    			}
    ...
    Thus, test has three children: two TEXT_NODE and one ENTITY_REFERENCE_NODE.

    Hope this help
This discussion has been closed.