inline void TestReader::adjustPrefixStack() {
    // Each time a node is read that is a BAEXML_NODE_TYPE_ELEMENT, we must
    // push an prefixed on the prefix stack.
    if (Obj::e_NODE_TYPE_ELEMENT == d_currentNode->d_type) {

        for (int ii = 0; ii < NUM_ATTRIBUTES; ++ii) {
            const char *prefix = d_currentNode->d_attributes[ii].d_qname;

            if (!prefix || bsl::strncmp("xmlns", prefix, 5)) {
                continue;
            }

            if (':' == prefix[5]) {
                d_prefixes->pushPrefix(
                    prefix + 6, d_currentNode->d_attributes[ii].d_value);
            }
            else {
                // default namespace
                d_prefixes->pushPrefix(
                    "", d_currentNode->d_attributes[ii].d_value);
            }
        }
    }
    else if (Obj::e_NODE_TYPE_NONE == d_currentNode->d_type) {
        d_prefixes->reset();
    }
}
int TestReader::advanceToNextNode() {
    if (!d_currentNode) {
        return -1;                                                    // RETURN
    }

    if (d_currentNode->d_retCode != 0) {
        d_prefixes->reset();
    }
    else {
        d_currentNode++;

        if (d_prefixes && 1 == d_nodeDepth) {
        // The 'TestReader' only recognizes namespace URIs with the prefix
        // (xmlns:) on the top level element, these URIs will be added to the
        // prefix stack.  Namespace URI declarations on any other elements will
        // be treated like normal attributes.  The prefix stack will be reset
        // once the top level element is closed.
            adjustPrefixStack();
        }

        d_nodeDepth += d_currentNode->d_depthChange;
    }

     return d_currentNode->d_retCode;
}
Exemple #3
0
int TestReader::advanceToNextNode() {
    if (!d_currentNode) {
        return -1;                                                    // RETURN
    }

    d_currentNode++;

    if (Obj::e_NODE_TYPE_NONE == d_currentNode->d_type) {
        // If the node type is BAEXML_NODE_TYPE_NONE after we have just
        // incremented to the next node, that mean we are at the end of the
        // document.  An easy way to deal with not incrementing d_currentNode
        // to a forbidden value is to simply decrement it.
        d_currentNode--;
        d_prefixes->reset();
        return 1;                                                     // RETURN
    }

    if (d_prefixes && 1 == d_nodeDepth) {
        // The 'TestReader' only recognizes namespace URIs with the prefix
        // (xmlns:) on the top level element, these URIs will be added to the
        // prefix stack.  Namespace URI declarations on any other elements will
        // be treated like normal attributes.  The prefix stack will be reset
        // once the top level element is closed.
        adjustPrefixStack();
    }

    d_nodeDepth += d_currentNode->d_depthChange;

    return 0;
}
void TestReader::close() {
    if (d_prefixes) {
        d_prefixes->reset();
    }

    d_isOpen = false;
    d_encoding.clear();
    d_nodeDepth = 0;
    d_currentNode = 0;
}