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

The following are Jave code examples for showing how to use lookupNamespaceURI() 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.
Example 1
Project: incubator-netbeans   File: DocumentModelAccess.java   Source Code and License Vote up 6 votes
public String lookupNamespaceURI(Node node, List<? extends Node> pathToRoot) {
    String prefix = node.getPrefix();
    if (prefix == null) prefix = ""; //NOI18N
    String namespace = node.lookupNamespaceURI(prefix);
    if (namespace == null) {
        boolean skipDeeperNodes = true;
        for (Node n : pathToRoot) {
            if (skipDeeperNodes) {
                // The target node has to be inside of pathToRoot. 
                // But it can be not a top element of the list. 
                // It's necessary to skip items until the target node 
                // isn't found in the list.
                if (areSameNodes(n, node)) {
                    skipDeeperNodes = false;
                }
            } else {
                namespace = n.lookupNamespaceURI(prefix);
                if (namespace != null) {
                    break;
                }
            }
        }
    }
    return namespace;
}
 
Example 2
Project: java-tools   File: MFDOMWriter.java   Source Code and License Vote up 6 votes
private static String getPrefixForW3URIs(String uri, Node node)
{
	if ( uri == null || uri.length() == 0)
		return "";
	
	if (uri.equals("http://www.w3.org/XML/1998/namespace"))
		return "xml";

	final String[] w3URIs = {"http://www.w3.org/2001/XMLSchema","http://www.w3.org/2001/XMLSchema-instance"};
	final String[] w3Prefix = {"xs","xsi"};

	if (w3URIs.length == w3Prefix.length)
	{
		for (int i = 0; i < w3Prefix.length; i++ )
		{
			if (uri.equals(w3URIs[i]))
			{
				String prefix = node.lookupNamespaceURI(w3Prefix[i]); 
				if ( prefix == null )
					return w3Prefix[i];
			}
		}
	}
	
	return "";
}
 
Example 3
Project: java-tools   File: XmlTreeOperations.java   Source Code and License Vote up 5 votes
public static String lookupNamespaceURI( Node node, String prefix )
{
	if ( prefix != null && prefix.equals("xml") )
		return "http://www.w3.org/XML/1998/namespace";

	return node.lookupNamespaceURI( prefix );
}