Code example for Node

Methods: getFirstChildgetNodeTypegetNodeValue

     * @param root the <code>Node</code> that contains the desired value 
     * @return a new <code>StringAttribute</code> representing the appropriate value (null if there 
     *         is a parsing error) 
    public static StringAttribute getInstance(Node root) {
        Node node = root.getFirstChild();
        // Strings are allowed to have an empty AttributeValue element and are 
        // just treated as empty strings...we have to handle this case 
        if (node == null)
            return new StringAttribute(""); 
        // get the type of the node 
        short type = node.getNodeType();
        // now see if we have (effectively) a simple string value 
        if ((type == Node.TEXT_NODE) || (type == Node.CDATA_SECTION_NODE)
                || (type == Node.COMMENT_NODE)) {
            return getInstance(node.getNodeValue());
        // there is some confusion in the specifications about what should 
        // happen at this point, but the strict reading of the XMLSchema 
        // specification suggests that this should be an error