Project

Profile

Help

Download (3.68 KB) Statistics
| Branch: | Revision:

he / src / main / c / Saxon.C.API / XdmNode.h @ a69dd173

1 72bf04c6 Norman Walsh
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 901b6eca O'Neil Delpratt
// Copyright (c) 2021 Saxonica Limited.
3 72bf04c6 Norman Walsh
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8
#ifndef SAXON_XDMNODE_h
9
#define SAXON_XDMNODE_h
10
11
#include "XdmItem.h"
12
#include <string.h>
13
14
typedef enum eXdmNodeKind { DOCUMENT = 9, ELEMENT = 1, ATTRIBUTE = 2, TEXT = 3, COMMENT = 8, PROCESSING_INSTRUCTION = 7, NAMESPACE = 13, UNKNOWN = 0 } XDM_NODE_KIND;
15
16
17
18
class XdmValue;
19
20
class XdmNode : public XdmItem
21
{
22
23
public:
24
25
26
        /* XdmNode(const XdmValue& valuei){
27
         //value = (sxnc_value *)malloc(sizeof(sxnc_value));
28
                 value = valuei.values[0]->getUnderlyingCValue();
29
         xdmSize =1;
30
         refCount = 1;
31
         nodeKind = UNKNOWN;
32
         }*/
33
34
        XdmNode(jobject);
35
36
        XdmNode(XdmNode *parent, jobject, XDM_NODE_KIND);
37
38
        virtual ~XdmNode() {
39 a69dd173 O'Neil Delpratt
        std::cerr<<"XdmNode destructor called"<<std::endl;
40 72bf04c6 Norman Walsh
                if (getRefCount() <1){
41 a69dd173 O'Neil Delpratt
                    delete baseURI;
42 72bf04c6 Norman Walsh
                        delete nodeName;
43
                }
44
45
                //There might be potential issues with children and attribute node not being deleted when the parent node has been deleted
46
                //we need to track this kind of problem.
47
        }
48
49
        virtual bool isAtomic();
50
51
52
        XDM_NODE_KIND getNodeKind();
53
54
        /**
55
         * Get the name of the node, as a string in the form of a EQName
56
         *
57
         * @return the name of the node. In the case of unnamed nodes (for example, text and comment nodes)
58 ead48a5d O'Neil Delpratt
         *         return nullptr.
59 72bf04c6 Norman Walsh
         */
60
        const char * getNodeName();
61
62
        /**
63
         * Get the typed value of this node, as defined in XDM
64
         *
65
         * @return the typed value. If the typed value is a single atomic value, this will be returned
66
         * as an instance of {@link XdmAtomicValue}
67
         */
68
        XdmValue * getTypedValue();
69
70
        const char* getBaseUri();
71
72
        /**
73
         * Get the string value of the item. For a node, this gets the string value
74
         * of the node. For an atomic value, it has the same effect as casting the value
75
         * to a string. In all cases the result is the same as applying the XPath string()
76
         * function.
77
         * <p>For atomic values, the result is the same as the result of calling
78
         * <code>toString</code>. This is not the case for nodes, where <code>toString</code>
79
         * returns an XML serialization of the node.</p>
80
         *
81
         * @return the result of converting the item to a string.
82
         * @deprecated the SaxonProcessor argument. It has been removed from release version 1.2.1
83
         */
84
        const char * getStringValue();
85
86
        
87
        const char * toString();
88
89
        XdmNode* getParent();
90
91
92
        const char* getAttributeValue(const char *str);
93
94
        int getAttributeCount();
95
96
        XdmNode** getAttributeNodes();
97
98
        jobject getUnderlyingValue() {
99
100
                return XdmItem::getUnderlyingValue();
101
102
        }
103
104 501beb26 O'Neil Delpratt
    /**
105
     * Determine whether the item is a node or some other type of item
106
     *
107
     * @return true if the item is a node, false if it is an atomic value or a function (including maps and arrays)
108
     */
109
    bool isNode(){
110
        return true;
111
    }
112
113
114 72bf04c6 Norman Walsh
115
        XdmNode** getChildren();
116
117
        int getChildCount();
118
119
        /**
120
   * Get the type of the object
121
   */
122
        XDM_TYPE getType() {
123
                return XDM_NODE;
124
        }
125
126
        // const char* getOuterXml();
127
128
129
130
private:
131
        const char * baseURI;
132
        const char * nodeName;
133
        XdmNode ** children; //caches child nodes when getChildren method is first called;
134
        int childCount;
135
        XdmNode * parent;
136
        XdmValue * typedValue;
137
        XdmNode ** attrValues;//caches attribute nodes when getAttributeNodes method is first called;
138
        int attrCount;
139
        XDM_NODE_KIND nodeKind;
140
141
};
142
143
#endif