Java Code Examples for net.sf.saxon.om.NodeInfo#getNodeKind()

The following examples show how to use net.sf.saxon.om.NodeInfo#getNodeKind() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SaxonEngine.java    From jlibs with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings({"unchecked"})
public List<?> translate(Object result, NamespaceContext nsContext){
    List nodeList = (List)result;
    int i = 0;
    for(Object item: nodeList){
        if(item instanceof List)
            nodeList.set(i, translate(item, nsContext));
        else{
            NodeInfo node = (NodeInfo)item;
            int type = node.getNodeKind();
            String value = "";
            if(type!=NodeType.DOCUMENT && type!=NodeType.ELEMENT)
                value = node.getStringValue();
            String localName = node.getLocalPart();
            String namespaceURI = node.getURI();
            String qualifiedName = node.getDisplayName();
            String location = SaxonNavigator.INSTANCE.getXPath(node, nsContext);
            NodeItem nodeItem = new NodeItem(type, location, value, localName, namespaceURI, qualifiedName);
            nodeItem.xml = node;
            nodeList.set(i, nodeItem);
        }
        i++;
    }
    return nodeList;
}
 
Example 2
Source File: SaxonEngine.java    From jlibs with Apache License 2.0 5 votes vote down vote up
@Override
public String convert(NodeInfo source){
    switch(source.getNodeKind()){
        case NodeType.ATTRIBUTE:
        case NodeType.NAMESPACE:
            return delegate.convert(source);
    }
    return super.convert(source);
}
 
Example 3
Source File: SaxonEngine.java    From jlibs with Apache License 2.0 5 votes vote down vote up
@Override
public String convert(NodeInfo source){
    switch(source.getNodeKind()){
        case Node.DOCUMENT_NODE:
            return "";
        case Node.TEXT_NODE:
        case Node.CDATA_SECTION_NODE:
            return "text()";
        case Node.COMMENT_NODE:
            return "comment()";
        case Node.PROCESSING_INSTRUCTION_NODE:
            return "processing-instruction('"+source.getDisplayName() +"')";
        case Node.ELEMENT_NODE:
            String prefix = nsContext.getPrefix(source.getURI());
            String name = source.getLocalPart();
            return StringUtil.isEmpty(prefix) ? name : prefix+':'+name;
        case Node.ATTRIBUTE_NODE:
            if(Namespaces.URI_XMLNS.equals(source.getURI()))
                return "namespace::"+source.getLocalPart();
            prefix = nsContext.getPrefix(source.getURI());
            name = source.getLocalPart();
            return '@'+ (StringUtil.isEmpty(prefix) ? name : prefix+':'+name);
        case NodeType.NAMESPACE:
            return "namespace::"+source.getLocalPart();
        default:
            return null;
    }
}
 
Example 4
Source File: SaxonEngine.java    From jlibs with Apache License 2.0 4 votes vote down vote up
public String getXPath(NodeInfo node, NamespaceContext nsContext){
    if(node.getNodeKind()==NodeType.DOCUMENT)
        return "/";
    else
        return getPath(node, new XPathConvertor(nsContext), "/");
}