Package net.sf.saxon.om

Examples of net.sf.saxon.om.AxisIterator


    doc.setBaseURI(node.getBaseURI());
   
    boolean hasRootElement = false;
    int i = 0;
    NodeInfo next;
    AxisIterator iter = node.iterateAxis(Axis.CHILD);
    while ((next = (NodeInfo) iter.next()) != null) {
      Node child = convertNodeInfo(next);
      if (child instanceof Element) { // replace fake root with real root
        if (hasRootElement) throw new IllegalAddException(
          "A XOM document must not have more than one root element.");
        doc.setRootElement((Element) child);
View Full Code Here


    if (DEBUG) System.err.println("converting element=" + node.getDisplayName());
    Element elem = new Element(node.getDisplayName(), node.getURI());
    NodeInfo next;
   
    // Append attributes
    AxisIterator iter = node.iterateAxis(Axis.ATTRIBUTE);
    ArrayList prefixes = null;
    while ((next = (NodeInfo) iter.next()) != null) {
      elem.addAttribute((Attribute) convertNodeInfo(next));
     
      // keep track of attributes with prefixes, so we can avoid adding costly
      // additional namespaces declarations below. This safes potentially vast
      // amounts of memory due too XOM's expensive NS declaration storage scheme.
      String prefix = next.getPrefix();
      if (prefix.length() != 0) { // e.g. SOAP
         if (prefixes == null) prefixes = new ArrayList(1);
         prefixes.add(prefix);
      }
    }
   
    // Append namespace declarations (avoids unnecessary redeclarations).
    // For background see net.sf.saxon.om.NamespaceIterator and
    // net.sf.saxon.om.NamespaceDeclarationsImpl
    int[] namespaces = node.getDeclaredNamespaces(NodeInfo.EMPTY_NAMESPACE_LIST);
    int i = 0;
    int nsCode;
    NamePool pool = null;
    while (i < namespaces.length && (nsCode = namespaces[i]) != -1) {
      short uriCode = (short) (nsCode & 0xffff);
      if (uriCode != 0) { // it is not an undeclaration
        if (pool == null) pool = node.getNamePool();
        String uri = pool.getURIFromURICode(uriCode);
        String prefix = pool.getPrefixFromNamespaceCode(nsCode);
       
        if (prefixes != null && prefixes.contains(prefix)) {
          if (DEBUG) System.err.println(
            "Safely ignoring additional namespace declaration for prefix="
            + prefix + ", uri=" + uri);
        }
        else {
          if (DEBUG) System.err.println(
            "Adding additional namespace declaration for prefix="
            + prefix + ", uri=" + uri);
          elem.addNamespaceDeclaration(prefix, uri);
        }
      }
      i++;
    }
    prefixes = null; // help gc
    namespaces = null; // help gc
   
//    // Append namespace declarations (would introduce lots of redundant redeclarations)
//    iter = node.iterateAxis(Axis.NAMESPACE);
//    while ((next = (NodeInfo) iter.next()) != null) {
//      String prefix = next.getLocalPart();
//      String uri = next.getStringValue();
//      if (DEBUG) System.err.println("converted prefix=" + prefix + ", uri=" + uri);
//      elem.addNamespaceDeclaration(prefix, uri);
//    }
   
    // Append children (recursively)
    iter = node.iterateAxis(Axis.CHILD);
    while ((next = (NodeInfo) iter.next()) != null) {
      elem.appendChild(convertNodeInfo(next));
    }
   
    return elem;
  }
View Full Code Here

        _doc.setRootElement(createElement(nodeInfo));
    }

    private Element createElement(NodeInfo nodeInfo) {
        Element el = new Element(nodeInfo.getLocalName());
        AxisIterator iter = nodeInfo.iterateAxis(Axis.CHILD, AnyNodeTest.getInstance());
        while (iter.hasNext()) {
            Item item = iter.next();
            switch (item.getItemType()) {
                case Type.ELEMENT:
                    el.addContent(createElement((NodeInfo) item));
                    break;
                default:
                    try {
                        el.setText(item.getStringValue());
                    } catch (XPathException e) {
                        e.printStackTrace();
                    }
            }
        }
        iter = nodeInfo.iterateAxis(Axis.ATTRIBUTE, AnyNodeTest.getInstance());
        while (iter.hasNext()) {
            Item item = iter.next();
            el.setAttribute(((NodeInfo) item).getLocalName(), ((NodeInfo) item).getStringValue());
        }
        return el;
    }
View Full Code Here

    public StreamSource[] resolve(String moduleURI, String baseURI, String[] locations) throws XPathException {
        NamePool pool = testCase.getNamePool();
        int moduleNC = pool.allocate("", "http://www.w3.org/2005/02/query-test-XQTSCatalog", "module");
        int namespaceNC = pool.allocate("", "", "namespace");
        AxisIterator iter = testCase.iterateAxis(Axis.CHILD, new NameTest(Type.ELEMENT, moduleNC, pool));
        List catalogLocations = new ArrayList(5);
        while (true) {
            NodeInfo m = (NodeInfo)iter.next();
            if (m == null) break;
            if (moduleURI.equals(m.getAttributeValue(namespaceNC))) {
                String moduleRef = m.getStringValue();
                // take a short cut here: hard code information from the catalog
                if (moduleRef.equals("module-defs")) {
View Full Code Here

    }

    public void validate() throws XPathException {
        super.validate();
        connection = typeCheck("connection", connection);
        AxisIterator kids = iterateAxis(Axis.CHILD);
        while(true) {
            NodeInfo curr = (NodeInfo)kids.next();
            if (curr == null) {
                break;
            }
            if (curr instanceof SQLColumn) {
                // OK
View Full Code Here

        // Collect names of columns to be added

        StringBuffer statement = new StringBuffer(120);
        statement.append("INSERT INTO " + table + " (");

        AxisIterator kids = iterateAxis(Axis.CHILD);
        NodeInfo child;
    int cols = 0;
    while (true) {
            child = (NodeInfo)kids.next();
            if (child == null) {
                break;
            }
        if (child instanceof SQLColumn) {
          if (cols++ > 0statement.append(',');
View Full Code Here

    }

    public List getColumnInstructions(Executable exec) throws XPathException {
        List list = new ArrayList(10);

        AxisIterator kids = iterateAxis(Axis.CHILD);
        NodeInfo child;
    while (true) {
            child = (NodeInfo)kids.next();
            if (child == null) {
                break;
            }
        if (child instanceof SQLColumn) {
          list.add(((SQLColumn)child).compile(exec));
View Full Code Here

          checkUnknownAttribute(nc);
        }
    }

    public void validate() throws XPathException {
        AxisIterator kids = iterateAxis(Axis.CHILD);
        while(true) {
            NodeInfo curr = (NodeInfo)kids.next();
            if (curr == null) {
                break;
            }
            if (curr instanceof XSLWhen) {
                if (otherwise!=null) {
View Full Code Here

    * Mark tail-recursive calls on templates and functions.
    */

    public boolean markTailCalls() {
        boolean found = false;
        AxisIterator kids = iterateAxis(Axis.CHILD);
        while(true) {
            NodeInfo curr = (NodeInfo)kids.next();
            if (curr == null) {
                return found;
            }
            if (curr instanceof StyleElement) {
                found |= ((StyleElement)curr).markTailCalls();
View Full Code Here

        int entries = numberOfWhens + (otherwise==null ? 0 : 1);
        Expression[] conditions = new Expression[entries];
        Expression[] actions = new Expression[entries];

        int w = 0;
        AxisIterator kids = iterateAxis(Axis.CHILD);
        while(true) {
            NodeInfo curr = (NodeInfo)kids.next();
            if (curr == null) {
                break;
            }
            if (curr instanceof XSLWhen) {
                conditions[w] = ((XSLWhen)curr).getCondition();
View Full Code Here

TOP

Related Classes of net.sf.saxon.om.AxisIterator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.