|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 |
|
18 /** |
|
19 @file |
|
20 @publishedAll |
|
21 @released |
|
22 */ |
|
23 #ifndef XMLENGNAMESPACE_H |
|
24 #define XMLENGNAMESPACE_H |
|
25 |
|
26 #include <xml/dom/xmlengnode.h> |
|
27 |
|
28 /** |
|
29 This class represents an existing namespace declaration in the DOM tree or a |
|
30 namespace node returned in RXmlEngNodeSet as a result of some XPath expression. |
|
31 |
|
32 All elements and attributes may have a namespace instance associated with them. |
|
33 Once added to an element, a namespace declaration (instance of |
|
34 TXmlEngNamespace) may be referred to by all attributes and descendants of the |
|
35 element (unless the prefix that this namespace-to-prefix binding uses is |
|
36 overriden somewhere below in the document tree). |
|
37 |
|
38 General rules for namespace handling: |
|
39 |
|
40 - A NULL prefix in the namespace node means NO PREFIX. An empty string "" can |
|
41 be used to specify the absence of a prefix when setting it, however, NULL will |
|
42 be stored and returned. |
|
43 |
|
44 - A NULL value for a namespace URI is legal only with a NULL prefix and is only |
|
45 used in the undeclaration of a namespace (@c xmlns="" ). An empty string "" |
|
46 can be used too, however, it will be returned as NULL. |
|
47 |
|
48 - A NULL or empty string namespace URI with a non-NULL prefix is illegal |
|
49 acording to the XML specification. |
|
50 |
|
51 - The namespace of an element is a default namespace if it has a NULL prefix. |
|
52 |
|
53 - Elements with namespace undeclarations (@c xmlns="" ), have no namespace and |
|
54 are treated as local names. |
|
55 |
|
56 - Attributes do not have a default namespace. Even if a namespace is applied at |
|
57 element scope, the default namespace declaration is not applied to the |
|
58 element's attributes (according to the XML specification). |
|
59 |
|
60 - The namespace of a node (element or attribute) is undefined if no namespace |
|
61 declaration is associated with it. |
|
62 |
|
63 - A node with an undefined namespace is serialized as having no prefix. In |
|
64 general, the DOM API handles the complexity of namespace declaration handling, |
|
65 creating neccessary namespace declarations and undeclaring default namespaces. |
|
66 However, some node-creation methods (e.g. TXmlEngElement::AddNewElementL()) do |
|
67 not ensure that a node created with an undefined namespace (i.e. without a |
|
68 prefix) will be treated after serialization as having the default namespace. |
|
69 |
|
70 Note: |
|
71 Namespace nodes that are the result of XPath expressions have following restrictions: |
|
72 |
|
73 - They cannot be used as namespace definitions, because they are not part of |
|
74 the DOM tree, but rather copies of existing namespace definitions. |
|
75 |
|
76 - The namespace prefix is not available because it is not mandated by the DOM |
|
77 Level 3 XPath API. So, in returned copies of the DOM tree, namespace prefix |
|
78 strings are not preserved and Prefix() returns NULL. |
|
79 */ |
|
80 class TXmlEngNamespace: public TXmlEngNode |
|
81 { |
|
82 friend class TXmlEngElement; |
|
83 friend class TXmlEngNode; |
|
84 |
|
85 public: |
|
86 /** Default constructor */ |
|
87 inline TXmlEngNamespace(); |
|
88 |
|
89 /** |
|
90 Gets the namespace URI |
|
91 @return Namespace URI string or an empty string if the namespace is either |
|
92 NULL or undeclared (@c xmlns="" ) |
|
93 */ |
|
94 IMPORT_C TPtrC8 Uri() const; |
|
95 |
|
96 /** |
|
97 Gets the namespace prefix. |
|
98 @return The prefix bound in the namespace declaration or an empty string |
|
99 when there is a default namespace or if no binding exists |
|
100 */ |
|
101 IMPORT_C TPtrC8 Prefix() const; |
|
102 |
|
103 /** |
|
104 Check if the namespace is default. |
|
105 @return ETrue if the namespace is default (no prefix), EFalse if the |
|
106 namespace is not default (bound to prefix) or the namespace is NULL |
|
107 */ |
|
108 IMPORT_C TBool IsDefault() const; |
|
109 |
|
110 /** |
|
111 Check if the namespace is undefined. A node's namespace is undefined if no |
|
112 namespace declaration is associated with it. This is the same as |
|
113 TXmlEngNode::IsNull(). |
|
114 @return ETrue if the namespace is undefined, EFalse otherwise |
|
115 */ |
|
116 IMPORT_C TBool IsUndefined() const; |
|
117 |
|
118 protected: |
|
119 /** |
|
120 This method is inherited from TXmlEngNode. To prevent its use, no function body |
|
121 has been supplied. The method Uri() should be used instead. |
|
122 |
|
123 @see Uri(). |
|
124 */ |
|
125 inline TPtrC8 NamespaceUri(); |
|
126 |
|
127 protected: |
|
128 /** |
|
129 Constructor |
|
130 @param aPtr Namespace pointer |
|
131 */ |
|
132 inline TXmlEngNamespace(void* aPtr); |
|
133 }; |
|
134 |
|
135 #include <xml/dom/xmlengnamespace.inl> |
|
136 |
|
137 #endif /* XMLENGNAMESPACE_H */ |
|
138 |