Java Code Examples for org.w3c.dom.Node.toString()

The following are Jave code examples for showing how to use toString() of the org.w3c.dom.Node class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: fluentxml4j   File: ToStringConverter.java   View Source Code Vote up 6 votes
static String toString(Node node)
{
	if (node == null)
	{
		return null;
	}
	else if (node instanceof Text)
	{
		return ((Text) node).getData();
	}
	else if (node instanceof Attr)
	{
		return ((Attr) node).getValue();
	}

	return node.toString();
}
 
Example 2
Project: OpenJSharp   File: W3CDomHandler.java   View Source Code Vote up 6 votes
public Element getElement(DOMResult r) {
    // JAXP spec is ambiguous about what really happens in this case,
    // so work defensively
    Node n = r.getNode();
    if( n instanceof Document ) {
        return ((Document)n).getDocumentElement();
    }
    if( n instanceof Element )
        return (Element)n;
    if( n instanceof DocumentFragment )
        return (Element)n.getChildNodes().item(0);

    // if the result object contains something strange,
    // it is not a user problem, but it is a JAXB provider's problem.
    // That's why we throw a runtime exception.
    throw new IllegalStateException(n.toString());
}
 
Example 3
Project: openjdk-jdk10   File: W3CDomHandler.java   View Source Code Vote up 6 votes
public Element getElement(DOMResult r) {
    // JAXP spec is ambiguous about what really happens in this case,
    // so work defensively
    Node n = r.getNode();
    if( n instanceof Document ) {
        return ((Document)n).getDocumentElement();
    }
    if( n instanceof Element )
        return (Element)n;
    if( n instanceof DocumentFragment )
        return (Element)n.getChildNodes().item(0);

    // if the result object contains something strange,
    // it is not a user problem, but it is a JAXB provider's problem.
    // That's why we throw a runtime exception.
    throw new IllegalStateException(n.toString());
}