| 1 | /****************************************************************************
|
|---|
| 2 | ** $Id: qdom.cpp 2 2005-11-16 15:49:26Z dmik $
|
|---|
| 3 | **
|
|---|
| 4 | ** Implementation of QDomDocument and related classes.
|
|---|
| 5 | **
|
|---|
| 6 | ** Created : 000518
|
|---|
| 7 | **
|
|---|
| 8 | ** Copyright (C) 1992-2002 Trolltech AS. All rights reserved.
|
|---|
| 9 | **
|
|---|
| 10 | ** This file is part of the xml module of the Qt GUI Toolkit.
|
|---|
| 11 | **
|
|---|
| 12 | ** This file may be distributed under the terms of the Q Public License
|
|---|
| 13 | ** as defined by Trolltech AS of Norway and appearing in the file
|
|---|
| 14 | ** LICENSE.QPL included in the packaging of this file.
|
|---|
| 15 | **
|
|---|
| 16 | ** This file may be distributed and/or modified under the terms of the
|
|---|
| 17 | ** GNU General Public License version 2 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 19 | ** packaging of this file.
|
|---|
| 20 | **
|
|---|
| 21 | ** Licensees holding valid Qt Enterprise Edition licenses may use this
|
|---|
| 22 | ** file in accordance with the Qt Commercial License Agreement provided
|
|---|
| 23 | ** with the Software.
|
|---|
| 24 | **
|
|---|
| 25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
|---|
| 26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|---|
| 27 | **
|
|---|
| 28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
|---|
| 29 | ** information about Qt Commercial License Agreements.
|
|---|
| 30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information.
|
|---|
| 31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
|---|
| 32 | **
|
|---|
| 33 | ** Contact info@trolltech.com if any conditions of this licensing are
|
|---|
| 34 | ** not clear to you.
|
|---|
| 35 | **
|
|---|
| 36 | **********************************************************************/
|
|---|
| 37 |
|
|---|
| 38 | #include "qdom.h"
|
|---|
| 39 |
|
|---|
| 40 | #ifndef QT_NO_DOM
|
|---|
| 41 |
|
|---|
| 42 | #include "qxml.h"
|
|---|
| 43 | #include "qptrlist.h"
|
|---|
| 44 | #include "qdict.h"
|
|---|
| 45 | #include "qtextstream.h"
|
|---|
| 46 | #include "qtextcodec.h"
|
|---|
| 47 | #include "qiodevice.h"
|
|---|
| 48 | #include "qregexp.h"
|
|---|
| 49 | #include "qbuffer.h"
|
|---|
| 50 |
|
|---|
| 51 | /*
|
|---|
| 52 | ### old todo comments -- I don't know if they still apply...
|
|---|
| 53 |
|
|---|
| 54 | If the document dies, remove all pointers to it from children
|
|---|
| 55 | which can not be deleted at this time.
|
|---|
| 56 |
|
|---|
| 57 | If a node dies and has direct children which can not be deleted,
|
|---|
| 58 | then remove the pointer to the parent.
|
|---|
| 59 |
|
|---|
| 60 | createElement and friends create double reference counts.
|
|---|
| 61 | */
|
|---|
| 62 |
|
|---|
| 63 | /*
|
|---|
| 64 | Reference counting:
|
|---|
| 65 |
|
|---|
| 66 | Some simple rules:
|
|---|
| 67 | 1) If an intern object returns a pointer to another intern object
|
|---|
| 68 | then the reference count of the returned object is not increased.
|
|---|
| 69 | 2) If an extern object is created and gets a pointer to some intern
|
|---|
| 70 | object, then the extern object increases the intern objects reference count.
|
|---|
| 71 | 3) If an extern object is deleted, then it decreases the reference count
|
|---|
| 72 | on its associated intern object and deletes it if nobody else hold references
|
|---|
| 73 | on the intern object.
|
|---|
| 74 | */
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 | /*
|
|---|
| 78 | Helper to split a qualified name in the prefix and local name.
|
|---|
| 79 | */
|
|---|
| 80 | static void qt_split_namespace( QString& prefix, QString& name, const QString& qName, bool hasURI )
|
|---|
| 81 | {
|
|---|
| 82 | int i = qName.find( ':' );
|
|---|
| 83 | if ( i == -1 ) {
|
|---|
| 84 | if ( hasURI )
|
|---|
| 85 | prefix = "";
|
|---|
| 86 | else
|
|---|
| 87 | prefix = QString::null;
|
|---|
| 88 | name = qName;
|
|---|
| 89 | } else {
|
|---|
| 90 | prefix = qName.left( i );
|
|---|
| 91 | name = qName.mid( i + 1 );
|
|---|
| 92 | }
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | /*
|
|---|
| 96 | Counter for the QDomNodeListPrivate timestamps.
|
|---|
| 97 | */
|
|---|
| 98 | static volatile long qt_nodeListTime = 0;
|
|---|
| 99 |
|
|---|
| 100 | /**************************************************************
|
|---|
| 101 | *
|
|---|
| 102 | * Private class declerations
|
|---|
| 103 | *
|
|---|
| 104 | **************************************************************/
|
|---|
| 105 |
|
|---|
| 106 | class QDomImplementationPrivate : public QShared
|
|---|
| 107 | {
|
|---|
| 108 | public:
|
|---|
| 109 | QDomImplementationPrivate();
|
|---|
| 110 | ~QDomImplementationPrivate();
|
|---|
| 111 |
|
|---|
| 112 | QDomImplementationPrivate* clone();
|
|---|
| 113 |
|
|---|
| 114 | };
|
|---|
| 115 |
|
|---|
| 116 | class QDomNodePrivate : public QShared
|
|---|
| 117 | {
|
|---|
| 118 | public:
|
|---|
| 119 | QDomNodePrivate( QDomDocumentPrivate*, QDomNodePrivate* parent = 0 );
|
|---|
| 120 | QDomNodePrivate( QDomNodePrivate* n, bool deep );
|
|---|
| 121 | virtual ~QDomNodePrivate();
|
|---|
| 122 |
|
|---|
| 123 | QString nodeName() const { return name; }
|
|---|
| 124 | QString nodeValue() const { return value; }
|
|---|
| 125 | virtual void setNodeValue( const QString& v ) { value = v; }
|
|---|
| 126 |
|
|---|
| 127 | QDomDocumentPrivate* ownerDocument();
|
|---|
| 128 | void setOwnerDocument( QDomDocumentPrivate* doc );
|
|---|
| 129 |
|
|---|
| 130 | virtual QDomNamedNodeMapPrivate* attributes();
|
|---|
| 131 | virtual bool hasAttributes() { return FALSE; }
|
|---|
| 132 | virtual QDomNodePrivate* insertBefore( QDomNodePrivate* newChild, QDomNodePrivate* refChild );
|
|---|
| 133 | virtual QDomNodePrivate* insertAfter( QDomNodePrivate* newChild, QDomNodePrivate* refChild );
|
|---|
| 134 | virtual QDomNodePrivate* replaceChild( QDomNodePrivate* newChild, QDomNodePrivate* oldChild );
|
|---|
| 135 | virtual QDomNodePrivate* removeChild( QDomNodePrivate* oldChild );
|
|---|
| 136 | virtual QDomNodePrivate* appendChild( QDomNodePrivate* newChild );
|
|---|
| 137 |
|
|---|
| 138 | QDomNodePrivate* namedItem( const QString& name );
|
|---|
| 139 |
|
|---|
| 140 | virtual QDomNodePrivate* cloneNode( bool deep = TRUE );
|
|---|
| 141 | virtual void normalize();
|
|---|
| 142 | virtual void clear();
|
|---|
| 143 |
|
|---|
| 144 | QDomNodePrivate* parent() { return hasParent ? ownerNode : 0; }
|
|---|
| 145 | void setParent( QDomNodePrivate *p ) { ownerNode = p; hasParent = TRUE; }
|
|---|
| 146 | void setNoParent() {
|
|---|
| 147 | ownerNode = hasParent ? (QDomNodePrivate*)ownerDocument() : 0;
|
|---|
| 148 | hasParent = FALSE;
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | // Dynamic cast
|
|---|
| 152 | virtual bool isAttr() { return FALSE; }
|
|---|
| 153 | virtual bool isCDATASection() { return FALSE; }
|
|---|
| 154 | virtual bool isDocumentFragment() { return FALSE; }
|
|---|
| 155 | virtual bool isDocument() { return FALSE; }
|
|---|
| 156 | virtual bool isDocumentType() { return FALSE; }
|
|---|
| 157 | virtual bool isElement() { return FALSE; }
|
|---|
| 158 | virtual bool isEntityReference() { return FALSE; }
|
|---|
| 159 | virtual bool isText() { return FALSE; }
|
|---|
| 160 | virtual bool isEntity() { return FALSE; }
|
|---|
| 161 | virtual bool isNotation() { return FALSE; }
|
|---|
| 162 | virtual bool isProcessingInstruction() { return FALSE; }
|
|---|
| 163 | virtual bool isCharacterData() { return FALSE; }
|
|---|
| 164 | virtual bool isComment() { return FALSE; }
|
|---|
| 165 | virtual QDomNode::NodeType nodeType() const { return QDomNode::BaseNode; }
|
|---|
| 166 |
|
|---|
| 167 | virtual void save( QTextStream&, int, int ) const;
|
|---|
| 168 |
|
|---|
| 169 | // Variables
|
|---|
| 170 | QDomNodePrivate* prev;
|
|---|
| 171 | QDomNodePrivate* next;
|
|---|
| 172 | QDomNodePrivate* ownerNode; // either the node's parent or the node's owner document
|
|---|
| 173 | QDomNodePrivate* first;
|
|---|
| 174 | QDomNodePrivate* last;
|
|---|
| 175 |
|
|---|
| 176 | QString name; // this is the local name if prefix != null
|
|---|
| 177 | QString value;
|
|---|
| 178 | QString prefix; // set this only for ElementNode and AttributeNode
|
|---|
| 179 | QString namespaceURI; // set this only for ElementNode and AttributeNode
|
|---|
| 180 | bool createdWithDom1Interface;
|
|---|
| 181 | bool hasParent;
|
|---|
| 182 | };
|
|---|
| 183 |
|
|---|
| 184 | class QDomNodeListPrivate : public QShared
|
|---|
| 185 | {
|
|---|
| 186 | public:
|
|---|
| 187 | QDomNodeListPrivate( QDomNodePrivate* );
|
|---|
| 188 | QDomNodeListPrivate( QDomNodePrivate*, const QString& );
|
|---|
| 189 | QDomNodeListPrivate( QDomNodePrivate*, const QString&, const QString& );
|
|---|
| 190 | virtual ~QDomNodeListPrivate();
|
|---|
| 191 |
|
|---|
| 192 | virtual bool operator== ( const QDomNodeListPrivate& ) const;
|
|---|
| 193 | virtual bool operator!= ( const QDomNodeListPrivate& ) const;
|
|---|
| 194 |
|
|---|
| 195 | void createList();
|
|---|
| 196 | virtual QDomNodePrivate* item( int index );
|
|---|
| 197 | virtual uint length() const;
|
|---|
| 198 |
|
|---|
| 199 | QDomNodePrivate* node_impl;
|
|---|
| 200 | QString tagname;
|
|---|
| 201 | QString nsURI;
|
|---|
| 202 | QPtrList<QDomNodePrivate> list;
|
|---|
| 203 | long timestamp;
|
|---|
| 204 | };
|
|---|
| 205 |
|
|---|
| 206 | class QDomNamedNodeMapPrivate : public QShared
|
|---|
| 207 | {
|
|---|
| 208 | public:
|
|---|
| 209 | QDomNamedNodeMapPrivate( QDomNodePrivate* );
|
|---|
| 210 | ~QDomNamedNodeMapPrivate();
|
|---|
| 211 |
|
|---|
| 212 | QDomNodePrivate* namedItem( const QString& name ) const;
|
|---|
| 213 | QDomNodePrivate* namedItemNS( const QString& nsURI, const QString& localName ) const;
|
|---|
| 214 | QDomNodePrivate* setNamedItem( QDomNodePrivate* arg );
|
|---|
| 215 | QDomNodePrivate* setNamedItemNS( QDomNodePrivate* arg );
|
|---|
| 216 | QDomNodePrivate* removeNamedItem( const QString& name );
|
|---|
| 217 | QDomNodePrivate* item( int index ) const;
|
|---|
| 218 | uint length() const;
|
|---|
| 219 | bool contains( const QString& name ) const;
|
|---|
| 220 | bool containsNS( const QString& nsURI, const QString & localName ) const;
|
|---|
| 221 |
|
|---|
| 222 | /**
|
|---|
| 223 | * Remove all children from the map.
|
|---|
| 224 | */
|
|---|
| 225 | void clearMap();
|
|---|
| 226 | bool isReadOnly() { return readonly; }
|
|---|
| 227 | void setReadOnly( bool r ) { readonly = r; }
|
|---|
| 228 | bool isAppendToParent() { return appendToParent; }
|
|---|
| 229 | /**
|
|---|
| 230 | * If TRUE, then the node will redirect insert/remove calls
|
|---|
| 231 | * to its parent by calling QDomNodePrivate::appendChild or removeChild.
|
|---|
| 232 | * In addition the map wont increase or decrease the reference count
|
|---|
| 233 | * of the nodes it contains.
|
|---|
| 234 | *
|
|---|
| 235 | * By default this value is FALSE and the map will handle reference counting
|
|---|
| 236 | * by itself.
|
|---|
| 237 | */
|
|---|
| 238 | void setAppendToParent( bool b ) { appendToParent = b; }
|
|---|
| 239 |
|
|---|
| 240 | /**
|
|---|
| 241 | * Creates a copy of the map. It is a deep copy
|
|---|
| 242 | * that means that all children are cloned.
|
|---|
| 243 | */
|
|---|
| 244 | QDomNamedNodeMapPrivate* clone( QDomNodePrivate* parent );
|
|---|
| 245 |
|
|---|
| 246 | // Variables
|
|---|
| 247 | QDict<QDomNodePrivate> map;
|
|---|
| 248 | QDomNodePrivate* parent;
|
|---|
| 249 | bool readonly;
|
|---|
| 250 | bool appendToParent;
|
|---|
| 251 | };
|
|---|
| 252 |
|
|---|
| 253 | class QDomDocumentTypePrivate : public QDomNodePrivate
|
|---|
| 254 | {
|
|---|
| 255 | public:
|
|---|
| 256 | QDomDocumentTypePrivate( QDomDocumentPrivate*, QDomNodePrivate* parent = 0 );
|
|---|
| 257 | QDomDocumentTypePrivate( QDomDocumentTypePrivate* n, bool deep );
|
|---|
| 258 | ~QDomDocumentTypePrivate();
|
|---|
| 259 | void init();
|
|---|
| 260 |
|
|---|
| 261 | // Reimplemented from QDomNodePrivate
|
|---|
| 262 | QDomNodePrivate* cloneNode( bool deep = TRUE );
|
|---|
| 263 | QDomNodePrivate* insertBefore( QDomNodePrivate* newChild, QDomNodePrivate* refChild );
|
|---|
| 264 | QDomNodePrivate* insertAfter( QDomNodePrivate* newChild, QDomNodePrivate* refChild );
|
|---|
| 265 | QDomNodePrivate* replaceChild( QDomNodePrivate* newChild, QDomNodePrivate* oldChild );
|
|---|
| 266 | QDomNodePrivate* removeChild( QDomNodePrivate* oldChild );
|
|---|
| 267 | QDomNodePrivate* appendChild( QDomNodePrivate* newChild );
|
|---|
| 268 |
|
|---|
| 269 | bool isDocumentType() { return TRUE; }
|
|---|
| 270 | QDomNode::NodeType nodeType() const { return QDomNode::DocumentTypeNode; }
|
|---|
| 271 |
|
|---|
| 272 | void save( QTextStream& s, int, int ) const;
|
|---|
| 273 |
|
|---|
| 274 | // Variables
|
|---|
| 275 | QDomNamedNodeMapPrivate* entities;
|
|---|
| 276 | QDomNamedNodeMapPrivate* notations;
|
|---|
| 277 | QString publicId;
|
|---|
| 278 | QString systemId;
|
|---|
| 279 | QString internalSubset;
|
|---|
| 280 | };
|
|---|
| 281 |
|
|---|
| 282 | class QDomDocumentFragmentPrivate : public QDomNodePrivate
|
|---|
| 283 | {
|
|---|
| 284 | public:
|
|---|
| 285 | QDomDocumentFragmentPrivate( QDomDocumentPrivate*, QDomNodePrivate* parent = 0 );
|
|---|
| 286 | QDomDocumentFragmentPrivate( QDomNodePrivate* n, bool deep );
|
|---|
| 287 | ~QDomDocumentFragmentPrivate();
|
|---|
| 288 |
|
|---|
| 289 | // Reimplemented from QDomNodePrivate
|
|---|
| 290 | QDomNodePrivate* cloneNode( bool deep = TRUE );
|
|---|
| 291 | bool isDocumentFragment() { return TRUE; }
|
|---|
| 292 | QDomNode::NodeType nodeType() const { return QDomNode::DocumentFragmentNode; }
|
|---|
| 293 | };
|
|---|
| 294 |
|
|---|
| 295 | class QDomCharacterDataPrivate : public QDomNodePrivate
|
|---|
| 296 | {
|
|---|
| 297 | public:
|
|---|
| 298 | QDomCharacterDataPrivate( QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& data );
|
|---|
| 299 | QDomCharacterDataPrivate( QDomCharacterDataPrivate* n, bool deep );
|
|---|
| 300 | ~QDomCharacterDataPrivate();
|
|---|
| 301 |
|
|---|
| 302 | uint dataLength() const;
|
|---|
| 303 | QString substringData( unsigned long offset, unsigned long count ) const;
|
|---|
| 304 | void appendData( const QString& arg );
|
|---|
| 305 | void insertData( unsigned long offset, const QString& arg );
|
|---|
| 306 | void deleteData( unsigned long offset, unsigned long count );
|
|---|
| 307 | void replaceData( unsigned long offset, unsigned long count, const QString& arg );
|
|---|
| 308 |
|
|---|
| 309 | // Reimplemented from QDomNodePrivate
|
|---|
| 310 | bool isCharacterData() { return TRUE; }
|
|---|
| 311 | QDomNode::NodeType nodeType() const { return QDomNode::CharacterDataNode; }
|
|---|
| 312 | QDomNodePrivate* cloneNode( bool deep = TRUE );
|
|---|
| 313 |
|
|---|
| 314 | };
|
|---|
| 315 |
|
|---|
| 316 | class QDomTextPrivate : public QDomCharacterDataPrivate
|
|---|
| 317 | {
|
|---|
| 318 | public:
|
|---|
| 319 | QDomTextPrivate( QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& value );
|
|---|
| 320 | QDomTextPrivate( QDomTextPrivate* n, bool deep );
|
|---|
| 321 | ~QDomTextPrivate();
|
|---|
| 322 |
|
|---|
| 323 | QDomTextPrivate* splitText( int offset );
|
|---|
| 324 |
|
|---|
| 325 | // Reimplemented from QDomNodePrivate
|
|---|
| 326 | QDomNodePrivate* cloneNode( bool deep = TRUE );
|
|---|
| 327 | bool isText() { return TRUE; }
|
|---|
| 328 | QDomNode::NodeType nodeType() const { return QDomNode::TextNode; }
|
|---|
| 329 | void save( QTextStream& s, int, int ) const;
|
|---|
| 330 |
|
|---|
| 331 | };
|
|---|
| 332 |
|
|---|
| 333 | class QDomAttrPrivate : public QDomNodePrivate
|
|---|
| 334 | {
|
|---|
| 335 | public:
|
|---|
| 336 | QDomAttrPrivate( QDomDocumentPrivate*, QDomNodePrivate*, const QString& name );
|
|---|
| 337 | QDomAttrPrivate( QDomDocumentPrivate*, QDomNodePrivate*, const QString& nsURI, const QString& qName );
|
|---|
| 338 | QDomAttrPrivate( QDomAttrPrivate* n, bool deep );
|
|---|
| 339 | ~QDomAttrPrivate();
|
|---|
| 340 |
|
|---|
| 341 | bool specified() const;
|
|---|
| 342 |
|
|---|
| 343 | // Reimplemented from QDomNodePrivate
|
|---|
| 344 | void setNodeValue( const QString& v );
|
|---|
| 345 | QDomNodePrivate* cloneNode( bool deep = TRUE );
|
|---|
| 346 | bool isAttr() { return TRUE; }
|
|---|
| 347 | QDomNode::NodeType nodeType() const { return QDomNode::AttributeNode; }
|
|---|
| 348 | void save( QTextStream& s, int, int ) const;
|
|---|
| 349 |
|
|---|
| 350 | // Variables
|
|---|
| 351 | bool m_specified;
|
|---|
| 352 | };
|
|---|
| 353 |
|
|---|
| 354 | class QDomElementPrivate : public QDomNodePrivate
|
|---|
| 355 | {
|
|---|
| 356 | public:
|
|---|
| 357 | QDomElementPrivate( QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& name );
|
|---|
| 358 | QDomElementPrivate( QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& nsURI, const QString& qName );
|
|---|
| 359 | QDomElementPrivate( QDomElementPrivate* n, bool deep );
|
|---|
| 360 | ~QDomElementPrivate();
|
|---|
| 361 |
|
|---|
| 362 | QString attribute( const QString& name, const QString& defValue ) const;
|
|---|
| 363 | QString attributeNS( const QString& nsURI, const QString& localName, const QString& defValue ) const;
|
|---|
| 364 | void setAttribute( const QString& name, const QString& value );
|
|---|
| 365 | void setAttributeNS( const QString& nsURI, const QString& qName, const QString& newValue );
|
|---|
| 366 | void removeAttribute( const QString& name );
|
|---|
| 367 | QDomAttrPrivate* attributeNode( const QString& name);
|
|---|
| 368 | QDomAttrPrivate* attributeNodeNS( const QString& nsURI, const QString& localName );
|
|---|
| 369 | QDomAttrPrivate* setAttributeNode( QDomAttrPrivate* newAttr );
|
|---|
| 370 | QDomAttrPrivate* setAttributeNodeNS( QDomAttrPrivate* newAttr );
|
|---|
| 371 | QDomAttrPrivate* removeAttributeNode( QDomAttrPrivate* oldAttr );
|
|---|
| 372 | bool hasAttribute( const QString& name );
|
|---|
| 373 | bool hasAttributeNS( const QString& nsURI, const QString& localName );
|
|---|
| 374 |
|
|---|
| 375 | QString text();
|
|---|
| 376 |
|
|---|
| 377 | // Reimplemented from QDomNodePrivate
|
|---|
| 378 | QDomNamedNodeMapPrivate* attributes() { return m_attr; }
|
|---|
| 379 | bool hasAttributes() { return ( m_attr->length() > 0 ); }
|
|---|
| 380 | bool isElement() { return TRUE; }
|
|---|
| 381 | QDomNode::NodeType nodeType() const { return QDomNode::ElementNode; }
|
|---|
| 382 | QDomNodePrivate* cloneNode( bool deep = TRUE );
|
|---|
| 383 | void save( QTextStream& s, int, int ) const;
|
|---|
| 384 |
|
|---|
| 385 | // Variables
|
|---|
| 386 | QDomNamedNodeMapPrivate* m_attr;
|
|---|
| 387 | };
|
|---|
| 388 |
|
|---|
| 389 |
|
|---|
| 390 | class QDomCommentPrivate : public QDomCharacterDataPrivate
|
|---|
| 391 | {
|
|---|
| 392 | public:
|
|---|
| 393 | QDomCommentPrivate( QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& value );
|
|---|
| 394 | QDomCommentPrivate( QDomCommentPrivate* n, bool deep );
|
|---|
| 395 | ~QDomCommentPrivate();
|
|---|
| 396 |
|
|---|
| 397 | // Reimplemented from QDomNodePrivate
|
|---|
| 398 | QDomNodePrivate* cloneNode( bool deep = TRUE );
|
|---|
| 399 | bool isComment() { return TRUE; }
|
|---|
| 400 | QDomNode::NodeType nodeType() const { return QDomNode::CommentNode; }
|
|---|
| 401 | void save( QTextStream& s, int, int ) const;
|
|---|
| 402 |
|
|---|
| 403 | };
|
|---|
| 404 |
|
|---|
| 405 | class QDomCDATASectionPrivate : public QDomTextPrivate
|
|---|
| 406 | {
|
|---|
| 407 | public:
|
|---|
| 408 | QDomCDATASectionPrivate( QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& value );
|
|---|
| 409 | QDomCDATASectionPrivate( QDomCDATASectionPrivate* n, bool deep );
|
|---|
| 410 | ~QDomCDATASectionPrivate();
|
|---|
| 411 |
|
|---|
| 412 | // Reimplemented from QDomNodePrivate
|
|---|
| 413 | QDomNodePrivate* cloneNode( bool deep = TRUE );
|
|---|
| 414 | bool isCDATASection() { return TRUE; }
|
|---|
| 415 | QDomNode::NodeType nodeType() const { return QDomNode::CDATASectionNode; }
|
|---|
| 416 | void save( QTextStream& s, int, int ) const;
|
|---|
| 417 |
|
|---|
| 418 | };
|
|---|
| 419 |
|
|---|
| 420 | class QDomNotationPrivate : public QDomNodePrivate
|
|---|
| 421 | {
|
|---|
| 422 | public:
|
|---|
| 423 | QDomNotationPrivate( QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& name,
|
|---|
| 424 | const QString& pub, const QString& sys );
|
|---|
| 425 | QDomNotationPrivate( QDomNotationPrivate* n, bool deep );
|
|---|
| 426 | ~QDomNotationPrivate();
|
|---|
| 427 |
|
|---|
| 428 | // Reimplemented from QDomNodePrivate
|
|---|
| 429 | QDomNodePrivate* cloneNode( bool deep = TRUE );
|
|---|
| 430 | bool isNotation() { return TRUE; }
|
|---|
| 431 | QDomNode::NodeType nodeType() const { return QDomNode::NotationNode; }
|
|---|
| 432 | void save( QTextStream& s, int, int ) const;
|
|---|
| 433 |
|
|---|
| 434 | // Variables
|
|---|
| 435 | QString m_sys;
|
|---|
| 436 | QString m_pub;
|
|---|
| 437 | };
|
|---|
| 438 |
|
|---|
| 439 | class QDomEntityPrivate : public QDomNodePrivate
|
|---|
| 440 | {
|
|---|
| 441 | public:
|
|---|
| 442 | QDomEntityPrivate( QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& name,
|
|---|
| 443 | const QString& pub, const QString& sys, const QString& notation );
|
|---|
| 444 | QDomEntityPrivate( QDomEntityPrivate* n, bool deep );
|
|---|
| 445 | ~QDomEntityPrivate();
|
|---|
| 446 |
|
|---|
| 447 | // Reimplemented from QDomNodePrivate
|
|---|
| 448 | QDomNodePrivate* cloneNode( bool deep = TRUE );
|
|---|
| 449 | bool isEntity() { return TRUE; }
|
|---|
| 450 | QDomNode::NodeType nodeType() const { return QDomNode::EntityNode; }
|
|---|
| 451 | void save( QTextStream& s, int, int ) const;
|
|---|
| 452 |
|
|---|
| 453 | // Variables
|
|---|
| 454 | QString m_sys;
|
|---|
| 455 | QString m_pub;
|
|---|
| 456 | QString m_notationName;
|
|---|
| 457 | };
|
|---|
| 458 |
|
|---|
| 459 | class QDomEntityReferencePrivate : public QDomNodePrivate
|
|---|
| 460 | {
|
|---|
| 461 | public:
|
|---|
| 462 | QDomEntityReferencePrivate( QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& name );
|
|---|
| 463 | QDomEntityReferencePrivate( QDomNodePrivate* n, bool deep );
|
|---|
| 464 | ~QDomEntityReferencePrivate();
|
|---|
| 465 |
|
|---|
| 466 | // Reimplemented from QDomNodePrivate
|
|---|
| 467 | QDomNodePrivate* cloneNode( bool deep = TRUE );
|
|---|
| 468 | bool isEntityReference() { return TRUE; }
|
|---|
| 469 | QDomNode::NodeType nodeType() const { return QDomNode::EntityReferenceNode; }
|
|---|
| 470 | void save( QTextStream& s, int, int ) const;
|
|---|
| 471 | };
|
|---|
| 472 |
|
|---|
| 473 | class QDomProcessingInstructionPrivate : public QDomNodePrivate
|
|---|
| 474 | {
|
|---|
| 475 | public:
|
|---|
| 476 | QDomProcessingInstructionPrivate( QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& target,
|
|---|
| 477 | const QString& data);
|
|---|
| 478 | QDomProcessingInstructionPrivate( QDomProcessingInstructionPrivate* n, bool deep );
|
|---|
| 479 | ~QDomProcessingInstructionPrivate();
|
|---|
| 480 |
|
|---|
| 481 | // Reimplemented from QDomNodePrivate
|
|---|
| 482 | QDomNodePrivate* cloneNode( bool deep = TRUE );
|
|---|
| 483 | bool isProcessingInstruction() { return TRUE; }
|
|---|
| 484 | QDomNode::NodeType nodeType() const { return QDomNode::ProcessingInstructionNode; }
|
|---|
| 485 | void save( QTextStream& s, int, int ) const;
|
|---|
| 486 | };
|
|---|
| 487 |
|
|---|
| 488 | class QDomDocumentPrivate : public QDomNodePrivate
|
|---|
| 489 | {
|
|---|
| 490 | public:
|
|---|
| 491 | QDomDocumentPrivate();
|
|---|
| 492 | QDomDocumentPrivate( const QString& name );
|
|---|
| 493 | QDomDocumentPrivate( QDomDocumentTypePrivate* dt );
|
|---|
| 494 | QDomDocumentPrivate( QDomDocumentPrivate* n, bool deep );
|
|---|
| 495 | ~QDomDocumentPrivate();
|
|---|
| 496 |
|
|---|
| 497 | bool setContent( QXmlInputSource *source, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn );
|
|---|
| 498 | bool setContent( QXmlInputSource *source, QXmlReader *reader, QString *errorMsg, int *errorLine, int *errorColumn );
|
|---|
| 499 |
|
|---|
| 500 | // Attributes
|
|---|
| 501 | QDomDocumentTypePrivate* doctype() { return type; };
|
|---|
| 502 | QDomImplementationPrivate* implementation() { return impl; };
|
|---|
| 503 | QDomElementPrivate* documentElement();
|
|---|
| 504 |
|
|---|
| 505 | // Factories
|
|---|
| 506 | QDomElementPrivate* createElement( const QString& tagName );
|
|---|
| 507 | QDomElementPrivate* createElementNS( const QString& nsURI, const QString& qName );
|
|---|
| 508 | QDomDocumentFragmentPrivate* createDocumentFragment();
|
|---|
| 509 | QDomTextPrivate* createTextNode( const QString& data );
|
|---|
| 510 | QDomCommentPrivate* createComment( const QString& data );
|
|---|
| 511 | QDomCDATASectionPrivate* createCDATASection( const QString& data );
|
|---|
| 512 | QDomProcessingInstructionPrivate* createProcessingInstruction( const QString& target, const QString& data );
|
|---|
| 513 | QDomAttrPrivate* createAttribute( const QString& name );
|
|---|
| 514 | QDomAttrPrivate* createAttributeNS( const QString& nsURI, const QString& qName );
|
|---|
| 515 | QDomEntityReferencePrivate* createEntityReference( const QString& name );
|
|---|
| 516 |
|
|---|
| 517 | QDomNodePrivate* importNode( const QDomNodePrivate* importedNode, bool deep );
|
|---|
| 518 |
|
|---|
| 519 | // Reimplemented from QDomNodePrivate
|
|---|
| 520 | QDomNodePrivate* cloneNode( bool deep = TRUE );
|
|---|
| 521 | bool isDocument() { return TRUE; }
|
|---|
| 522 | QDomNode::NodeType nodeType() const { return QDomNode::DocumentNode; }
|
|---|
| 523 | void clear();
|
|---|
| 524 | void save( QTextStream&, int, int ) const;
|
|---|
| 525 |
|
|---|
| 526 | // Variables
|
|---|
| 527 | QDomImplementationPrivate* impl;
|
|---|
| 528 | QDomDocumentTypePrivate* type;
|
|---|
| 529 | };
|
|---|
| 530 |
|
|---|
| 531 | /**************************************************************
|
|---|
| 532 | *
|
|---|
| 533 | * QDomHandler
|
|---|
| 534 | *
|
|---|
| 535 | **************************************************************/
|
|---|
| 536 |
|
|---|
| 537 | class QDomHandler : public QXmlDefaultHandler
|
|---|
| 538 | {
|
|---|
| 539 | public:
|
|---|
| 540 | QDomHandler( QDomDocumentPrivate* d, bool namespaceProcessing );
|
|---|
| 541 | ~QDomHandler();
|
|---|
| 542 |
|
|---|
| 543 | // content handler
|
|---|
| 544 | bool endDocument();
|
|---|
| 545 | bool startElement( const QString& nsURI, const QString& localName, const QString& qName, const QXmlAttributes& atts );
|
|---|
| 546 | bool endElement( const QString& nsURI, const QString& localName, const QString& qName );
|
|---|
| 547 | bool characters( const QString& ch );
|
|---|
| 548 | bool processingInstruction( const QString& target, const QString& data );
|
|---|
| 549 | bool skippedEntity( const QString& name );
|
|---|
| 550 |
|
|---|
| 551 | // error handler
|
|---|
| 552 | bool fatalError( const QXmlParseException& exception );
|
|---|
| 553 |
|
|---|
| 554 | // lexical handler
|
|---|
| 555 | bool startCDATA();
|
|---|
| 556 | bool endCDATA();
|
|---|
| 557 | bool startEntity( const QString & );
|
|---|
| 558 | bool endEntity( const QString & );
|
|---|
| 559 | bool startDTD( const QString& name, const QString& publicId, const QString& systemId );
|
|---|
| 560 | bool comment( const QString& ch );
|
|---|
| 561 |
|
|---|
| 562 | // decl handler
|
|---|
| 563 | bool externalEntityDecl( const QString &name, const QString &publicId, const QString &systemId ) ;
|
|---|
| 564 |
|
|---|
| 565 | // DTD handler
|
|---|
| 566 | bool notationDecl( const QString & name, const QString & publicId, const QString & systemId );
|
|---|
| 567 | bool unparsedEntityDecl( const QString &name, const QString &publicId, const QString &systemId, const QString ¬ationName ) ;
|
|---|
| 568 |
|
|---|
| 569 | QString errorMsg;
|
|---|
| 570 | int errorLine;
|
|---|
| 571 | int errorColumn;
|
|---|
| 572 |
|
|---|
| 573 | private:
|
|---|
| 574 | QDomDocumentPrivate *doc;
|
|---|
| 575 | QDomNodePrivate *node;
|
|---|
| 576 | QString entityName;
|
|---|
| 577 | bool cdata;
|
|---|
| 578 | bool nsProcessing;
|
|---|
| 579 | };
|
|---|
| 580 |
|
|---|
| 581 | /**************************************************************
|
|---|
| 582 | *
|
|---|
| 583 | * QDomImplementationPrivate
|
|---|
| 584 | *
|
|---|
| 585 | **************************************************************/
|
|---|
| 586 |
|
|---|
| 587 | QDomImplementationPrivate::QDomImplementationPrivate()
|
|---|
| 588 | {
|
|---|
| 589 | }
|
|---|
| 590 |
|
|---|
| 591 | QDomImplementationPrivate::~QDomImplementationPrivate()
|
|---|
| 592 | {
|
|---|
| 593 | }
|
|---|
| 594 |
|
|---|
| 595 | QDomImplementationPrivate* QDomImplementationPrivate::clone()
|
|---|
| 596 | {
|
|---|
| 597 | QDomImplementationPrivate* p = new QDomImplementationPrivate;
|
|---|
| 598 | // We are not interested in this node
|
|---|
| 599 | p->deref();
|
|---|
| 600 | return p;
|
|---|
| 601 | }
|
|---|
| 602 |
|
|---|
| 603 | /**************************************************************
|
|---|
| 604 | *
|
|---|
| 605 | * QDomImplementation
|
|---|
| 606 | *
|
|---|
| 607 | **************************************************************/
|
|---|
| 608 |
|
|---|
| 609 | /*!
|
|---|
| 610 | \class QDomImplementation qdom.h
|
|---|
| 611 | \reentrant
|
|---|
| 612 | \brief The QDomImplementation class provides information about the
|
|---|
| 613 | features of the DOM implementation.
|
|---|
| 614 | \if defined(commercial)
|
|---|
| 615 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
|---|
| 616 | \endif
|
|---|
| 617 |
|
|---|
| 618 | \module XML
|
|---|
| 619 | \ingroup xml-tools
|
|---|
| 620 |
|
|---|
| 621 | This class describes the features that are supported by the DOM
|
|---|
| 622 | implementation. Currently the XML subset of DOM Level 1 and DOM
|
|---|
| 623 | Level 2 Core are supported.
|
|---|
| 624 |
|
|---|
| 625 | Normally you will use the function QDomDocument::implementation()
|
|---|
| 626 | to get the implementation object.
|
|---|
| 627 |
|
|---|
| 628 | You can create a new document type with createDocumentType() and a
|
|---|
| 629 | new document with createDocument().
|
|---|
| 630 |
|
|---|
| 631 | For further information about the Document Object Model see \link
|
|---|
| 632 | http://www.w3.org/TR/REC-DOM-Level-1/\endlink and \link
|
|---|
| 633 | http://www.w3.org/TR/DOM-Level-2-Core/\endlink. For a more general
|
|---|
| 634 | introduction of the DOM implementation see the QDomDocument
|
|---|
| 635 | documentation.
|
|---|
| 636 |
|
|---|
| 637 | \sa hasFeature()
|
|---|
| 638 | */
|
|---|
| 639 |
|
|---|
| 640 | /*!
|
|---|
| 641 | Constructs a QDomImplementation object.
|
|---|
| 642 | */
|
|---|
| 643 | QDomImplementation::QDomImplementation()
|
|---|
| 644 | {
|
|---|
| 645 | impl = 0;
|
|---|
| 646 | }
|
|---|
| 647 |
|
|---|
| 648 | /*!
|
|---|
| 649 | Constructs a copy of \a x.
|
|---|
| 650 | */
|
|---|
| 651 | QDomImplementation::QDomImplementation( const QDomImplementation& x )
|
|---|
| 652 | {
|
|---|
| 653 | impl = x.impl;
|
|---|
| 654 | if ( impl )
|
|---|
| 655 | impl->ref();
|
|---|
| 656 | }
|
|---|
| 657 |
|
|---|
| 658 | QDomImplementation::QDomImplementation( QDomImplementationPrivate* p )
|
|---|
| 659 | {
|
|---|
| 660 | // We want to be co-owners, so increase the reference count
|
|---|
| 661 | impl = p;
|
|---|
| 662 | if (impl)
|
|---|
| 663 | impl->ref();
|
|---|
| 664 | }
|
|---|
| 665 |
|
|---|
| 666 | /*!
|
|---|
| 667 | Assigns \a x to this DOM implementation.
|
|---|
| 668 | */
|
|---|
| 669 | QDomImplementation& QDomImplementation::operator= ( const QDomImplementation& x )
|
|---|
| 670 | {
|
|---|
| 671 | if ( x.impl )
|
|---|
| 672 | x.impl->ref(); // avoid x=x
|
|---|
| 673 | if ( impl && impl->deref() )
|
|---|
| 674 | delete impl;
|
|---|
| 675 | impl = x.impl;
|
|---|
| 676 |
|
|---|
| 677 | return *this;
|
|---|
| 678 | }
|
|---|
| 679 |
|
|---|
| 680 | /*!
|
|---|
| 681 | Returns TRUE if \a x and this DOM implementation object were
|
|---|
| 682 | created from the same QDomDocument; otherwise returns FALSE.
|
|---|
| 683 | */
|
|---|
| 684 | bool QDomImplementation::operator==( const QDomImplementation& x ) const
|
|---|
| 685 | {
|
|---|
| 686 | return ( impl == x.impl );
|
|---|
| 687 | }
|
|---|
| 688 |
|
|---|
| 689 | /*!
|
|---|
| 690 | Returns TRUE if \a x and this DOM implementation object were
|
|---|
| 691 | created from different QDomDocuments; otherwise returns FALSE.
|
|---|
| 692 | */
|
|---|
| 693 | bool QDomImplementation::operator!=( const QDomImplementation& x ) const
|
|---|
| 694 | {
|
|---|
| 695 | return ( impl != x.impl );
|
|---|
| 696 | }
|
|---|
| 697 |
|
|---|
| 698 | /*!
|
|---|
| 699 | Destroys the object and frees its resources.
|
|---|
| 700 | */
|
|---|
| 701 | QDomImplementation::~QDomImplementation()
|
|---|
| 702 | {
|
|---|
| 703 | if ( impl && impl->deref() )
|
|---|
| 704 | delete impl;
|
|---|
| 705 | }
|
|---|
| 706 |
|
|---|
| 707 | /*!
|
|---|
| 708 | The function returns TRUE if QDom implements the requested \a
|
|---|
| 709 | version of a \a feature; otherwise returns FALSE.
|
|---|
| 710 |
|
|---|
| 711 | The currently supported features and their versions:
|
|---|
| 712 | \table
|
|---|
| 713 | \header \i Feature \i Version
|
|---|
| 714 | \row \i XML \i 1.0
|
|---|
| 715 | \endtable
|
|---|
| 716 | */
|
|---|
| 717 | bool QDomImplementation::hasFeature( const QString& feature, const QString& version )
|
|---|
| 718 | {
|
|---|
| 719 | if ( feature == "XML" ) {
|
|---|
| 720 | if ( version.isEmpty() || version == "1.0" ) {
|
|---|
| 721 | return TRUE;
|
|---|
| 722 | }
|
|---|
| 723 | }
|
|---|
| 724 | // ### add DOM level 2 features
|
|---|
| 725 | return FALSE;
|
|---|
| 726 | }
|
|---|
| 727 |
|
|---|
| 728 | /*!
|
|---|
| 729 | Creates a document type node for the name \a qName.
|
|---|
| 730 |
|
|---|
| 731 | \a publicId specifies the public identifier of the external
|
|---|
| 732 | subset. If you specify QString::null as the \a publicId, this
|
|---|
| 733 | means that the document type has no public identifier.
|
|---|
| 734 |
|
|---|
| 735 | \a systemId specifies the system identifier of the external
|
|---|
| 736 | subset. If you specify QString::null as the \a systemId, this
|
|---|
| 737 | means that the document type has no system identifier.
|
|---|
| 738 |
|
|---|
| 739 | Since you cannot have a public identifier without a system
|
|---|
| 740 | identifier, the public identifier is set to QString::null if there
|
|---|
| 741 | is no system identifier.
|
|---|
| 742 |
|
|---|
| 743 | DOM level 2 does not support any other document type declaration
|
|---|
| 744 | features.
|
|---|
| 745 |
|
|---|
| 746 | The only way you can use a document type that was created this
|
|---|
| 747 | way, is in combination with the createDocument() function to
|
|---|
| 748 | create a QDomDocument with this document type.
|
|---|
| 749 |
|
|---|
| 750 | \sa createDocument();
|
|---|
| 751 | */
|
|---|
| 752 | QDomDocumentType QDomImplementation::createDocumentType( const QString& qName, const QString& publicId, const QString& systemId )
|
|---|
| 753 | {
|
|---|
| 754 | QDomDocumentTypePrivate *dt = new QDomDocumentTypePrivate( 0 );
|
|---|
| 755 | dt->name = qName;
|
|---|
| 756 | if ( systemId.isNull() ) {
|
|---|
| 757 | dt->publicId = QString::null;
|
|---|
| 758 | dt->systemId = QString::null;
|
|---|
| 759 | } else {
|
|---|
| 760 | dt->publicId = publicId;
|
|---|
| 761 | dt->systemId = systemId;
|
|---|
| 762 | }
|
|---|
| 763 | return QDomDocumentType( dt );
|
|---|
| 764 | }
|
|---|
| 765 |
|
|---|
| 766 | /*!
|
|---|
| 767 | Creates a DOM document with the document type \a doctype. This
|
|---|
| 768 | function also adds a root element node with the qualified name \a
|
|---|
| 769 | qName and the namespace URI \a nsURI.
|
|---|
| 770 | */
|
|---|
| 771 | QDomDocument QDomImplementation::createDocument( const QString& nsURI, const QString& qName, const QDomDocumentType& doctype )
|
|---|
| 772 | {
|
|---|
| 773 | QDomDocument doc( doctype );
|
|---|
| 774 | QDomElement root = doc.createElementNS( nsURI, qName );
|
|---|
| 775 | doc.appendChild( root );
|
|---|
| 776 | return doc;
|
|---|
| 777 | }
|
|---|
| 778 |
|
|---|
| 779 | /*!
|
|---|
| 780 | Returns FALSE if the object was created by
|
|---|
| 781 | QDomDocument::implementation(); otherwise returns TRUE.
|
|---|
| 782 | */
|
|---|
| 783 | bool QDomImplementation::isNull()
|
|---|
| 784 | {
|
|---|
| 785 | return ( impl == 0 );
|
|---|
| 786 | }
|
|---|
| 787 |
|
|---|
| 788 | /**************************************************************
|
|---|
| 789 | *
|
|---|
| 790 | * QDomNodeListPrivate
|
|---|
| 791 | *
|
|---|
| 792 | **************************************************************/
|
|---|
| 793 |
|
|---|
| 794 | QDomNodeListPrivate::QDomNodeListPrivate( QDomNodePrivate* n_impl )
|
|---|
| 795 | {
|
|---|
| 796 | node_impl = n_impl;
|
|---|
| 797 | if ( node_impl )
|
|---|
| 798 | node_impl->ref();
|
|---|
| 799 | timestamp = -1;
|
|---|
| 800 | }
|
|---|
| 801 |
|
|---|
| 802 | QDomNodeListPrivate::QDomNodeListPrivate( QDomNodePrivate* n_impl, const QString& name )
|
|---|
| 803 | {
|
|---|
| 804 | node_impl = n_impl;
|
|---|
| 805 | if ( node_impl )
|
|---|
| 806 | node_impl->ref();
|
|---|
| 807 | tagname = name;
|
|---|
| 808 | timestamp = -1;
|
|---|
| 809 | }
|
|---|
| 810 |
|
|---|
| 811 | QDomNodeListPrivate::QDomNodeListPrivate( QDomNodePrivate* n_impl, const QString& _nsURI, const QString& localName )
|
|---|
| 812 | {
|
|---|
| 813 | node_impl = n_impl;
|
|---|
| 814 | if ( node_impl )
|
|---|
| 815 | node_impl->ref();
|
|---|
| 816 | tagname = localName;
|
|---|
| 817 | nsURI = _nsURI;
|
|---|
| 818 | timestamp = -1;
|
|---|
| 819 | }
|
|---|
| 820 |
|
|---|
| 821 | QDomNodeListPrivate::~QDomNodeListPrivate()
|
|---|
| 822 | {
|
|---|
| 823 | if ( node_impl && node_impl->deref() )
|
|---|
| 824 | delete node_impl;
|
|---|
| 825 | }
|
|---|
| 826 |
|
|---|
| 827 | bool QDomNodeListPrivate::operator== ( const QDomNodeListPrivate& other ) const
|
|---|
| 828 | {
|
|---|
| 829 | return ( node_impl == other.node_impl ) && ( tagname == other.tagname ) ;
|
|---|
| 830 | }
|
|---|
| 831 |
|
|---|
| 832 | bool QDomNodeListPrivate::operator!= ( const QDomNodeListPrivate& other ) const
|
|---|
| 833 | {
|
|---|
| 834 | return ( node_impl != other.node_impl ) || ( tagname != other.tagname ) ;
|
|---|
| 835 | }
|
|---|
| 836 |
|
|---|
| 837 | void QDomNodeListPrivate::createList()
|
|---|
| 838 | {
|
|---|
| 839 | if ( !node_impl )
|
|---|
| 840 | return;
|
|---|
| 841 | timestamp = qt_nodeListTime;
|
|---|
| 842 | QDomNodePrivate* p = node_impl->first;
|
|---|
| 843 |
|
|---|
| 844 | list.clear();
|
|---|
| 845 | if ( tagname.isNull() ) {
|
|---|
| 846 | while ( p ) {
|
|---|
| 847 | list.append( p );
|
|---|
| 848 | p = p->next;
|
|---|
| 849 | }
|
|---|
| 850 | } else if ( nsURI.isNull() ) {
|
|---|
| 851 | while ( p && p != node_impl ) {
|
|---|
| 852 | if ( p->isElement() && p->nodeName() == tagname ) {
|
|---|
| 853 | list.append( p );
|
|---|
| 854 | }
|
|---|
| 855 | if ( p->first )
|
|---|
| 856 | p = p->first;
|
|---|
| 857 | else if ( p->next )
|
|---|
| 858 | p = p->next;
|
|---|
| 859 | else {
|
|---|
| 860 | p = p->parent();
|
|---|
| 861 | while ( p && p != node_impl && !p->next )
|
|---|
| 862 | p = p->parent();
|
|---|
| 863 | if ( p && p != node_impl )
|
|---|
| 864 | p = p->next;
|
|---|
| 865 | }
|
|---|
| 866 | }
|
|---|
| 867 | } else {
|
|---|
| 868 | while ( p && p != node_impl ) {
|
|---|
| 869 | if ( p->isElement() && p->name==tagname && p->namespaceURI==nsURI ) {
|
|---|
| 870 | list.append( p );
|
|---|
| 871 | }
|
|---|
| 872 | if ( p->first )
|
|---|
| 873 | p = p->first;
|
|---|
| 874 | else if ( p->next )
|
|---|
| 875 | p = p->next;
|
|---|
| 876 | else {
|
|---|
| 877 | p = p->parent();
|
|---|
| 878 | while ( p && p != node_impl && !p->next )
|
|---|
| 879 | p = p->parent();
|
|---|
| 880 | if ( p && p != node_impl )
|
|---|
| 881 | p = p->next;
|
|---|
| 882 | }
|
|---|
| 883 | }
|
|---|
| 884 | }
|
|---|
| 885 | }
|
|---|
| 886 |
|
|---|
| 887 | QDomNodePrivate* QDomNodeListPrivate::item( int index )
|
|---|
| 888 | {
|
|---|
| 889 | if ( !node_impl )
|
|---|
| 890 | return 0;
|
|---|
| 891 | if ( timestamp < qt_nodeListTime )
|
|---|
| 892 | createList();
|
|---|
| 893 | return list.at( index );
|
|---|
| 894 | }
|
|---|
| 895 |
|
|---|
| 896 | uint QDomNodeListPrivate::length() const
|
|---|
| 897 | {
|
|---|
| 898 | if ( !node_impl )
|
|---|
| 899 | return 0;
|
|---|
| 900 | if ( timestamp < qt_nodeListTime ) {
|
|---|
| 901 | QDomNodeListPrivate *that = (QDomNodeListPrivate*)this;
|
|---|
| 902 | that->createList();
|
|---|
| 903 | }
|
|---|
| 904 | return list.count();
|
|---|
| 905 | }
|
|---|
| 906 |
|
|---|
| 907 | /**************************************************************
|
|---|
| 908 | *
|
|---|
| 909 | * QDomNodeList
|
|---|
| 910 | *
|
|---|
| 911 | **************************************************************/
|
|---|
| 912 |
|
|---|
| 913 | /*!
|
|---|
| 914 | \class QDomNodeList qdom.h
|
|---|
| 915 | \reentrant
|
|---|
| 916 | \brief The QDomNodeList class is a list of QDomNode objects.
|
|---|
| 917 | \if defined(commercial)
|
|---|
| 918 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
|---|
| 919 | \endif
|
|---|
| 920 |
|
|---|
| 921 | \module XML
|
|---|
| 922 | \ingroup xml-tools
|
|---|
| 923 |
|
|---|
| 924 | Lists can be obtained by QDomDocument::elementsByTagName() and
|
|---|
| 925 | QDomNode::childNodes(). The Document Object Model (DOM) requires
|
|---|
| 926 | these lists to be "live": whenever you change the underlying
|
|---|
| 927 | document, the contents of the list will get updated.
|
|---|
| 928 |
|
|---|
| 929 | You can get a particular node from the list with item(). The
|
|---|
| 930 | number of items in the list is returned by count() (and by
|
|---|
| 931 | length()).
|
|---|
| 932 |
|
|---|
| 933 | For further information about the Document Object Model see \link
|
|---|
| 934 | http://www.w3.org/TR/REC-DOM-Level-1/\endlink and \link
|
|---|
| 935 | http://www.w3.org/TR/DOM-Level-2-Core/\endlink. For a more general
|
|---|
| 936 | introduction of the DOM implementation see the QDomDocument
|
|---|
| 937 | documentation.
|
|---|
| 938 |
|
|---|
| 939 | \sa QDomNode::childNodes() QDomDocument::elementsByTagName()
|
|---|
| 940 | */
|
|---|
| 941 |
|
|---|
| 942 | /*!
|
|---|
| 943 | Creates an empty node list.
|
|---|
| 944 | */
|
|---|
| 945 | QDomNodeList::QDomNodeList()
|
|---|
| 946 | {
|
|---|
| 947 | impl = 0;
|
|---|
| 948 | }
|
|---|
| 949 |
|
|---|
| 950 | QDomNodeList::QDomNodeList( QDomNodeListPrivate* p )
|
|---|
| 951 | {
|
|---|
| 952 | impl = p;
|
|---|
| 953 | }
|
|---|
| 954 |
|
|---|
| 955 | /*!
|
|---|
| 956 | Constructs a copy of \a n.
|
|---|
| 957 | */
|
|---|
| 958 | QDomNodeList::QDomNodeList( const QDomNodeList& n )
|
|---|
| 959 | {
|
|---|
| 960 | impl = n.impl;
|
|---|
| 961 | if ( impl )
|
|---|
| 962 | impl->ref();
|
|---|
| 963 | }
|
|---|
| 964 |
|
|---|
| 965 | /*!
|
|---|
| 966 | Assigns \a n to this node list.
|
|---|
| 967 | */
|
|---|
| 968 | QDomNodeList& QDomNodeList::operator= ( const QDomNodeList& n )
|
|---|
| 969 | {
|
|---|
| 970 | if ( n.impl )
|
|---|
| 971 | n.impl->ref();
|
|---|
| 972 | if ( impl && impl->deref() )
|
|---|
| 973 | delete impl;
|
|---|
| 974 | impl = n.impl;
|
|---|
| 975 |
|
|---|
| 976 | return *this;
|
|---|
| 977 | }
|
|---|
| 978 |
|
|---|
| 979 | /*!
|
|---|
| 980 | Returns TRUE if the node list \a n and this node list are equal;
|
|---|
| 981 | otherwise returns FALSE.
|
|---|
| 982 | */
|
|---|
| 983 | bool QDomNodeList::operator== ( const QDomNodeList& n ) const
|
|---|
| 984 | {
|
|---|
| 985 | if ( impl == n.impl )
|
|---|
| 986 | return TRUE;
|
|---|
| 987 | if ( !impl || !n.impl )
|
|---|
| 988 | return FALSE;
|
|---|
| 989 | return (*impl == *n.impl);
|
|---|
| 990 | }
|
|---|
| 991 |
|
|---|
| 992 | /*!
|
|---|
| 993 | Returns TRUE the node list \a n and this node list are not equal;
|
|---|
| 994 | otherwise returns FALSE.
|
|---|
| 995 | */
|
|---|
| 996 | bool QDomNodeList::operator!= ( const QDomNodeList& n ) const
|
|---|
| 997 | {
|
|---|
| 998 | return !operator==(n);
|
|---|
| 999 | }
|
|---|
| 1000 |
|
|---|
| 1001 | /*!
|
|---|
| 1002 | Destroys the object and frees its resources.
|
|---|
| 1003 | */
|
|---|
| 1004 | QDomNodeList::~QDomNodeList()
|
|---|
| 1005 | {
|
|---|
| 1006 | if ( impl && impl->deref() )
|
|---|
| 1007 | delete impl;
|
|---|
| 1008 | }
|
|---|
| 1009 |
|
|---|
| 1010 | /*!
|
|---|
| 1011 | Returns the node at position \a index.
|
|---|
| 1012 |
|
|---|
| 1013 | If \a index is negative or if \a index >= length() then a null
|
|---|
| 1014 | node is returned (i.e. a node for which QDomNode::isNull() returns
|
|---|
| 1015 | TRUE).
|
|---|
| 1016 |
|
|---|
| 1017 | \sa count()
|
|---|
| 1018 | */
|
|---|
| 1019 | QDomNode QDomNodeList::item( int index ) const
|
|---|
| 1020 | {
|
|---|
| 1021 | if ( !impl )
|
|---|
| 1022 | return QDomNode();
|
|---|
| 1023 |
|
|---|
| 1024 | return QDomNode( impl->item( index ) );
|
|---|
| 1025 | }
|
|---|
| 1026 |
|
|---|
| 1027 | /*!
|
|---|
| 1028 | Returns the number of nodes in the list.
|
|---|
| 1029 |
|
|---|
| 1030 | This function is the same as count().
|
|---|
| 1031 | */
|
|---|
| 1032 | uint QDomNodeList::length() const
|
|---|
| 1033 | {
|
|---|
| 1034 | if ( !impl )
|
|---|
| 1035 | return 0;
|
|---|
| 1036 | return impl->length();
|
|---|
| 1037 | }
|
|---|
| 1038 |
|
|---|
| 1039 | /*!
|
|---|
| 1040 | \fn uint QDomNodeList::count() const
|
|---|
| 1041 |
|
|---|
| 1042 | Returns the number of nodes in the list.
|
|---|
| 1043 |
|
|---|
| 1044 | This function is the same as length().
|
|---|
| 1045 | */
|
|---|
| 1046 |
|
|---|
| 1047 |
|
|---|
| 1048 | /**************************************************************
|
|---|
| 1049 | *
|
|---|
| 1050 | * QDomNodePrivate
|
|---|
| 1051 | *
|
|---|
| 1052 | **************************************************************/
|
|---|
| 1053 |
|
|---|
| 1054 | inline void QDomNodePrivate::setOwnerDocument( QDomDocumentPrivate* doc )
|
|---|
| 1055 | {
|
|---|
| 1056 | ownerNode = doc;
|
|---|
| 1057 | hasParent = FALSE;
|
|---|
| 1058 | }
|
|---|
| 1059 |
|
|---|
| 1060 | QDomNodePrivate::QDomNodePrivate( QDomDocumentPrivate* doc, QDomNodePrivate *par )
|
|---|
| 1061 | {
|
|---|
| 1062 | if ( par )
|
|---|
| 1063 | setParent( par );
|
|---|
| 1064 | else
|
|---|
| 1065 | setOwnerDocument( doc );
|
|---|
| 1066 | prev = 0;
|
|---|
| 1067 | next = 0;
|
|---|
| 1068 | first = 0;
|
|---|
| 1069 | last = 0;
|
|---|
| 1070 | createdWithDom1Interface = TRUE;
|
|---|
| 1071 | }
|
|---|
| 1072 |
|
|---|
| 1073 | QDomNodePrivate::QDomNodePrivate( QDomNodePrivate* n, bool deep )
|
|---|
| 1074 | {
|
|---|
| 1075 | setOwnerDocument( n->ownerDocument() );
|
|---|
| 1076 | prev = 0;
|
|---|
| 1077 | next = 0;
|
|---|
| 1078 | first = 0;
|
|---|
| 1079 | last = 0;
|
|---|
| 1080 |
|
|---|
| 1081 | name = n->name;
|
|---|
| 1082 | value = n->value;
|
|---|
| 1083 | prefix = n->prefix;
|
|---|
| 1084 | namespaceURI = n->namespaceURI;
|
|---|
| 1085 | createdWithDom1Interface = n->createdWithDom1Interface;
|
|---|
| 1086 |
|
|---|
| 1087 | if ( !deep )
|
|---|
| 1088 | return;
|
|---|
| 1089 |
|
|---|
| 1090 | for ( QDomNodePrivate* x = n->first; x; x = x->next )
|
|---|
| 1091 | appendChild( x->cloneNode( TRUE ) );
|
|---|
| 1092 | }
|
|---|
| 1093 |
|
|---|
| 1094 | QDomNodePrivate::~QDomNodePrivate()
|
|---|
| 1095 | {
|
|---|
| 1096 | QDomNodePrivate* p = first;
|
|---|
| 1097 | QDomNodePrivate* n;
|
|---|
| 1098 |
|
|---|
| 1099 | while ( p ) {
|
|---|
| 1100 | n = p->next;
|
|---|
| 1101 | if ( p->deref() )
|
|---|
| 1102 | delete p;
|
|---|
| 1103 | else
|
|---|
| 1104 | p->setNoParent();
|
|---|
| 1105 | p = n;
|
|---|
| 1106 | }
|
|---|
| 1107 |
|
|---|
| 1108 | first = 0;
|
|---|
| 1109 | last = 0;
|
|---|
| 1110 | }
|
|---|
| 1111 |
|
|---|
| 1112 | void QDomNodePrivate::clear()
|
|---|
| 1113 | {
|
|---|
| 1114 | QDomNodePrivate* p = first;
|
|---|
| 1115 | QDomNodePrivate* n;
|
|---|
| 1116 |
|
|---|
| 1117 | while ( p ) {
|
|---|
| 1118 | n = p->next;
|
|---|
| 1119 | if ( p->deref() )
|
|---|
| 1120 | delete p;
|
|---|
| 1121 | p = n;
|
|---|
| 1122 | }
|
|---|
| 1123 |
|
|---|
| 1124 | first = 0;
|
|---|
| 1125 | last = 0;
|
|---|
| 1126 | }
|
|---|
| 1127 |
|
|---|
| 1128 | QDomNodePrivate* QDomNodePrivate::namedItem( const QString& n )
|
|---|
| 1129 | {
|
|---|
| 1130 | QDomNodePrivate* p = first;
|
|---|
| 1131 | while ( p ) {
|
|---|
| 1132 | if ( p->nodeName() == n )
|
|---|
| 1133 | return p;
|
|---|
| 1134 | p = p->next;
|
|---|
| 1135 | }
|
|---|
| 1136 |
|
|---|
| 1137 | return 0;
|
|---|
| 1138 | }
|
|---|
| 1139 |
|
|---|
| 1140 | QDomNamedNodeMapPrivate* QDomNodePrivate::attributes()
|
|---|
| 1141 | {
|
|---|
| 1142 | return 0;
|
|---|
| 1143 | }
|
|---|
| 1144 |
|
|---|
| 1145 | QDomNodePrivate* QDomNodePrivate::insertBefore( QDomNodePrivate* newChild, QDomNodePrivate* refChild )
|
|---|
| 1146 | {
|
|---|
| 1147 | // Error check
|
|---|
| 1148 | if ( !newChild )
|
|---|
| 1149 | return 0;
|
|---|
| 1150 |
|
|---|
| 1151 | // Error check
|
|---|
| 1152 | if ( newChild == refChild )
|
|---|
| 1153 | return 0;
|
|---|
| 1154 |
|
|---|
| 1155 | // Error check
|
|---|
| 1156 | if ( refChild && refChild->parent() != this )
|
|---|
| 1157 | return 0;
|
|---|
| 1158 |
|
|---|
| 1159 | // "mark lists as dirty"
|
|---|
| 1160 | qt_nodeListTime++;
|
|---|
| 1161 |
|
|---|
| 1162 | // Special handling for inserting a fragment. We just insert
|
|---|
| 1163 | // all elements of the fragment instead of the fragment itself.
|
|---|
| 1164 | if ( newChild->isDocumentFragment() ) {
|
|---|
| 1165 | // Fragment is empty ?
|
|---|
| 1166 | if ( newChild->first == 0 )
|
|---|
| 1167 | return newChild;
|
|---|
| 1168 |
|
|---|
| 1169 | // New parent
|
|---|
| 1170 | QDomNodePrivate* n = newChild->first;
|
|---|
| 1171 | while ( n ) {
|
|---|
| 1172 | n->setParent( this );
|
|---|
| 1173 | n = n->next;
|
|---|
| 1174 | }
|
|---|
| 1175 |
|
|---|
| 1176 | // Insert at the beginning ?
|
|---|
| 1177 | if ( !refChild || refChild->prev == 0 ) {
|
|---|
| 1178 | if ( first )
|
|---|
| 1179 | first->prev = newChild->last;
|
|---|
| 1180 | newChild->last->next = first;
|
|---|
| 1181 | if ( !last )
|
|---|
| 1182 | last = newChild->last;
|
|---|
| 1183 | first = newChild->first;
|
|---|
| 1184 | } else {
|
|---|
| 1185 | // Insert in the middle
|
|---|
| 1186 | newChild->last->next = refChild;
|
|---|
| 1187 | newChild->first->prev = refChild->prev;
|
|---|
| 1188 | refChild->prev->next = newChild->first;
|
|---|
| 1189 | refChild->prev = newChild->last;
|
|---|
| 1190 | }
|
|---|
| 1191 |
|
|---|
| 1192 | // No need to increase the reference since QDomDocumentFragment
|
|---|
| 1193 | // does not decrease the reference.
|
|---|
| 1194 |
|
|---|
| 1195 | // Remove the nodes from the fragment
|
|---|
| 1196 | newChild->first = 0;
|
|---|
| 1197 | newChild->last = 0;
|
|---|
| 1198 | return newChild;
|
|---|
| 1199 | }
|
|---|
| 1200 |
|
|---|
| 1201 | // No more errors can occur now, so we take
|
|---|
| 1202 | // ownership of the node.
|
|---|
| 1203 | newChild->ref();
|
|---|
| 1204 |
|
|---|
| 1205 | if ( newChild->parent() )
|
|---|
| 1206 | newChild->parent()->removeChild( newChild );
|
|---|
| 1207 |
|
|---|
| 1208 | newChild->setParent( this );
|
|---|
| 1209 |
|
|---|
| 1210 | if ( !refChild ) {
|
|---|
| 1211 | if ( first )
|
|---|
| 1212 | first->prev = newChild;
|
|---|
| 1213 | newChild->next = first;
|
|---|
| 1214 | if ( !last )
|
|---|
| 1215 | last = newChild;
|
|---|
| 1216 | first = newChild;
|
|---|
| 1217 | return newChild;
|
|---|
| 1218 | }
|
|---|
| 1219 |
|
|---|
| 1220 | if ( refChild->prev == 0 ) {
|
|---|
| 1221 | if ( first )
|
|---|
| 1222 | first->prev = newChild;
|
|---|
| 1223 | newChild->next = first;
|
|---|
| 1224 | if ( !last )
|
|---|
| 1225 | last = newChild;
|
|---|
| 1226 | first = newChild;
|
|---|
| 1227 | return newChild;
|
|---|
| 1228 | }
|
|---|
| 1229 |
|
|---|
| 1230 | newChild->next = refChild;
|
|---|
| 1231 | newChild->prev = refChild->prev;
|
|---|
| 1232 | refChild->prev->next = newChild;
|
|---|
| 1233 | refChild->prev = newChild;
|
|---|
| 1234 |
|
|---|
| 1235 | return newChild;
|
|---|
| 1236 | }
|
|---|
| 1237 |
|
|---|
| 1238 | QDomNodePrivate* QDomNodePrivate::insertAfter( QDomNodePrivate* newChild, QDomNodePrivate* refChild )
|
|---|
| 1239 | {
|
|---|
| 1240 | // Error check
|
|---|
| 1241 | if ( !newChild )
|
|---|
| 1242 | return 0;
|
|---|
| 1243 |
|
|---|
| 1244 | // Error check
|
|---|
| 1245 | if ( newChild == refChild )
|
|---|
| 1246 | return 0;
|
|---|
| 1247 |
|
|---|
| 1248 | // Error check
|
|---|
| 1249 | if ( refChild && refChild->parent() != this )
|
|---|
| 1250 | return 0;
|
|---|
| 1251 |
|
|---|
| 1252 | // "mark lists as dirty"
|
|---|
| 1253 | qt_nodeListTime++;
|
|---|
| 1254 |
|
|---|
| 1255 | // Special handling for inserting a fragment. We just insert
|
|---|
| 1256 | // all elements of the fragment instead of the fragment itself.
|
|---|
| 1257 | if ( newChild->isDocumentFragment() ) {
|
|---|
| 1258 | // Fragment is empty ?
|
|---|
| 1259 | if ( newChild->first == 0 )
|
|---|
| 1260 | return newChild;
|
|---|
| 1261 |
|
|---|
| 1262 | // New parent
|
|---|
| 1263 | QDomNodePrivate* n = newChild->first;
|
|---|
| 1264 | while ( n ) {
|
|---|
| 1265 | n->setParent( this );
|
|---|
| 1266 | n = n->next;
|
|---|
| 1267 | }
|
|---|
| 1268 |
|
|---|
| 1269 | // Insert at the end
|
|---|
| 1270 | if ( !refChild || refChild->next == 0 ) {
|
|---|
| 1271 | if ( last )
|
|---|
| 1272 | last->next = newChild->first;
|
|---|
| 1273 | newChild->first->prev = last;
|
|---|
| 1274 | if ( !first )
|
|---|
| 1275 | first = newChild->first;
|
|---|
| 1276 | last = newChild->last;
|
|---|
| 1277 | } else { // Insert in the middle
|
|---|
| 1278 | newChild->first->prev = refChild;
|
|---|
| 1279 | newChild->last->next = refChild->next;
|
|---|
| 1280 | refChild->next->prev = newChild->last;
|
|---|
| 1281 | refChild->next = newChild->first;
|
|---|
| 1282 | }
|
|---|
| 1283 |
|
|---|
| 1284 | // No need to increase the reference since QDomDocumentFragment
|
|---|
| 1285 | // does not decrease the reference.
|
|---|
| 1286 |
|
|---|
| 1287 | // Remove the nodes from the fragment
|
|---|
| 1288 | newChild->first = 0;
|
|---|
| 1289 | newChild->last = 0;
|
|---|
| 1290 | return newChild;
|
|---|
| 1291 | }
|
|---|
| 1292 |
|
|---|
| 1293 | // Release new node from its current parent
|
|---|
| 1294 | if ( newChild->parent() )
|
|---|
| 1295 | newChild->parent()->removeChild( newChild );
|
|---|
| 1296 |
|
|---|
| 1297 | // No more errors can occur now, so we take
|
|---|
| 1298 | // ownership of the node
|
|---|
| 1299 | newChild->ref();
|
|---|
| 1300 |
|
|---|
| 1301 | newChild->setParent( this );
|
|---|
| 1302 |
|
|---|
| 1303 | // Insert at the end
|
|---|
| 1304 | if ( !refChild ) {
|
|---|
| 1305 | if ( last )
|
|---|
| 1306 | last->next = newChild;
|
|---|
| 1307 | newChild->prev = last;
|
|---|
| 1308 | if ( !first )
|
|---|
| 1309 | first = newChild;
|
|---|
| 1310 | last = newChild;
|
|---|
| 1311 | return newChild;
|
|---|
| 1312 | }
|
|---|
| 1313 |
|
|---|
| 1314 | if ( refChild->next == 0 ) {
|
|---|
| 1315 | if ( last )
|
|---|
| 1316 | last->next = newChild;
|
|---|
| 1317 | newChild->prev = last;
|
|---|
| 1318 | if ( !first )
|
|---|
| 1319 | first = newChild;
|
|---|
| 1320 | last = newChild;
|
|---|
| 1321 | return newChild;
|
|---|
| 1322 | }
|
|---|
| 1323 |
|
|---|
| 1324 | newChild->prev = refChild;
|
|---|
| 1325 | newChild->next = refChild->next;
|
|---|
| 1326 | refChild->next->prev = newChild;
|
|---|
| 1327 | refChild->next = newChild;
|
|---|
| 1328 |
|
|---|
| 1329 | return newChild;
|
|---|
| 1330 | }
|
|---|
| 1331 |
|
|---|
| 1332 | QDomNodePrivate* QDomNodePrivate::replaceChild( QDomNodePrivate* newChild, QDomNodePrivate* oldChild )
|
|---|
| 1333 | {
|
|---|
| 1334 | if ( oldChild->parent() != this )
|
|---|
| 1335 | return 0;
|
|---|
| 1336 | if ( !newChild || !oldChild )
|
|---|
| 1337 | return 0;
|
|---|
| 1338 | if ( newChild == oldChild )
|
|---|
| 1339 | return 0;
|
|---|
| 1340 |
|
|---|
| 1341 | // mark lists as dirty
|
|---|
| 1342 | qt_nodeListTime++;
|
|---|
| 1343 |
|
|---|
| 1344 | // Special handling for inserting a fragment. We just insert
|
|---|
| 1345 | // all elements of the fragment instead of the fragment itself.
|
|---|
| 1346 | if ( newChild->isDocumentFragment() ) {
|
|---|
| 1347 | // Fragment is empty ?
|
|---|
| 1348 | if ( newChild->first == 0 )
|
|---|
| 1349 | return newChild;
|
|---|
| 1350 |
|
|---|
| 1351 | // New parent
|
|---|
| 1352 | QDomNodePrivate* n = newChild->first;
|
|---|
| 1353 | while ( n ) {
|
|---|
| 1354 | n->setParent( this );
|
|---|
| 1355 | n = n->next;
|
|---|
| 1356 | }
|
|---|
| 1357 |
|
|---|
| 1358 |
|
|---|
| 1359 | if ( oldChild->next )
|
|---|
| 1360 | oldChild->next->prev = newChild->last;
|
|---|
| 1361 | if ( oldChild->prev )
|
|---|
| 1362 | oldChild->prev->next = newChild->first;
|
|---|
| 1363 |
|
|---|
| 1364 | newChild->last->next = oldChild->next;
|
|---|
| 1365 | newChild->first->prev = oldChild->prev;
|
|---|
| 1366 |
|
|---|
| 1367 | if ( first == oldChild )
|
|---|
| 1368 | first = newChild->first;
|
|---|
| 1369 | if ( last == oldChild )
|
|---|
| 1370 | last = newChild->last;
|
|---|
| 1371 |
|
|---|
| 1372 | oldChild->setNoParent();
|
|---|
| 1373 | oldChild->next = 0;
|
|---|
| 1374 | oldChild->prev = 0;
|
|---|
| 1375 |
|
|---|
| 1376 | // No need to increase the reference since QDomDocumentFragment
|
|---|
| 1377 | // does not decrease the reference.
|
|---|
| 1378 |
|
|---|
| 1379 | // Remove the nodes from the fragment
|
|---|
| 1380 | newChild->first = 0;
|
|---|
| 1381 | newChild->last = 0;
|
|---|
| 1382 |
|
|---|
| 1383 | // We are no longer interested in the old node
|
|---|
| 1384 | if ( oldChild ) oldChild->deref();
|
|---|
| 1385 |
|
|---|
| 1386 | return oldChild;
|
|---|
| 1387 | }
|
|---|
| 1388 |
|
|---|
| 1389 | // No more errors can occur now, so we take
|
|---|
| 1390 | // ownership of the node
|
|---|
| 1391 | newChild->ref();
|
|---|
| 1392 |
|
|---|
| 1393 | // Release new node from its current parent
|
|---|
| 1394 | if ( newChild->parent() )
|
|---|
| 1395 | newChild->parent()->removeChild( newChild );
|
|---|
| 1396 |
|
|---|
| 1397 | newChild->setParent( this );
|
|---|
| 1398 |
|
|---|
| 1399 | if ( oldChild->next )
|
|---|
| 1400 | oldChild->next->prev = newChild;
|
|---|
| 1401 | if ( oldChild->prev )
|
|---|
| 1402 | oldChild->prev->next = newChild;
|
|---|
| 1403 |
|
|---|
| 1404 | newChild->next = oldChild->next;
|
|---|
| 1405 | newChild->prev = oldChild->prev;
|
|---|
| 1406 |
|
|---|
| 1407 | if ( first == oldChild )
|
|---|
| 1408 | first = newChild;
|
|---|
| 1409 | if ( last == oldChild )
|
|---|
| 1410 | last = newChild;
|
|---|
| 1411 |
|
|---|
| 1412 | oldChild->setNoParent();
|
|---|
| 1413 | oldChild->next = 0;
|
|---|
| 1414 | oldChild->prev = 0;
|
|---|
| 1415 |
|
|---|
| 1416 | // We are no longer interested in the old node
|
|---|
| 1417 | if ( oldChild ) oldChild->deref();
|
|---|
| 1418 |
|
|---|
| 1419 | return oldChild;
|
|---|
| 1420 | }
|
|---|
| 1421 |
|
|---|
| 1422 | QDomNodePrivate* QDomNodePrivate::removeChild( QDomNodePrivate* oldChild )
|
|---|
| 1423 | {
|
|---|
| 1424 | // Error check
|
|---|
| 1425 | if ( oldChild->parent() != this )
|
|---|
| 1426 | return 0;
|
|---|
| 1427 |
|
|---|
| 1428 | // "mark lists as dirty"
|
|---|
| 1429 | qt_nodeListTime++;
|
|---|
| 1430 |
|
|---|
| 1431 | // Perhaps oldChild was just created with "createElement" or that. In this case
|
|---|
| 1432 | // its parent is QDomDocument but it is not part of the documents child list.
|
|---|
| 1433 | if ( oldChild->next == 0 && oldChild->prev == 0 && first != oldChild )
|
|---|
| 1434 | return 0;
|
|---|
| 1435 |
|
|---|
| 1436 | if ( oldChild->next )
|
|---|
| 1437 | oldChild->next->prev = oldChild->prev;
|
|---|
| 1438 | if ( oldChild->prev )
|
|---|
| 1439 | oldChild->prev->next = oldChild->next;
|
|---|
| 1440 |
|
|---|
| 1441 | if ( last == oldChild )
|
|---|
| 1442 | last = oldChild->prev;
|
|---|
| 1443 | if ( first == oldChild )
|
|---|
| 1444 | first = oldChild->next;
|
|---|
| 1445 |
|
|---|
| 1446 | oldChild->setNoParent();
|
|---|
| 1447 | oldChild->next = 0;
|
|---|
| 1448 | oldChild->prev = 0;
|
|---|
| 1449 |
|
|---|
| 1450 | // We are no longer interested in the old node
|
|---|
| 1451 | if ( oldChild ) oldChild->deref();
|
|---|
| 1452 |
|
|---|
| 1453 | return oldChild;
|
|---|
| 1454 | }
|
|---|
| 1455 |
|
|---|
| 1456 | QDomNodePrivate* QDomNodePrivate::appendChild( QDomNodePrivate* newChild )
|
|---|
| 1457 | {
|
|---|
| 1458 | // No reference manipulation needed. Done in insertAfter.
|
|---|
| 1459 | return insertAfter( newChild, 0 );
|
|---|
| 1460 | }
|
|---|
| 1461 |
|
|---|
| 1462 | QDomDocumentPrivate* QDomNodePrivate::ownerDocument()
|
|---|
| 1463 | {
|
|---|
| 1464 | QDomNodePrivate* p = this;
|
|---|
| 1465 | while ( p && !p->isDocument() ) {
|
|---|
| 1466 | if ( !p->hasParent )
|
|---|
| 1467 | return (QDomDocumentPrivate*)p->ownerNode;
|
|---|
| 1468 | p = p->parent();
|
|---|
| 1469 | }
|
|---|
| 1470 |
|
|---|
| 1471 | return (QDomDocumentPrivate*)p;
|
|---|
| 1472 | }
|
|---|
| 1473 |
|
|---|
| 1474 | QDomNodePrivate* QDomNodePrivate::cloneNode( bool deep )
|
|---|
| 1475 | {
|
|---|
| 1476 | QDomNodePrivate* p = new QDomNodePrivate( this, deep );
|
|---|
| 1477 | // We are not interested in this node
|
|---|
| 1478 | p->deref();
|
|---|
| 1479 | return p;
|
|---|
| 1480 | }
|
|---|
| 1481 |
|
|---|
| 1482 | static void qNormalizeNode( QDomNodePrivate* n )
|
|---|
| 1483 | {
|
|---|
| 1484 | QDomNodePrivate* p = n->first;
|
|---|
| 1485 | QDomTextPrivate* t = 0;
|
|---|
| 1486 |
|
|---|
| 1487 | while ( p ) {
|
|---|
| 1488 | if ( p->isText() ) {
|
|---|
| 1489 | if ( t ) {
|
|---|
| 1490 | QDomNodePrivate* tmp = p->next;
|
|---|
| 1491 | t->appendData( p->nodeValue() );
|
|---|
| 1492 | n->removeChild( p );
|
|---|
| 1493 | p = tmp;
|
|---|
| 1494 | } else {
|
|---|
| 1495 | t = (QDomTextPrivate*)p;
|
|---|
| 1496 | p = p->next;
|
|---|
| 1497 | }
|
|---|
| 1498 | } else {
|
|---|
| 1499 | p = p->next;
|
|---|
| 1500 | t = 0;
|
|---|
| 1501 | }
|
|---|
| 1502 | }
|
|---|
| 1503 | }
|
|---|
| 1504 | void QDomNodePrivate::normalize()
|
|---|
| 1505 | {
|
|---|
| 1506 | // ### This one has moved from QDomElementPrivate to this position. It is
|
|---|
| 1507 | // not tested.
|
|---|
| 1508 | qNormalizeNode( this );
|
|---|
| 1509 | }
|
|---|
| 1510 |
|
|---|
| 1511 | void QDomNodePrivate::save( QTextStream& s, int depth, int indent ) const
|
|---|
| 1512 | {
|
|---|
| 1513 | const QDomNodePrivate* n = first;
|
|---|
| 1514 | while ( n ) {
|
|---|
| 1515 | n->save( s, depth, indent );
|
|---|
| 1516 | n = n->next;
|
|---|
| 1517 | }
|
|---|
| 1518 | }
|
|---|
| 1519 |
|
|---|
| 1520 | /**************************************************************
|
|---|
| 1521 | *
|
|---|
| 1522 | * QDomNode
|
|---|
| 1523 | *
|
|---|
| 1524 | **************************************************************/
|
|---|
| 1525 |
|
|---|
| 1526 | #define IMPL ((QDomNodePrivate*)impl)
|
|---|
| 1527 |
|
|---|
| 1528 | /*!
|
|---|
| 1529 | \class QDomNode qdom.h
|
|---|
| 1530 | \reentrant
|
|---|
| 1531 | \brief The QDomNode class is the base class for all the nodes in a DOM tree.
|
|---|
| 1532 | \if defined(commercial)
|
|---|
| 1533 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
|---|
| 1534 | \endif
|
|---|
| 1535 |
|
|---|
| 1536 | \module XML
|
|---|
| 1537 | \ingroup xml-tools
|
|---|
| 1538 |
|
|---|
| 1539 | Many functions in the DOM return a QDomNode.
|
|---|
| 1540 |
|
|---|
| 1541 | You can find out the type of a node using isAttr(),
|
|---|
| 1542 | isCDATASection(), isDocumentFragment(), isDocument(),
|
|---|
| 1543 | isDocumentType(), isElement(), isEntityReference(), isText(),
|
|---|
| 1544 | isEntity(), isNotation(), isProcessingInstruction(),
|
|---|
| 1545 | isCharacterData() and isComment().
|
|---|
| 1546 |
|
|---|
| 1547 | A QDomNode can be converted into one of its subclasses using
|
|---|
| 1548 | toAttr(), toCDATASection(), toDocumentFragment(), toDocument(),
|
|---|
| 1549 | toDocumentType(), toElement(), toEntityReference(), toText(),
|
|---|
| 1550 | toEntity(), toNotation(), toProcessingInstruction(),
|
|---|
| 1551 | toCharacterData() or toComment(). You can convert a node to a null
|
|---|
| 1552 | node with clear().
|
|---|
| 1553 |
|
|---|
| 1554 | Copies of the QDomNode class share their data using explicit
|
|---|
| 1555 | sharing. This means that modifying one node will change all
|
|---|
| 1556 | copies. This is especially useful in combination with functions
|
|---|
| 1557 | which return a QDomNode, e.g. firstChild(). You can make an
|
|---|
| 1558 | independent (deep) copy of the node with cloneNode().
|
|---|
| 1559 |
|
|---|
| 1560 | Nodes are inserted with insertBefore(), insertAfter() or
|
|---|
| 1561 | appendChild(). You can replace one node with another using
|
|---|
| 1562 | replaceChild() and remove a node with removeChild().
|
|---|
| 1563 |
|
|---|
| 1564 | To traverse nodes use firstChild() to get a node's first child (if
|
|---|
| 1565 | any), and nextSibling() to traverse. QDomNode also provides
|
|---|
| 1566 | lastChild(), previousSibling() and parentNode(). To find the first
|
|---|
| 1567 | child node with a particular node name use namedItem().
|
|---|
| 1568 |
|
|---|
| 1569 | To find out if a node has children use hasChildNodes() and to get
|
|---|
| 1570 | a list of all of a node's children use childNodes().
|
|---|
| 1571 |
|
|---|
| 1572 | The node's name and value (the meaning of which varies depending
|
|---|
| 1573 | on its type) is returned by nodeName() and nodeValue()
|
|---|
| 1574 | respectively. The node's type is returned by nodeType(). The
|
|---|
| 1575 | node's value can be set with setNodeValue().
|
|---|
| 1576 |
|
|---|
| 1577 | The document to which the node belongs is returned by
|
|---|
| 1578 | ownerDocument().
|
|---|
| 1579 |
|
|---|
| 1580 | Adjacent QDomText nodes can be merged into a single node with
|
|---|
| 1581 | normalize().
|
|---|
| 1582 |
|
|---|
| 1583 | \l QDomElement nodes have attributes which can be retrieved with
|
|---|
| 1584 | attributes().
|
|---|
| 1585 |
|
|---|
| 1586 | QDomElement and QDomAttr nodes can have namespaces which can be
|
|---|
| 1587 | retrieved with namespaceURI(). Their local name is retrieved with
|
|---|
| 1588 | localName(), and their prefix with prefix(). The prefix can be set
|
|---|
| 1589 | with setPrefix().
|
|---|
| 1590 |
|
|---|
| 1591 | You can write the XML representation of the node to a text stream
|
|---|
| 1592 | with save().
|
|---|
| 1593 |
|
|---|
| 1594 | The following example looks for the first element in an XML document and
|
|---|
| 1595 | prints the names of all the elements that are its direct children.
|
|---|
| 1596 | \code
|
|---|
| 1597 | QDomDocument d;
|
|---|
| 1598 | d.setContent( someXML );
|
|---|
| 1599 | QDomNode n = d.firstChild();
|
|---|
| 1600 | while ( !n.isNull() ) {
|
|---|
| 1601 | if ( n.isElement() ) {
|
|---|
| 1602 | QDomElement e = n.toElement();
|
|---|
| 1603 | cout << "Element name: " << e.tagName() << endl;
|
|---|
| 1604 | break;
|
|---|
| 1605 | }
|
|---|
| 1606 | n = n.nextSibling();
|
|---|
| 1607 | }
|
|---|
| 1608 | \endcode
|
|---|
| 1609 |
|
|---|
| 1610 | For further information about the Document Object Model see \link
|
|---|
| 1611 | http://www.w3.org/TR/REC-DOM-Level-1/\endlink and \link
|
|---|
| 1612 | http://www.w3.org/TR/DOM-Level-2-Core/\endlink. For a more general
|
|---|
| 1613 | introduction of the DOM implementation see the QDomDocument
|
|---|
| 1614 | documentation.
|
|---|
| 1615 | */
|
|---|
| 1616 |
|
|---|
| 1617 | /*!
|
|---|
| 1618 | Constructs a \link isNull() null\endlink node.
|
|---|
| 1619 | */
|
|---|
| 1620 | QDomNode::QDomNode()
|
|---|
| 1621 | {
|
|---|
| 1622 | impl = 0;
|
|---|
| 1623 | }
|
|---|
| 1624 |
|
|---|
| 1625 | /*!
|
|---|
| 1626 | Constructs a copy of \a n.
|
|---|
| 1627 |
|
|---|
| 1628 | The data of the copy is shared (shallow copy): modifying one node
|
|---|
| 1629 | will also change the other. If you want to make a deep copy, use
|
|---|
| 1630 | cloneNode().
|
|---|
| 1631 | */
|
|---|
| 1632 | QDomNode::QDomNode( const QDomNode& n )
|
|---|
| 1633 | {
|
|---|
| 1634 | impl = n.impl;
|
|---|
| 1635 | if ( impl ) impl->ref();
|
|---|
| 1636 | }
|
|---|
| 1637 |
|
|---|
| 1638 | /*! \internal
|
|---|
| 1639 | Constructs a new node for the data \a n.
|
|---|
| 1640 | */
|
|---|
| 1641 | QDomNode::QDomNode( QDomNodePrivate* n )
|
|---|
| 1642 | {
|
|---|
| 1643 | impl = n;
|
|---|
| 1644 | if ( impl ) impl->ref();
|
|---|
| 1645 | }
|
|---|
| 1646 |
|
|---|
| 1647 | /*!
|
|---|
| 1648 | Assigns a copy of \a n to this DOM node.
|
|---|
| 1649 |
|
|---|
| 1650 | The data of the copy is shared (shallow copy): modifying one node
|
|---|
| 1651 | will also change the other. If you want to make a deep copy, use
|
|---|
| 1652 | cloneNode().
|
|---|
| 1653 | */
|
|---|
| 1654 | QDomNode& QDomNode::operator= ( const QDomNode& n )
|
|---|
| 1655 | {
|
|---|
| 1656 | if ( n.impl ) n.impl->ref();
|
|---|
| 1657 | if ( impl && impl->deref() ) delete impl;
|
|---|
| 1658 | impl = n.impl;
|
|---|
| 1659 |
|
|---|
| 1660 | return *this;
|
|---|
| 1661 | }
|
|---|
| 1662 |
|
|---|
| 1663 | /*!
|
|---|
| 1664 | Returns TRUE if \a n and this DOM node are equal; otherwise
|
|---|
| 1665 | returns FALSE.
|
|---|
| 1666 | */
|
|---|
| 1667 | bool QDomNode::operator== ( const QDomNode& n ) const
|
|---|
| 1668 | {
|
|---|
| 1669 | return ( impl == n.impl );
|
|---|
| 1670 | }
|
|---|
| 1671 |
|
|---|
| 1672 | /*!
|
|---|
| 1673 | Returns TRUE if \a n and this DOM node are not equal; otherwise
|
|---|
| 1674 | returns FALSE.
|
|---|
| 1675 | */
|
|---|
| 1676 | bool QDomNode::operator!= ( const QDomNode& n ) const
|
|---|
| 1677 | {
|
|---|
| 1678 | return ( impl != n.impl );
|
|---|
| 1679 | }
|
|---|
| 1680 |
|
|---|
| 1681 | /*!
|
|---|
| 1682 | Destroys the object and frees its resources.
|
|---|
| 1683 | */
|
|---|
| 1684 | QDomNode::~QDomNode()
|
|---|
| 1685 | {
|
|---|
| 1686 | if ( impl && impl->deref() ) delete impl;
|
|---|
| 1687 | }
|
|---|
| 1688 |
|
|---|
| 1689 | /*!
|
|---|
| 1690 | Returns the name of the node.
|
|---|
| 1691 |
|
|---|
| 1692 | The meaning of the name depends on the subclass:
|
|---|
| 1693 | \table
|
|---|
| 1694 | \header \i Name \i Meaning
|
|---|
| 1695 | \row \i QDomAttr \i The name of the attribute
|
|---|
| 1696 | \row \i QDomCDATASection \i The string "#cdata-section"
|
|---|
| 1697 | \row \i QDomComment \i The string "#comment"
|
|---|
| 1698 | \row \i QDomDocument \i The string "#document"
|
|---|
| 1699 | \row \i QDomDocumentFragment \i The string "#document-fragment"
|
|---|
| 1700 | \row \i QDomDocumentType \i The name of the document type
|
|---|
| 1701 | \row \i QDomElement \i The tag name
|
|---|
| 1702 | \row \i QDomEntity \i The name of the entity
|
|---|
| 1703 | \row \i QDomEntityReference \i The name of the referenced entity
|
|---|
| 1704 | \row \i QDomNotation \i The name of the notation
|
|---|
| 1705 | \row \i QDomProcessingInstruction \i The target of the processing instruction
|
|---|
| 1706 | \row \i QDomText \i The string "#text"
|
|---|
| 1707 | \endtable
|
|---|
| 1708 |
|
|---|
| 1709 | \sa nodeValue()
|
|---|
| 1710 | */
|
|---|
| 1711 | QString QDomNode::nodeName() const
|
|---|
| 1712 | {
|
|---|
| 1713 | if ( !impl )
|
|---|
| 1714 | return QString::null;
|
|---|
| 1715 |
|
|---|
| 1716 | if ( !IMPL->prefix.isEmpty() )
|
|---|
| 1717 | return IMPL->prefix + ":" + IMPL->name;
|
|---|
| 1718 | return IMPL->name;
|
|---|
| 1719 | }
|
|---|
| 1720 |
|
|---|
| 1721 | /*!
|
|---|
| 1722 | Returns the value of the node.
|
|---|
| 1723 |
|
|---|
| 1724 | The meaning of the value depends on the subclass:
|
|---|
| 1725 | \table
|
|---|
| 1726 | \header \i Name \i Meaning
|
|---|
| 1727 | \row \i QDomAttr \i The attribute value
|
|---|
| 1728 | \row \i QDomCDATASection \i The content of the CDATA section
|
|---|
| 1729 | \row \i QDomComment \i The comment
|
|---|
| 1730 | \row \i QDomProcessingInstruction \i The data of the processing intruction
|
|---|
| 1731 | \row \i QDomText \i The text
|
|---|
| 1732 | \endtable
|
|---|
| 1733 |
|
|---|
| 1734 | All the other subclasses do not have a node value and will return
|
|---|
| 1735 | QString::null.
|
|---|
| 1736 |
|
|---|
| 1737 | \sa setNodeValue() nodeName()
|
|---|
| 1738 | */
|
|---|
| 1739 | QString QDomNode::nodeValue() const
|
|---|
| 1740 | {
|
|---|
| 1741 | if ( !impl )
|
|---|
| 1742 | return QString::null;
|
|---|
| 1743 | return IMPL->value;
|
|---|
| 1744 | }
|
|---|
| 1745 |
|
|---|
| 1746 | /*!
|
|---|
| 1747 | Sets the node's value to \a v.
|
|---|
| 1748 |
|
|---|
| 1749 | \sa nodeValue()
|
|---|
| 1750 | */
|
|---|
| 1751 | void QDomNode::setNodeValue( const QString& v )
|
|---|
| 1752 | {
|
|---|
| 1753 | if ( !impl )
|
|---|
| 1754 | return;
|
|---|
| 1755 | IMPL->setNodeValue( v );
|
|---|
| 1756 | }
|
|---|
| 1757 |
|
|---|
| 1758 | /*!
|
|---|
| 1759 | \enum QDomNode::NodeType
|
|---|
| 1760 |
|
|---|
| 1761 | This enum defines the type of the node:
|
|---|
| 1762 | \value ElementNode
|
|---|
| 1763 | \value AttributeNode
|
|---|
| 1764 | \value TextNode
|
|---|
| 1765 | \value CDATASectionNode
|
|---|
| 1766 | \value EntityReferenceNode
|
|---|
| 1767 | \value EntityNode
|
|---|
| 1768 | \value ProcessingInstructionNode
|
|---|
| 1769 | \value CommentNode
|
|---|
| 1770 | \value DocumentNode
|
|---|
| 1771 | \value DocumentTypeNode
|
|---|
| 1772 | \value DocumentFragmentNode
|
|---|
| 1773 | \value NotationNode
|
|---|
| 1774 | \value BaseNode A QDomNode object, i.e. not a QDomNode subclass.
|
|---|
| 1775 | \value CharacterDataNode
|
|---|
| 1776 | */
|
|---|
| 1777 |
|
|---|
| 1778 | /*!
|
|---|
| 1779 | Returns the type of the node.
|
|---|
| 1780 |
|
|---|
| 1781 | \sa toAttr(), toCDATASection(), toDocumentFragment(),
|
|---|
| 1782 | toDocument() toDocumentType(), toElement(), toEntityReference(),
|
|---|
| 1783 | toText(), toEntity() toNotation(), toProcessingInstruction(),
|
|---|
| 1784 | toCharacterData(), toComment()
|
|---|
| 1785 | */
|
|---|
| 1786 | QDomNode::NodeType QDomNode::nodeType() const
|
|---|
| 1787 | {
|
|---|
| 1788 | if ( !impl )
|
|---|
| 1789 | return QDomNode::BaseNode;
|
|---|
| 1790 | return IMPL->nodeType();
|
|---|
| 1791 | }
|
|---|
| 1792 |
|
|---|
| 1793 | /*!
|
|---|
| 1794 | Returns the parent node. If this node has no parent, a null node
|
|---|
| 1795 | is returned (i.e. a node for which isNull() returns TRUE).
|
|---|
| 1796 | */
|
|---|
| 1797 | QDomNode QDomNode::parentNode() const
|
|---|
| 1798 | {
|
|---|
| 1799 | if ( !impl )
|
|---|
| 1800 | return QDomNode();
|
|---|
| 1801 | return QDomNode( IMPL->parent() );
|
|---|
| 1802 | }
|
|---|
| 1803 |
|
|---|
| 1804 | /*!
|
|---|
| 1805 | Returns a list of all direct child nodes.
|
|---|
| 1806 |
|
|---|
| 1807 | Most often you will call this function on a QDomElement object.
|
|---|
| 1808 |
|
|---|
| 1809 | For example, if the XML document looks like this:
|
|---|
| 1810 | \code
|
|---|
| 1811 | <body>
|
|---|
| 1812 | <h1>Heading</h1>
|
|---|
| 1813 | <p>Hello <b>you</b></p>
|
|---|
| 1814 | </body>
|
|---|
| 1815 | \endcode
|
|---|
| 1816 | Then the list of child nodes for the "body"-element will contain
|
|---|
| 1817 | the node created by the <h1> tag and the node created by the
|
|---|
| 1818 | <p> tag.
|
|---|
| 1819 |
|
|---|
| 1820 | The nodes in the list are not copied; so changing the nodes in the
|
|---|
| 1821 | list will also change the children of this node.
|
|---|
| 1822 |
|
|---|
| 1823 | \sa firstChild() lastChild()
|
|---|
| 1824 | */
|
|---|
| 1825 | QDomNodeList QDomNode::childNodes() const
|
|---|
| 1826 | {
|
|---|
| 1827 | if ( !impl )
|
|---|
| 1828 | return QDomNodeList();
|
|---|
| 1829 | return QDomNodeList( new QDomNodeListPrivate( impl ) );
|
|---|
| 1830 | }
|
|---|
| 1831 |
|
|---|
| 1832 | /*!
|
|---|
| 1833 | Returns the first child of the node. If there is no child node, a
|
|---|
| 1834 | \link isNull() null node\endlink is returned. Changing the
|
|---|
| 1835 | returned node will also change the node in the document tree.
|
|---|
| 1836 |
|
|---|
| 1837 | \sa lastChild() childNodes()
|
|---|
| 1838 | */
|
|---|
| 1839 | QDomNode QDomNode::firstChild() const
|
|---|
| 1840 | {
|
|---|
| 1841 | if ( !impl )
|
|---|
| 1842 | return QDomNode();
|
|---|
| 1843 | return QDomNode( IMPL->first );
|
|---|
| 1844 | }
|
|---|
| 1845 |
|
|---|
| 1846 | /*!
|
|---|
| 1847 | Returns the last child of the node. If there is no child node, a
|
|---|
| 1848 | \link isNull() null node\endlink is returned. Changing the
|
|---|
| 1849 | returned node will also change the node in the document tree.
|
|---|
| 1850 |
|
|---|
| 1851 | \sa firstChild() childNodes()
|
|---|
| 1852 | */
|
|---|
| 1853 | QDomNode QDomNode::lastChild() const
|
|---|
| 1854 | {
|
|---|
| 1855 | if ( !impl )
|
|---|
| 1856 | return QDomNode();
|
|---|
| 1857 | return QDomNode( IMPL->last );
|
|---|
| 1858 | }
|
|---|
| 1859 |
|
|---|
| 1860 | /*!
|
|---|
| 1861 | Returns the previous sibling in the document tree. Changing the
|
|---|
| 1862 | returned node will also change the node in the document tree.
|
|---|
| 1863 |
|
|---|
| 1864 | For example, if you have XML like this:
|
|---|
| 1865 | \code
|
|---|
| 1866 | <h1>Heading</h1>
|
|---|
| 1867 | <p>The text...</p>
|
|---|
| 1868 | <h2>Next heading</h2>
|
|---|
| 1869 | \endcode
|
|---|
| 1870 | and this QDomNode represents the <p> tag, previousSibling()
|
|---|
| 1871 | will return the node representing the <h1> tag.
|
|---|
| 1872 |
|
|---|
| 1873 | \sa nextSibling()
|
|---|
| 1874 | */
|
|---|
| 1875 | QDomNode QDomNode::previousSibling() const
|
|---|
| 1876 | {
|
|---|
| 1877 | if ( !impl )
|
|---|
| 1878 | return QDomNode();
|
|---|
| 1879 | return QDomNode( IMPL->prev );
|
|---|
| 1880 | }
|
|---|
| 1881 |
|
|---|
| 1882 | /*!
|
|---|
| 1883 | Returns the next sibling in the document tree. Changing the
|
|---|
| 1884 | returned node will also change the node in the document tree.
|
|---|
| 1885 |
|
|---|
| 1886 | If you have XML like this:
|
|---|
| 1887 | \code
|
|---|
| 1888 | <h1>Heading</h1>
|
|---|
| 1889 | <p>The text...</p>
|
|---|
| 1890 | <h2>Next heading</h2>
|
|---|
| 1891 | \endcode
|
|---|
| 1892 | and this QDomNode represents the <p> tag, nextSibling() will
|
|---|
| 1893 | return the node representing the <h2> tag.
|
|---|
| 1894 |
|
|---|
| 1895 | \sa previousSibling()
|
|---|
| 1896 | */
|
|---|
| 1897 | QDomNode QDomNode::nextSibling() const
|
|---|
| 1898 | {
|
|---|
| 1899 | if ( !impl )
|
|---|
| 1900 | return QDomNode();
|
|---|
| 1901 | return QDomNode( IMPL->next );
|
|---|
| 1902 | }
|
|---|
| 1903 |
|
|---|
| 1904 | /*!
|
|---|
| 1905 | Returns a named node map of all attributes. Attributes are only
|
|---|
| 1906 | provided for \l{QDomElement}s.
|
|---|
| 1907 |
|
|---|
| 1908 | Changing the attributes in the map will also change the attributes
|
|---|
| 1909 | of this QDomNode.
|
|---|
| 1910 | */
|
|---|
| 1911 | QDomNamedNodeMap QDomNode::attributes() const
|
|---|
| 1912 | {
|
|---|
| 1913 | if ( !impl )
|
|---|
| 1914 | return QDomNamedNodeMap();
|
|---|
| 1915 |
|
|---|
| 1916 | return QDomNamedNodeMap( impl->attributes() );
|
|---|
| 1917 | }
|
|---|
| 1918 |
|
|---|
| 1919 | /*!
|
|---|
| 1920 | Returns the document to which this node belongs.
|
|---|
| 1921 | */
|
|---|
| 1922 | QDomDocument QDomNode::ownerDocument() const
|
|---|
| 1923 | {
|
|---|
| 1924 | if ( !impl )
|
|---|
| 1925 | return QDomDocument();
|
|---|
| 1926 | return QDomDocument( IMPL->ownerDocument() );
|
|---|
| 1927 | }
|
|---|
| 1928 |
|
|---|
| 1929 | /*!
|
|---|
| 1930 | Creates a deep (not shallow) copy of the QDomNode.
|
|---|
| 1931 |
|
|---|
| 1932 | If \a deep is TRUE, then the cloning is done recursively which
|
|---|
| 1933 | means that all the node's children are deep copied too. If \a deep
|
|---|
| 1934 | is FALSE only the node itself is copied and the copy will have no
|
|---|
| 1935 | child nodes.
|
|---|
| 1936 | */
|
|---|
| 1937 | QDomNode QDomNode::cloneNode( bool deep ) const
|
|---|
| 1938 | {
|
|---|
| 1939 | if ( !impl )
|
|---|
| 1940 | return QDomNode();
|
|---|
| 1941 | return QDomNode( IMPL->cloneNode( deep ) );
|
|---|
| 1942 | }
|
|---|
| 1943 |
|
|---|
| 1944 | /*!
|
|---|
| 1945 | Calling normalize() on an element converts all its children into a
|
|---|
| 1946 | standard form. This means that adjacent QDomText objects will be
|
|---|
| 1947 | merged into a single text object (QDomCDATASection nodes are not
|
|---|
| 1948 | merged).
|
|---|
| 1949 | */
|
|---|
| 1950 | void QDomNode::normalize()
|
|---|
| 1951 | {
|
|---|
| 1952 | if ( !impl )
|
|---|
| 1953 | return;
|
|---|
| 1954 | IMPL->normalize();
|
|---|
| 1955 | }
|
|---|
| 1956 |
|
|---|
| 1957 | /*!
|
|---|
| 1958 | Returns TRUE if the DOM implementation implements the feature \a
|
|---|
| 1959 | feature and this feature is supported by this node in the version
|
|---|
| 1960 | \a version; otherwise returns FALSE.
|
|---|
| 1961 |
|
|---|
| 1962 | \sa QDomImplementation::hasFeature()
|
|---|
| 1963 | */
|
|---|
| 1964 | bool QDomNode::isSupported( const QString& feature, const QString& version ) const
|
|---|
| 1965 | {
|
|---|
| 1966 | QDomImplementation i;
|
|---|
| 1967 | return i.hasFeature( feature, version );
|
|---|
| 1968 | }
|
|---|
| 1969 |
|
|---|
| 1970 | /*!
|
|---|
| 1971 | Returns the namespace URI of this node or QString::null if the
|
|---|
| 1972 | node has no namespace URI.
|
|---|
| 1973 |
|
|---|
| 1974 | Only nodes of type \link QDomNode::NodeType ElementNode\endlink or
|
|---|
| 1975 | \link QDomNode::NodeType AttributeNode\endlink can have
|
|---|
| 1976 | namespaces. A namespace URI must be specified at creation time and
|
|---|
| 1977 | cannot be changed later.
|
|---|
| 1978 |
|
|---|
| 1979 | \sa prefix() localName() QDomDocument::createElementNS()
|
|---|
| 1980 | QDomDocument::createAttributeNS()
|
|---|
| 1981 | */
|
|---|
| 1982 | QString QDomNode::namespaceURI() const
|
|---|
| 1983 | {
|
|---|
| 1984 | if ( !impl )
|
|---|
| 1985 | return QString::null;
|
|---|
| 1986 | return IMPL->namespaceURI;
|
|---|
| 1987 | }
|
|---|
| 1988 |
|
|---|
| 1989 | /*!
|
|---|
| 1990 | Returns the namespace prefix of the node or QString::null if the
|
|---|
| 1991 | node has no namespace prefix.
|
|---|
| 1992 |
|
|---|
| 1993 | Only nodes of type \link QDomNode::NodeType ElementNode\endlink or
|
|---|
| 1994 | \link QDomNode::NodeType AttributeNode\endlink can have
|
|---|
| 1995 | namespaces. A namespace prefix must be specified at creation time.
|
|---|
| 1996 | If a node was created with a namespace prefix, you can change it
|
|---|
| 1997 | later with setPrefix().
|
|---|
| 1998 |
|
|---|
| 1999 | If you create an element or attribute with
|
|---|
| 2000 | QDomDocument::createElement() or QDomDocument::createAttribute(),
|
|---|
| 2001 | the prefix will be QString::null. If you use
|
|---|
| 2002 | QDomDocument::createElementNS() or
|
|---|
| 2003 | QDomDocument::createAttributeNS() instead, the prefix will not be
|
|---|
| 2004 | QString::null; but it might be an empty string if the name does
|
|---|
| 2005 | not have a prefix.
|
|---|
| 2006 |
|
|---|
| 2007 | \sa setPrefix() localName() namespaceURI()
|
|---|
| 2008 | QDomDocument::createElementNS() QDomDocument::createAttributeNS()
|
|---|
| 2009 | */
|
|---|
| 2010 | QString QDomNode::prefix() const
|
|---|
| 2011 | {
|
|---|
| 2012 | if ( !impl )
|
|---|
| 2013 | return QString::null;
|
|---|
| 2014 | return IMPL->prefix;
|
|---|
| 2015 | }
|
|---|
| 2016 |
|
|---|
| 2017 | /*!
|
|---|
| 2018 | If the node has a namespace prefix, this function changes the
|
|---|
| 2019 | namespace prefix of the node to \a pre. Otherwise this function
|
|---|
| 2020 | does nothing.
|
|---|
| 2021 |
|
|---|
| 2022 | Only nodes of type \link QDomNode::NodeType ElementNode\endlink or
|
|---|
| 2023 | \link QDomNode::NodeType AttributeNode\endlink can have
|
|---|
| 2024 | namespaces. A namespace prefix must have be specified at creation
|
|---|
| 2025 | time; it is not possible to add a namespace prefix afterwards.
|
|---|
| 2026 |
|
|---|
| 2027 | \sa prefix() localName() namespaceURI()
|
|---|
| 2028 | QDomDocument::createElementNS() QDomDocument::createAttributeNS()
|
|---|
| 2029 | */
|
|---|
| 2030 | void QDomNode::setPrefix( const QString& pre )
|
|---|
| 2031 | {
|
|---|
| 2032 | if ( !impl || IMPL->prefix.isNull() )
|
|---|
| 2033 | return;
|
|---|
| 2034 | if ( isAttr() || isElement() )
|
|---|
| 2035 | IMPL->prefix = pre;
|
|---|
| 2036 | }
|
|---|
| 2037 |
|
|---|
| 2038 | /*!
|
|---|
| 2039 | If the node uses namespaces, this function returns the local name
|
|---|
| 2040 | of the node; otherwise it returns QString::null.
|
|---|
| 2041 |
|
|---|
| 2042 | Only nodes of type \link QDomNode::NodeType ElementNode\endlink or
|
|---|
| 2043 | \link QDomNode::NodeType AttributeNode\endlink can have
|
|---|
| 2044 | namespaces. A namespace must have been specified at creation time;
|
|---|
| 2045 | it is not possible to add a namespace afterwards.
|
|---|
| 2046 |
|
|---|
| 2047 | \sa prefix() namespaceURI() QDomDocument::createElementNS()
|
|---|
| 2048 | QDomDocument::createAttributeNS()
|
|---|
| 2049 | */
|
|---|
| 2050 | QString QDomNode::localName() const
|
|---|
| 2051 | {
|
|---|
| 2052 | if ( !impl || IMPL->createdWithDom1Interface )
|
|---|
| 2053 | return QString::null;
|
|---|
| 2054 | return IMPL->name;
|
|---|
| 2055 | }
|
|---|
| 2056 |
|
|---|
| 2057 | /*!
|
|---|
| 2058 | Returns TRUE if the node has attributes; otherwise returns FALSE.
|
|---|
| 2059 |
|
|---|
| 2060 | \sa attributes()
|
|---|
| 2061 | */
|
|---|
| 2062 | bool QDomNode::hasAttributes() const
|
|---|
| 2063 | {
|
|---|
| 2064 | if ( !impl )
|
|---|
| 2065 | return FALSE;
|
|---|
| 2066 | return IMPL->hasAttributes();
|
|---|
| 2067 | }
|
|---|
| 2068 |
|
|---|
| 2069 | /*!
|
|---|
| 2070 | Inserts the node \a newChild before the child node \a refChild.
|
|---|
| 2071 | \a refChild must be a direct child of this node. If \a refChild is
|
|---|
| 2072 | \link isNull() null\endlink then \a newChild is inserted as the
|
|---|
| 2073 | node's first child.
|
|---|
| 2074 |
|
|---|
| 2075 | If \a newChild is the child of another node, it is reparented to
|
|---|
| 2076 | this node. If \a newChild is a child of this node, then its
|
|---|
| 2077 | position in the list of children is changed.
|
|---|
| 2078 |
|
|---|
| 2079 | If \a newChild is a QDomDocumentFragment, then the children of the
|
|---|
| 2080 | fragment are removed from the fragment and inserted before \a
|
|---|
| 2081 | refChild.
|
|---|
| 2082 |
|
|---|
| 2083 | Returns a new reference to \a newChild on success or a \link
|
|---|
| 2084 | isNull() null node\endlink on failure.
|
|---|
| 2085 |
|
|---|
| 2086 | \sa insertAfter() replaceChild() removeChild() appendChild()
|
|---|
| 2087 | */
|
|---|
| 2088 | QDomNode QDomNode::insertBefore( const QDomNode& newChild, const QDomNode& refChild )
|
|---|
| 2089 | {
|
|---|
| 2090 | if ( !impl )
|
|---|
| 2091 | return QDomNode();
|
|---|
| 2092 | return QDomNode( IMPL->insertBefore( newChild.impl, refChild.impl ) );
|
|---|
| 2093 | }
|
|---|
| 2094 |
|
|---|
| 2095 | /*!
|
|---|
| 2096 | Inserts the node \a newChild after the child node \a refChild. \a
|
|---|
| 2097 | refChild must be a direct child of this node. If \a refChild is
|
|---|
| 2098 | \link isNull() null\endlink then \a newChild is appended as this
|
|---|
| 2099 | node's last child.
|
|---|
| 2100 |
|
|---|
| 2101 | If \a newChild is the child of another node, it is reparented to
|
|---|
| 2102 | this node. If \a newChild is a child of this node, then its
|
|---|
| 2103 | position in the list of children is changed.
|
|---|
| 2104 |
|
|---|
| 2105 | If \a newChild is a QDomDocumentFragment, then the children of the
|
|---|
| 2106 | fragment are removed from the fragment and inserted after \a
|
|---|
| 2107 | refChild.
|
|---|
| 2108 |
|
|---|
| 2109 | Returns a new reference to \a newChild on success or a \link
|
|---|
| 2110 | isNull() null node\endlink on failure.
|
|---|
| 2111 |
|
|---|
| 2112 | \sa insertBefore() replaceChild() removeChild() appendChild()
|
|---|
| 2113 | */
|
|---|
| 2114 | QDomNode QDomNode::insertAfter( const QDomNode& newChild, const QDomNode& refChild )
|
|---|
| 2115 | {
|
|---|
| 2116 | if ( !impl )
|
|---|
| 2117 | return QDomNode();
|
|---|
| 2118 | return QDomNode( IMPL->insertAfter( newChild.impl, refChild.impl ) );
|
|---|
| 2119 | }
|
|---|
| 2120 |
|
|---|
| 2121 | /*!
|
|---|
| 2122 | Replaces \a oldChild with \a newChild. \a oldChild must be a
|
|---|
| 2123 | direct child of this node.
|
|---|
| 2124 |
|
|---|
| 2125 | If \a newChild is the child of another node, it is reparented to
|
|---|
| 2126 | this node. If \a newChild is a child of this node, then its
|
|---|
| 2127 | position in the list of children is changed.
|
|---|
| 2128 |
|
|---|
| 2129 | If \a newChild is a QDomDocumentFragment, then \a oldChild is
|
|---|
| 2130 | replaced by all of the children of the fragment.
|
|---|
| 2131 |
|
|---|
| 2132 | Returns a new reference to \a oldChild on success or a \link
|
|---|
| 2133 | isNull() null node\endlink an failure.
|
|---|
| 2134 |
|
|---|
| 2135 | \sa insertBefore() insertAfter() removeChild() appendChild()
|
|---|
| 2136 | */
|
|---|
| 2137 | QDomNode QDomNode::replaceChild( const QDomNode& newChild, const QDomNode& oldChild )
|
|---|
| 2138 | {
|
|---|
| 2139 | if ( !impl )
|
|---|
| 2140 | return QDomNode();
|
|---|
| 2141 | return QDomNode( IMPL->replaceChild( newChild.impl, oldChild.impl ) );
|
|---|
| 2142 | }
|
|---|
| 2143 |
|
|---|
| 2144 | /*!
|
|---|
| 2145 | Removes \a oldChild from the list of children. \a oldChild must be
|
|---|
| 2146 | a direct child of this node.
|
|---|
| 2147 |
|
|---|
| 2148 | Returns a new reference to \a oldChild on success or a \link
|
|---|
| 2149 | isNull() null node\endlink on failure.
|
|---|
| 2150 |
|
|---|
| 2151 | \sa insertBefore() insertAfter() replaceChild() appendChild()
|
|---|
| 2152 | */
|
|---|
| 2153 | QDomNode QDomNode::removeChild( const QDomNode& oldChild )
|
|---|
| 2154 | {
|
|---|
| 2155 | if ( !impl )
|
|---|
| 2156 | return QDomNode();
|
|---|
| 2157 |
|
|---|
| 2158 | if ( oldChild.isNull() )
|
|---|
| 2159 | return QDomNode();
|
|---|
| 2160 |
|
|---|
| 2161 | return QDomNode( IMPL->removeChild( oldChild.impl ) );
|
|---|
| 2162 | }
|
|---|
| 2163 |
|
|---|
| 2164 | /*!
|
|---|
| 2165 | Appends \a newChild as the node's last child.
|
|---|
| 2166 |
|
|---|
| 2167 | If \a newChild is the child of another node, it is reparented to
|
|---|
| 2168 | this node. If \a newChild is a child of this node, then its
|
|---|
| 2169 | position in the list of children is changed.
|
|---|
| 2170 |
|
|---|
| 2171 | If \a newChild is a QDomDocumentFragment, then the children of the
|
|---|
| 2172 | fragment are removed from the fragment and appended.
|
|---|
| 2173 |
|
|---|
| 2174 | Returns a new reference to \a newChild.
|
|---|
| 2175 |
|
|---|
| 2176 | \sa insertBefore() insertAfter() replaceChild() removeChild()
|
|---|
| 2177 | */
|
|---|
| 2178 | QDomNode QDomNode::appendChild( const QDomNode& newChild )
|
|---|
| 2179 | {
|
|---|
| 2180 | if ( !impl )
|
|---|
| 2181 | return QDomNode();
|
|---|
| 2182 | return QDomNode( IMPL->appendChild( newChild.impl ) );
|
|---|
| 2183 | }
|
|---|
| 2184 |
|
|---|
| 2185 | /*!
|
|---|
| 2186 | Returns TRUE if the node has one or more children; otherwise
|
|---|
| 2187 | returns FALSE.
|
|---|
| 2188 | */
|
|---|
| 2189 | bool QDomNode::hasChildNodes() const
|
|---|
| 2190 | {
|
|---|
| 2191 | if ( !impl )
|
|---|
| 2192 | return FALSE;
|
|---|
| 2193 | return IMPL->first != 0;
|
|---|
| 2194 | }
|
|---|
| 2195 |
|
|---|
| 2196 | /*!
|
|---|
| 2197 | Returns TRUE if this node is null (i.e. if it has no type or
|
|---|
| 2198 | contents); otherwise returns FALSE.
|
|---|
| 2199 | */
|
|---|
| 2200 | bool QDomNode::isNull() const
|
|---|
| 2201 | {
|
|---|
| 2202 | return ( impl == 0 );
|
|---|
| 2203 | }
|
|---|
| 2204 |
|
|---|
| 2205 | /*!
|
|---|
| 2206 | Converts the node into a null node; if it was not a null node
|
|---|
| 2207 | before, its type and contents are deleted.
|
|---|
| 2208 |
|
|---|
| 2209 | \sa isNull()
|
|---|
| 2210 | */
|
|---|
| 2211 | void QDomNode::clear()
|
|---|
| 2212 | {
|
|---|
| 2213 | if ( impl && impl->deref() ) delete impl;
|
|---|
| 2214 | impl = 0;
|
|---|
| 2215 | }
|
|---|
| 2216 |
|
|---|
| 2217 | /*!
|
|---|
| 2218 | Returns the first direct child node for which nodeName() equals \a
|
|---|
| 2219 | name.
|
|---|
| 2220 |
|
|---|
| 2221 | If no such direct child exists, a \link isNull() null node\endlink
|
|---|
| 2222 | is returned.
|
|---|
| 2223 |
|
|---|
| 2224 | \sa nodeName()
|
|---|
| 2225 | */
|
|---|
| 2226 | QDomNode QDomNode::namedItem( const QString& name ) const
|
|---|
| 2227 | {
|
|---|
| 2228 | if ( !impl )
|
|---|
| 2229 | return QDomNode();
|
|---|
| 2230 | return QDomNode( impl->namedItem( name ) );
|
|---|
| 2231 | }
|
|---|
| 2232 |
|
|---|
| 2233 | /*!
|
|---|
| 2234 | Writes the XML representation of the node and all its children to
|
|---|
| 2235 | the stream \a str. This function uses \a indent as the amount of
|
|---|
| 2236 | space to indent the node.
|
|---|
| 2237 | */
|
|---|
| 2238 | void QDomNode::save( QTextStream& str, int indent ) const
|
|---|
| 2239 | {
|
|---|
| 2240 | if ( impl )
|
|---|
| 2241 | IMPL->save( str, 1, indent );
|
|---|
| 2242 | }
|
|---|
| 2243 |
|
|---|
| 2244 | /*!
|
|---|
| 2245 | \relates QDomNode
|
|---|
| 2246 |
|
|---|
| 2247 | Writes the XML representation of the node \a node and all its
|
|---|
| 2248 | children to the stream \a str.
|
|---|
| 2249 | */
|
|---|
| 2250 | QTextStream& operator<<( QTextStream& str, const QDomNode& node )
|
|---|
| 2251 | {
|
|---|
| 2252 | node.save( str, 1 );
|
|---|
| 2253 |
|
|---|
| 2254 | return str;
|
|---|
| 2255 | }
|
|---|
| 2256 |
|
|---|
| 2257 | /*!
|
|---|
| 2258 | Returns TRUE if the node is an attribute; otherwise returns FALSE.
|
|---|
| 2259 |
|
|---|
| 2260 | If this function returns TRUE, it does not imply that this object
|
|---|
| 2261 | is a QDomAttribute; you can get the QDomAttribute with
|
|---|
| 2262 | toAttribute().
|
|---|
| 2263 |
|
|---|
| 2264 | \sa toAttr()
|
|---|
| 2265 | */
|
|---|
| 2266 | bool QDomNode::isAttr() const
|
|---|
| 2267 | {
|
|---|
| 2268 | if(impl)
|
|---|
| 2269 | return impl->isAttr();
|
|---|
| 2270 | return FALSE;
|
|---|
| 2271 | }
|
|---|
| 2272 |
|
|---|
| 2273 | /*!
|
|---|
| 2274 | Returns TRUE if the node is a CDATA section; otherwise returns
|
|---|
| 2275 | FALSE.
|
|---|
| 2276 |
|
|---|
| 2277 | If this function returns TRUE, it does not imply that this object
|
|---|
| 2278 | is a QDomCDATASection; you can get the QDomCDATASection with
|
|---|
| 2279 | toCDATASection().
|
|---|
| 2280 |
|
|---|
| 2281 | \sa toCDATASection()
|
|---|
| 2282 | */
|
|---|
| 2283 | bool QDomNode::isCDATASection() const
|
|---|
| 2284 | {
|
|---|
| 2285 | if(impl)
|
|---|
| 2286 | return impl->isCDATASection();
|
|---|
| 2287 | return FALSE;
|
|---|
| 2288 | }
|
|---|
| 2289 |
|
|---|
| 2290 | /*!
|
|---|
| 2291 | Returns TRUE if the node is a document fragment; otherwise returns
|
|---|
| 2292 | FALSE.
|
|---|
| 2293 |
|
|---|
| 2294 | If this function returns TRUE, it does not imply that this object
|
|---|
| 2295 | is a QDomDocumentFragment; you can get the QDomDocumentFragment
|
|---|
| 2296 | with toDocumentFragment().
|
|---|
| 2297 |
|
|---|
| 2298 | \sa toDocumentFragment()
|
|---|
| 2299 | */
|
|---|
| 2300 | bool QDomNode::isDocumentFragment() const
|
|---|
| 2301 | {
|
|---|
| 2302 | if(impl)
|
|---|
| 2303 | return impl->isDocumentFragment();
|
|---|
| 2304 | return FALSE;
|
|---|
| 2305 | }
|
|---|
| 2306 |
|
|---|
| 2307 | /*!
|
|---|
| 2308 | Returns TRUE if the node is a document; otherwise returns FALSE.
|
|---|
| 2309 |
|
|---|
| 2310 | If this function returns TRUE, it does not imply that this object
|
|---|
| 2311 | is a QDomDocument; you can get the QDomDocument with toDocument().
|
|---|
| 2312 |
|
|---|
| 2313 | \sa toDocument()
|
|---|
| 2314 | */
|
|---|
| 2315 | bool QDomNode::isDocument() const
|
|---|
| 2316 | {
|
|---|
| 2317 | if(impl)
|
|---|
| 2318 | return impl->isDocument();
|
|---|
| 2319 | return FALSE;
|
|---|
| 2320 | }
|
|---|
| 2321 |
|
|---|
| 2322 | /*!
|
|---|
| 2323 | Returns TRUE if the node is a document type; otherwise returns
|
|---|
| 2324 | FALSE.
|
|---|
| 2325 |
|
|---|
| 2326 | If this function returns TRUE, it does not imply that this object
|
|---|
| 2327 | is a QDomDocumentType; you can get the QDomDocumentType with
|
|---|
| 2328 | toDocumentType().
|
|---|
| 2329 |
|
|---|
| 2330 | \sa toDocumentType()
|
|---|
| 2331 | */
|
|---|
| 2332 | bool QDomNode::isDocumentType() const
|
|---|
| 2333 | {
|
|---|
| 2334 | if(impl)
|
|---|
| 2335 | return impl->isDocumentType();
|
|---|
| 2336 | return FALSE;
|
|---|
| 2337 | }
|
|---|
| 2338 |
|
|---|
| 2339 | /*!
|
|---|
| 2340 | Returns TRUE if the node is an element; otherwise returns FALSE.
|
|---|
| 2341 |
|
|---|
| 2342 | If this function returns TRUE, it does not imply that this object
|
|---|
| 2343 | is a QDomElement; you can get the QDomElement with toElement().
|
|---|
| 2344 |
|
|---|
| 2345 | \sa toElement()
|
|---|
| 2346 | */
|
|---|
| 2347 | bool QDomNode::isElement() const
|
|---|
| 2348 | {
|
|---|
| 2349 | if(impl)
|
|---|
| 2350 | return impl->isElement();
|
|---|
| 2351 | return FALSE;
|
|---|
| 2352 | }
|
|---|
| 2353 |
|
|---|
| 2354 | /*!
|
|---|
| 2355 | Returns TRUE if the node is an entity reference; otherwise returns
|
|---|
| 2356 | FALSE.
|
|---|
| 2357 |
|
|---|
| 2358 | If this function returns TRUE, it does not imply that this object
|
|---|
| 2359 | is a QDomEntityReference; you can get the QDomEntityReference with
|
|---|
| 2360 | toEntityReference().
|
|---|
| 2361 |
|
|---|
| 2362 | \sa toEntityReference()
|
|---|
| 2363 | */
|
|---|
| 2364 | bool QDomNode::isEntityReference() const
|
|---|
| 2365 | {
|
|---|
| 2366 | if(impl)
|
|---|
| 2367 | return impl->isEntityReference();
|
|---|
| 2368 | return FALSE;
|
|---|
| 2369 | }
|
|---|
| 2370 |
|
|---|
| 2371 | /*!
|
|---|
| 2372 | Returns TRUE if the node is a text node; otherwise returns FALSE.
|
|---|
| 2373 |
|
|---|
| 2374 | If this function returns TRUE, it does not imply that this object
|
|---|
| 2375 | is a QDomText; you can get the QDomText with toText().
|
|---|
| 2376 |
|
|---|
| 2377 | \sa toText()
|
|---|
| 2378 | */
|
|---|
| 2379 | bool QDomNode::isText() const
|
|---|
| 2380 | {
|
|---|
| 2381 | if(impl)
|
|---|
| 2382 | return impl->isText();
|
|---|
| 2383 | return FALSE;
|
|---|
| 2384 | }
|
|---|
| 2385 |
|
|---|
| 2386 | /*!
|
|---|
| 2387 | Returns TRUE if the node is an entity; otherwise returns FALSE.
|
|---|
| 2388 |
|
|---|
| 2389 | If this function returns TRUE, it does not imply that this object
|
|---|
| 2390 | is a QDomEntity; you can get the QDomEntity with toEntity().
|
|---|
| 2391 |
|
|---|
| 2392 | \sa toEntity()
|
|---|
| 2393 | */
|
|---|
| 2394 | bool QDomNode::isEntity() const
|
|---|
| 2395 | {
|
|---|
| 2396 | if(impl)
|
|---|
| 2397 | return impl->isEntity();
|
|---|
| 2398 | return FALSE;
|
|---|
| 2399 | }
|
|---|
| 2400 |
|
|---|
| 2401 | /*!
|
|---|
| 2402 | Returns TRUE if the node is a notation; otherwise returns FALSE.
|
|---|
| 2403 |
|
|---|
| 2404 | If this function returns TRUE, it does not imply that this object
|
|---|
| 2405 | is a QDomNotation; you can get the QDomNotation with toNotation().
|
|---|
| 2406 |
|
|---|
| 2407 | \sa toNotation()
|
|---|
| 2408 | */
|
|---|
| 2409 | bool QDomNode::isNotation() const
|
|---|
| 2410 | {
|
|---|
| 2411 | if(impl)
|
|---|
| 2412 | return impl->isNotation();
|
|---|
| 2413 | return FALSE;
|
|---|
| 2414 | }
|
|---|
| 2415 |
|
|---|
| 2416 | /*!
|
|---|
| 2417 | Returns TRUE if the node is a processing instruction; otherwise
|
|---|
| 2418 | returns FALSE.
|
|---|
| 2419 |
|
|---|
| 2420 | If this function returns TRUE, it does not imply that this object
|
|---|
| 2421 | is a QDomProcessingInstruction; you can get the
|
|---|
| 2422 | QProcessingInstruction with toProcessingInstruction().
|
|---|
| 2423 |
|
|---|
| 2424 | \sa toProcessingInstruction()
|
|---|
| 2425 | */
|
|---|
| 2426 | bool QDomNode::isProcessingInstruction() const
|
|---|
| 2427 | {
|
|---|
| 2428 | if(impl)
|
|---|
| 2429 | return impl->isProcessingInstruction();
|
|---|
| 2430 | return FALSE;
|
|---|
| 2431 | }
|
|---|
| 2432 |
|
|---|
| 2433 | /*!
|
|---|
| 2434 | Returns TRUE if the node is a character data node; otherwise
|
|---|
| 2435 | returns FALSE.
|
|---|
| 2436 |
|
|---|
| 2437 | If this function returns TRUE, it does not imply that this object
|
|---|
| 2438 | is a QDomCharacterData; you can get the QDomCharacterData with
|
|---|
| 2439 | toCharacterData().
|
|---|
| 2440 |
|
|---|
| 2441 | \sa toCharacterData()
|
|---|
| 2442 | */
|
|---|
| 2443 | bool QDomNode::isCharacterData() const
|
|---|
| 2444 | {
|
|---|
| 2445 | if(impl)
|
|---|
| 2446 | return impl->isCharacterData();
|
|---|
| 2447 | return FALSE;
|
|---|
| 2448 | }
|
|---|
| 2449 |
|
|---|
| 2450 | /*!
|
|---|
| 2451 | Returns TRUE if the node is a comment; otherwise returns FALSE.
|
|---|
| 2452 |
|
|---|
| 2453 | If this function returns TRUE, it does not imply that this object
|
|---|
| 2454 | is a QDomComment; you can get the QDomComment with toComment().
|
|---|
| 2455 |
|
|---|
| 2456 | \sa toComment()
|
|---|
| 2457 | */
|
|---|
| 2458 | bool QDomNode::isComment() const
|
|---|
| 2459 | {
|
|---|
| 2460 | if(impl)
|
|---|
| 2461 | return impl->isComment();
|
|---|
| 2462 | return FALSE;
|
|---|
| 2463 | }
|
|---|
| 2464 |
|
|---|
| 2465 | #undef IMPL
|
|---|
| 2466 |
|
|---|
| 2467 | /**************************************************************
|
|---|
| 2468 | *
|
|---|
| 2469 | * QDomNamedNodeMapPrivate
|
|---|
| 2470 | *
|
|---|
| 2471 | **************************************************************/
|
|---|
| 2472 |
|
|---|
| 2473 | QDomNamedNodeMapPrivate::QDomNamedNodeMapPrivate( QDomNodePrivate* n )
|
|---|
| 2474 | {
|
|---|
| 2475 | readonly = FALSE;
|
|---|
| 2476 | parent = n;
|
|---|
| 2477 | appendToParent = FALSE;
|
|---|
| 2478 | }
|
|---|
| 2479 |
|
|---|
| 2480 | QDomNamedNodeMapPrivate::~QDomNamedNodeMapPrivate()
|
|---|
| 2481 | {
|
|---|
| 2482 | clearMap();
|
|---|
| 2483 | }
|
|---|
| 2484 |
|
|---|
| 2485 | QDomNamedNodeMapPrivate* QDomNamedNodeMapPrivate::clone( QDomNodePrivate* p )
|
|---|
| 2486 | {
|
|---|
| 2487 | QDomNamedNodeMapPrivate* m = new QDomNamedNodeMapPrivate( p );
|
|---|
| 2488 | m->readonly = readonly;
|
|---|
| 2489 | m->appendToParent = appendToParent;
|
|---|
| 2490 |
|
|---|
| 2491 | QDictIterator<QDomNodePrivate> it ( map );
|
|---|
| 2492 | for ( ; it.current(); ++it )
|
|---|
| 2493 | m->setNamedItem( it.current()->cloneNode() );
|
|---|
| 2494 |
|
|---|
| 2495 | // we are no longer interested in ownership
|
|---|
| 2496 | m->deref();
|
|---|
| 2497 | return m;
|
|---|
| 2498 | }
|
|---|
| 2499 |
|
|---|
| 2500 | void QDomNamedNodeMapPrivate::clearMap()
|
|---|
| 2501 | {
|
|---|
| 2502 | // Dereference all of our children if we took references
|
|---|
| 2503 | if ( !appendToParent ) {
|
|---|
| 2504 | QDictIterator<QDomNodePrivate> it( map );
|
|---|
| 2505 | for ( ; it.current(); ++it )
|
|---|
| 2506 | if ( it.current()->deref() )
|
|---|
| 2507 | delete it.current();
|
|---|
| 2508 | }
|
|---|
| 2509 |
|
|---|
| 2510 | map.clear();
|
|---|
| 2511 | }
|
|---|
| 2512 |
|
|---|
| 2513 | QDomNodePrivate* QDomNamedNodeMapPrivate::namedItem( const QString& name ) const
|
|---|
| 2514 | {
|
|---|
| 2515 | QDomNodePrivate* p = map[ name ];
|
|---|
| 2516 | return p;
|
|---|
| 2517 | }
|
|---|
| 2518 |
|
|---|
| 2519 | QDomNodePrivate* QDomNamedNodeMapPrivate::namedItemNS( const QString& nsURI, const QString& localName ) const
|
|---|
| 2520 | {
|
|---|
| 2521 | QDictIterator<QDomNodePrivate> it( map );
|
|---|
| 2522 | QDomNodePrivate *n = it.current();
|
|---|
| 2523 | while ( n ) {
|
|---|
| 2524 | if ( !n->prefix.isNull() ) {
|
|---|
| 2525 | // node has a namespace
|
|---|
| 2526 | if ( n->namespaceURI==nsURI && n->name==localName ) {
|
|---|
| 2527 | return n;
|
|---|
| 2528 | }
|
|---|
| 2529 | }
|
|---|
| 2530 | ++it;
|
|---|
| 2531 | n = it.current();
|
|---|
| 2532 | }
|
|---|
| 2533 | return 0;
|
|---|
| 2534 | }
|
|---|
| 2535 |
|
|---|
| 2536 | QDomNodePrivate* QDomNamedNodeMapPrivate::setNamedItem( QDomNodePrivate* arg )
|
|---|
| 2537 | {
|
|---|
| 2538 | if ( readonly || !arg )
|
|---|
| 2539 | return 0;
|
|---|
| 2540 |
|
|---|
| 2541 | if ( appendToParent )
|
|---|
| 2542 | return parent->appendChild( arg );
|
|---|
| 2543 |
|
|---|
| 2544 | QDomNodePrivate *n = map[ arg->nodeName() ];
|
|---|
| 2545 | // We take a reference
|
|---|
| 2546 | arg->ref();
|
|---|
| 2547 | map.insert( arg->nodeName(), arg );
|
|---|
| 2548 | return n;
|
|---|
| 2549 | }
|
|---|
| 2550 |
|
|---|
| 2551 | QDomNodePrivate* QDomNamedNodeMapPrivate::setNamedItemNS( QDomNodePrivate* arg )
|
|---|
| 2552 | {
|
|---|
| 2553 | if ( readonly || !arg )
|
|---|
| 2554 | return 0;
|
|---|
| 2555 |
|
|---|
| 2556 | if ( appendToParent )
|
|---|
| 2557 | return parent->appendChild( arg );
|
|---|
| 2558 |
|
|---|
| 2559 | if ( !arg->prefix.isNull() ) {
|
|---|
| 2560 | // node has a namespace
|
|---|
| 2561 | QDomNodePrivate *n = namedItemNS( arg->namespaceURI, arg->name );
|
|---|
| 2562 | // We take a reference
|
|---|
| 2563 | arg->ref();
|
|---|
| 2564 | map.insert( arg->nodeName(), arg );
|
|---|
| 2565 | return n;
|
|---|
| 2566 | } else {
|
|---|
| 2567 | // ### check the following code if it is ok
|
|---|
| 2568 | return setNamedItem( arg );
|
|---|
| 2569 | }
|
|---|
| 2570 | }
|
|---|
| 2571 |
|
|---|
| 2572 | QDomNodePrivate* QDomNamedNodeMapPrivate::removeNamedItem( const QString& name )
|
|---|
| 2573 | {
|
|---|
| 2574 | if ( readonly )
|
|---|
| 2575 | return 0;
|
|---|
| 2576 |
|
|---|
| 2577 | QDomNodePrivate* p = namedItem( name );
|
|---|
| 2578 | if ( p == 0 )
|
|---|
| 2579 | return 0;
|
|---|
| 2580 | if ( appendToParent )
|
|---|
| 2581 | return parent->removeChild( p );
|
|---|
| 2582 |
|
|---|
| 2583 | map.remove( p->nodeName() );
|
|---|
| 2584 | // We took a reference, so we have to free one here
|
|---|
| 2585 | p->deref();
|
|---|
| 2586 | return p;
|
|---|
| 2587 | }
|
|---|
| 2588 |
|
|---|
| 2589 | QDomNodePrivate* QDomNamedNodeMapPrivate::item( int index ) const
|
|---|
| 2590 | {
|
|---|
| 2591 | if ( (uint)index >= length() )
|
|---|
| 2592 | return 0;
|
|---|
| 2593 |
|
|---|
| 2594 | QDictIterator<QDomNodePrivate> it( map );
|
|---|
| 2595 | for ( int i = 0; i < index; ++i, ++it )
|
|---|
| 2596 | ;
|
|---|
| 2597 | return it.current();
|
|---|
| 2598 | }
|
|---|
| 2599 |
|
|---|
| 2600 | uint QDomNamedNodeMapPrivate::length() const
|
|---|
| 2601 | {
|
|---|
| 2602 | return map.count();
|
|---|
| 2603 | }
|
|---|
| 2604 |
|
|---|
| 2605 | bool QDomNamedNodeMapPrivate::contains( const QString& name ) const
|
|---|
| 2606 | {
|
|---|
| 2607 | return ( map[ name ] != 0 );
|
|---|
| 2608 | }
|
|---|
| 2609 |
|
|---|
| 2610 | bool QDomNamedNodeMapPrivate::containsNS( const QString& nsURI, const QString & localName ) const
|
|---|
| 2611 | {
|
|---|
| 2612 | return ( namedItemNS( nsURI, localName ) != 0 );
|
|---|
| 2613 | }
|
|---|
| 2614 |
|
|---|
| 2615 | /**************************************************************
|
|---|
| 2616 | *
|
|---|
| 2617 | * QDomNamedNodeMap
|
|---|
| 2618 | *
|
|---|
| 2619 | **************************************************************/
|
|---|
| 2620 |
|
|---|
| 2621 | #define IMPL ((QDomNamedNodeMapPrivate*)impl)
|
|---|
| 2622 |
|
|---|
| 2623 | /*!
|
|---|
| 2624 | \class QDomNamedNodeMap qdom.h
|
|---|
| 2625 | \reentrant
|
|---|
| 2626 | \brief The QDomNamedNodeMap class contains a collection of nodes
|
|---|
| 2627 | that can be accessed by name.
|
|---|
| 2628 | \if defined(commercial)
|
|---|
| 2629 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
|---|
| 2630 | \endif
|
|---|
| 2631 |
|
|---|
| 2632 | \module XML
|
|---|
| 2633 | \ingroup xml-tools
|
|---|
| 2634 |
|
|---|
| 2635 | Note that QDomNamedNodeMap does not inherit from QDomNodeList.
|
|---|
| 2636 | QDomNamedNodeMaps do not provide any specific node ordering.
|
|---|
| 2637 | Although nodes in a QDomNamedNodeMap may be accessed by an ordinal
|
|---|
| 2638 | index, this is simply to allow a convenient enumeration of the
|
|---|
| 2639 | contents of a QDomNamedNodeMap, and does not imply that the DOM
|
|---|
| 2640 | specifies an ordering of the nodes.
|
|---|
| 2641 |
|
|---|
| 2642 | The QDomNamedNodeMap is used in three places:
|
|---|
| 2643 | \list 1
|
|---|
| 2644 | \i QDomDocumentType::entities() returns a map of all entities
|
|---|
| 2645 | described in the DTD.
|
|---|
| 2646 | \i QDomDocumentType::notations() returns a map of all notations
|
|---|
| 2647 | described in the DTD.
|
|---|
| 2648 | \i QDomNode::attributes() returns a map of all attributes of an
|
|---|
| 2649 | element.
|
|---|
| 2650 | \endlist
|
|---|
| 2651 |
|
|---|
| 2652 | Items in the map are identified by the name which QDomNode::name()
|
|---|
| 2653 | returns. Nodes are retrieved using namedItem(), namedItemNS() or
|
|---|
| 2654 | item(). New nodes are inserted with setNamedItem() or
|
|---|
| 2655 | setNamedItemNS() and removed with removeNamedItem() or
|
|---|
| 2656 | removeNamedItemNS(). Use contains() to see if an item with the
|
|---|
| 2657 | given name is in the named node map. The number of items is
|
|---|
| 2658 | returned by length().
|
|---|
| 2659 |
|
|---|
| 2660 | Terminology: in this class we use "item" and "node"
|
|---|
| 2661 | interchangeably.
|
|---|
| 2662 | */
|
|---|
| 2663 |
|
|---|
| 2664 | /*!
|
|---|
| 2665 | Constructs an empty named node map.
|
|---|
| 2666 | */
|
|---|
| 2667 | QDomNamedNodeMap::QDomNamedNodeMap()
|
|---|
| 2668 | {
|
|---|
| 2669 | impl = 0;
|
|---|
| 2670 | }
|
|---|
| 2671 |
|
|---|
| 2672 | /*!
|
|---|
| 2673 | Constructs a copy of \a n.
|
|---|
| 2674 | */
|
|---|
| 2675 | QDomNamedNodeMap::QDomNamedNodeMap( const QDomNamedNodeMap& n )
|
|---|
| 2676 | {
|
|---|
| 2677 | impl = n.impl;
|
|---|
| 2678 | if ( impl )
|
|---|
| 2679 | impl->ref();
|
|---|
| 2680 | }
|
|---|
| 2681 |
|
|---|
| 2682 | QDomNamedNodeMap::QDomNamedNodeMap( QDomNamedNodeMapPrivate* n )
|
|---|
| 2683 | {
|
|---|
| 2684 | impl = n;
|
|---|
| 2685 | if ( impl )
|
|---|
| 2686 | impl->ref();
|
|---|
| 2687 | }
|
|---|
| 2688 |
|
|---|
| 2689 | /*!
|
|---|
| 2690 | Assigns \a n to this named node map.
|
|---|
| 2691 | */
|
|---|
| 2692 | QDomNamedNodeMap& QDomNamedNodeMap::operator= ( const QDomNamedNodeMap& n )
|
|---|
| 2693 | {
|
|---|
| 2694 | if ( impl && impl->deref() )
|
|---|
| 2695 | delete impl;
|
|---|
| 2696 | impl = n.impl;
|
|---|
| 2697 | if ( impl )
|
|---|
| 2698 | impl->ref();
|
|---|
| 2699 |
|
|---|
| 2700 | return *this;
|
|---|
| 2701 | }
|
|---|
| 2702 |
|
|---|
| 2703 | /*!
|
|---|
| 2704 | Returns TRUE if \a n and this named node map are equal; otherwise
|
|---|
| 2705 | returns FALSE.
|
|---|
| 2706 | */
|
|---|
| 2707 | bool QDomNamedNodeMap::operator== ( const QDomNamedNodeMap& n ) const
|
|---|
| 2708 | {
|
|---|
| 2709 | return ( impl == n.impl );
|
|---|
| 2710 | }
|
|---|
| 2711 |
|
|---|
| 2712 | /*!
|
|---|
| 2713 | Returns TRUE if \a n and this named node map are not equal;
|
|---|
| 2714 | otherwise returns FALSE.
|
|---|
| 2715 | */
|
|---|
| 2716 | bool QDomNamedNodeMap::operator!= ( const QDomNamedNodeMap& n ) const
|
|---|
| 2717 | {
|
|---|
| 2718 | return ( impl != n.impl );
|
|---|
| 2719 | }
|
|---|
| 2720 |
|
|---|
| 2721 | /*!
|
|---|
| 2722 | Destroys the object and frees its resources.
|
|---|
| 2723 | */
|
|---|
| 2724 | QDomNamedNodeMap::~QDomNamedNodeMap()
|
|---|
| 2725 | {
|
|---|
| 2726 | if ( impl && impl->deref() )
|
|---|
| 2727 | delete impl;
|
|---|
| 2728 | }
|
|---|
| 2729 |
|
|---|
| 2730 | /*!
|
|---|
| 2731 | Returns the node called \a name.
|
|---|
| 2732 |
|
|---|
| 2733 | If the named node map does not contain such a node, a \link
|
|---|
| 2734 | QDomNode::isNull() null node\endlink is returned. A node's name is
|
|---|
| 2735 | the name returned by QDomNode::nodeName().
|
|---|
| 2736 |
|
|---|
| 2737 | \sa setNamedItem() namedItemNS()
|
|---|
| 2738 | */
|
|---|
| 2739 | QDomNode QDomNamedNodeMap::namedItem( const QString& name ) const
|
|---|
| 2740 | {
|
|---|
| 2741 | if ( !impl )
|
|---|
| 2742 | return QDomNode();
|
|---|
| 2743 | return QDomNode( IMPL->namedItem( name ) );
|
|---|
| 2744 | }
|
|---|
| 2745 |
|
|---|
| 2746 | /*!
|
|---|
| 2747 | Inserts the node \a newNode into the named node map. The name used
|
|---|
| 2748 | by the map is the node name of \a newNode as returned by
|
|---|
| 2749 | QDomNode::nodeName().
|
|---|
| 2750 |
|
|---|
| 2751 | If the new node replaces an existing node, i.e. the map contains a
|
|---|
| 2752 | node with the same name, the replaced node is returned.
|
|---|
| 2753 |
|
|---|
| 2754 | \sa namedItem() removeNamedItem() setNamedItemNS()
|
|---|
| 2755 | */
|
|---|
| 2756 | QDomNode QDomNamedNodeMap::setNamedItem( const QDomNode& newNode )
|
|---|
| 2757 | {
|
|---|
| 2758 | if ( !impl )
|
|---|
| 2759 | return QDomNode();
|
|---|
| 2760 | return QDomNode( IMPL->setNamedItem( (QDomNodePrivate*)newNode.impl ) );
|
|---|
| 2761 | }
|
|---|
| 2762 |
|
|---|
| 2763 | /*!
|
|---|
| 2764 | Removes the node called \a name from the map.
|
|---|
| 2765 |
|
|---|
| 2766 | The function returns the removed node or a \link
|
|---|
| 2767 | QDomNode::isNull() null node\endlink if the map did not contain a
|
|---|
| 2768 | node called \a name.
|
|---|
| 2769 |
|
|---|
| 2770 | \sa setNamedItem() namedItem() removeNamedItemNS()
|
|---|
| 2771 | */
|
|---|
| 2772 | QDomNode QDomNamedNodeMap::removeNamedItem( const QString& name )
|
|---|
| 2773 | {
|
|---|
| 2774 | if ( !impl )
|
|---|
| 2775 | return QDomNode();
|
|---|
| 2776 | return QDomNode( IMPL->removeNamedItem( name ) );
|
|---|
| 2777 | }
|
|---|
| 2778 |
|
|---|
| 2779 | /*!
|
|---|
| 2780 | Retrieves the node at position \a index.
|
|---|
| 2781 |
|
|---|
| 2782 | This can be used to iterate over the map. Note that the nodes in
|
|---|
| 2783 | the map are ordered arbitrarily.
|
|---|
| 2784 |
|
|---|
| 2785 | \sa length()
|
|---|
| 2786 | */
|
|---|
| 2787 | QDomNode QDomNamedNodeMap::item( int index ) const
|
|---|
| 2788 | {
|
|---|
| 2789 | if ( !impl )
|
|---|
| 2790 | return QDomNode();
|
|---|
| 2791 | return QDomNode( IMPL->item( index ) );
|
|---|
| 2792 | }
|
|---|
| 2793 |
|
|---|
| 2794 | /*!
|
|---|
| 2795 | Returns the node associated with the local name \a localName and
|
|---|
| 2796 | the namespace URI \a nsURI.
|
|---|
| 2797 |
|
|---|
| 2798 | If the map does not contain such a node, a \link
|
|---|
| 2799 | QDomNode::isNull() null node\endlink is returned.
|
|---|
| 2800 |
|
|---|
| 2801 | \sa setNamedItemNS() namedItem()
|
|---|
| 2802 | */
|
|---|
| 2803 | QDomNode QDomNamedNodeMap::namedItemNS( const QString& nsURI, const QString& localName ) const
|
|---|
| 2804 | {
|
|---|
| 2805 | if ( !impl )
|
|---|
| 2806 | return QDomNode();
|
|---|
| 2807 | return QDomNode( IMPL->namedItemNS( nsURI, localName ) );
|
|---|
| 2808 | }
|
|---|
| 2809 |
|
|---|
| 2810 | /*!
|
|---|
| 2811 | Inserts the node \a newNode in the map. If a node with the same
|
|---|
| 2812 | namespace URI and the same local name already exists in the map,
|
|---|
| 2813 | it is replaced by \a newNode. If the new node replaces an existing
|
|---|
| 2814 | node, the replaced node is returned.
|
|---|
| 2815 |
|
|---|
| 2816 | \sa namedItemNS() removeNamedItemNS() setNamedItem()
|
|---|
| 2817 | */
|
|---|
| 2818 | QDomNode QDomNamedNodeMap::setNamedItemNS( const QDomNode& newNode )
|
|---|
| 2819 | {
|
|---|
| 2820 | if ( !impl )
|
|---|
| 2821 | return QDomNode();
|
|---|
| 2822 | return QDomNode( IMPL->setNamedItemNS( (QDomNodePrivate*)newNode.impl ) );
|
|---|
| 2823 | }
|
|---|
| 2824 |
|
|---|
| 2825 | /*!
|
|---|
| 2826 | Removes the node with the local name \a localName and the
|
|---|
| 2827 | namespace URI \a nsURI from the map.
|
|---|
| 2828 |
|
|---|
| 2829 | The function returns the removed node or a \link
|
|---|
| 2830 | QDomNode::isNull() null node\endlink if the map did not contain a
|
|---|
| 2831 | node with the local name \a localName and the namespace URI \a
|
|---|
| 2832 | nsURI.
|
|---|
| 2833 |
|
|---|
| 2834 | \sa setNamedItemNS() namedItemNS() removeNamedItem()
|
|---|
| 2835 | */
|
|---|
| 2836 | QDomNode QDomNamedNodeMap::removeNamedItemNS( const QString& nsURI, const QString& localName )
|
|---|
| 2837 | {
|
|---|
| 2838 | if ( !impl )
|
|---|
| 2839 | return QDomNode();
|
|---|
| 2840 | QDomNodePrivate *n = IMPL->namedItemNS( nsURI, localName );
|
|---|
| 2841 | if ( !n )
|
|---|
| 2842 | return QDomNode();
|
|---|
| 2843 | return QDomNode( IMPL->removeNamedItem( n->name ) );
|
|---|
| 2844 | }
|
|---|
| 2845 |
|
|---|
| 2846 | /*!
|
|---|
| 2847 | Returns the number of nodes in the map.
|
|---|
| 2848 |
|
|---|
| 2849 | \sa item()
|
|---|
| 2850 | */
|
|---|
| 2851 | uint QDomNamedNodeMap::length() const
|
|---|
| 2852 | {
|
|---|
| 2853 | if ( !impl )
|
|---|
| 2854 | return 0;
|
|---|
| 2855 | return IMPL->length();
|
|---|
| 2856 | }
|
|---|
| 2857 |
|
|---|
| 2858 | /*!
|
|---|
| 2859 | \fn uint QDomNamedNodeMap::count() const
|
|---|
| 2860 |
|
|---|
| 2861 | Returns the number of nodes in the map.
|
|---|
| 2862 |
|
|---|
| 2863 | This function is the same as length().
|
|---|
| 2864 | */
|
|---|
| 2865 |
|
|---|
| 2866 | /*!
|
|---|
| 2867 | Returns TRUE if the map contains a node called \a name; otherwise
|
|---|
| 2868 | returns FALSE.
|
|---|
| 2869 | */
|
|---|
| 2870 | bool QDomNamedNodeMap::contains( const QString& name ) const
|
|---|
| 2871 | {
|
|---|
| 2872 | if ( !impl )
|
|---|
| 2873 | return FALSE;
|
|---|
| 2874 | return IMPL->contains( name );
|
|---|
| 2875 | }
|
|---|
| 2876 |
|
|---|
| 2877 | #undef IMPL
|
|---|
| 2878 |
|
|---|
| 2879 | /**************************************************************
|
|---|
| 2880 | *
|
|---|
| 2881 | * QDomDocumentTypePrivate
|
|---|
| 2882 | *
|
|---|
| 2883 | **************************************************************/
|
|---|
| 2884 |
|
|---|
| 2885 | QDomDocumentTypePrivate::QDomDocumentTypePrivate( QDomDocumentPrivate* doc, QDomNodePrivate* parent )
|
|---|
| 2886 | : QDomNodePrivate( doc, parent )
|
|---|
| 2887 | {
|
|---|
| 2888 | init();
|
|---|
| 2889 | }
|
|---|
| 2890 |
|
|---|
| 2891 | QDomDocumentTypePrivate::QDomDocumentTypePrivate( QDomDocumentTypePrivate* n, bool deep )
|
|---|
| 2892 | : QDomNodePrivate( n, deep )
|
|---|
| 2893 | {
|
|---|
| 2894 | init();
|
|---|
| 2895 | // Refill the maps with our new children
|
|---|
| 2896 | QDomNodePrivate* p = first;
|
|---|
| 2897 | while ( p ) {
|
|---|
| 2898 | if ( p->isEntity() )
|
|---|
| 2899 | // Dont use normal insert function since we would create infinite recursion
|
|---|
| 2900 | entities->map.insert( p->nodeName(), p );
|
|---|
| 2901 | if ( p->isNotation() )
|
|---|
| 2902 | // Dont use normal insert function since we would create infinite recursion
|
|---|
| 2903 | notations->map.insert( p->nodeName(), p );
|
|---|
| 2904 | }
|
|---|
| 2905 | }
|
|---|
| 2906 |
|
|---|
| 2907 | QDomDocumentTypePrivate::~QDomDocumentTypePrivate()
|
|---|
| 2908 | {
|
|---|
| 2909 | if ( entities->deref() )
|
|---|
| 2910 | delete entities;
|
|---|
| 2911 | if ( notations->deref() )
|
|---|
| 2912 | delete notations;
|
|---|
| 2913 | }
|
|---|
| 2914 |
|
|---|
| 2915 | void QDomDocumentTypePrivate::init()
|
|---|
| 2916 | {
|
|---|
| 2917 | entities = new QDomNamedNodeMapPrivate( this );
|
|---|
| 2918 | notations = new QDomNamedNodeMapPrivate( this );
|
|---|
| 2919 | publicId = QString::null;
|
|---|
| 2920 | systemId = QString::null;
|
|---|
| 2921 | internalSubset = QString::null;
|
|---|
| 2922 |
|
|---|
| 2923 | entities->setAppendToParent( TRUE );
|
|---|
| 2924 | notations->setAppendToParent( TRUE );
|
|---|
| 2925 | }
|
|---|
| 2926 |
|
|---|
| 2927 | QDomNodePrivate* QDomDocumentTypePrivate::cloneNode( bool deep)
|
|---|
| 2928 | {
|
|---|
| 2929 | QDomNodePrivate* p = new QDomDocumentTypePrivate( this, deep );
|
|---|
| 2930 | // We are not interested in this node
|
|---|
| 2931 | p->deref();
|
|---|
| 2932 | return p;
|
|---|
| 2933 | }
|
|---|
| 2934 |
|
|---|
| 2935 | QDomNodePrivate* QDomDocumentTypePrivate::insertBefore( QDomNodePrivate* newChild, QDomNodePrivate* refChild )
|
|---|
| 2936 | {
|
|---|
| 2937 | // Call the origianl implementation
|
|---|
| 2938 | QDomNodePrivate* p = QDomNodePrivate::insertBefore( newChild, refChild );
|
|---|
| 2939 | // Update the maps
|
|---|
| 2940 | if ( p && p->isEntity() )
|
|---|
| 2941 | entities->map.insert( p->nodeName(), p );
|
|---|
| 2942 | else if ( p && p->isNotation() )
|
|---|
| 2943 | notations->map.insert( p->nodeName(), p );
|
|---|
| 2944 |
|
|---|
| 2945 | return p;
|
|---|
| 2946 | }
|
|---|
| 2947 |
|
|---|
| 2948 | QDomNodePrivate* QDomDocumentTypePrivate::insertAfter( QDomNodePrivate* newChild, QDomNodePrivate* refChild )
|
|---|
| 2949 | {
|
|---|
| 2950 | // Call the origianl implementation
|
|---|
| 2951 | QDomNodePrivate* p = QDomNodePrivate::insertAfter( newChild, refChild );
|
|---|
| 2952 | // Update the maps
|
|---|
| 2953 | if ( p && p->isEntity() )
|
|---|
| 2954 | entities->map.insert( p->nodeName(), p );
|
|---|
| 2955 | else if ( p && p->isNotation() )
|
|---|
| 2956 | notations->map.insert( p->nodeName(), p );
|
|---|
| 2957 |
|
|---|
| 2958 | return p;
|
|---|
| 2959 | }
|
|---|
| 2960 |
|
|---|
| 2961 | QDomNodePrivate* QDomDocumentTypePrivate::replaceChild( QDomNodePrivate* newChild, QDomNodePrivate* oldChild )
|
|---|
| 2962 | {
|
|---|
| 2963 | // Call the origianl implementation
|
|---|
| 2964 | QDomNodePrivate* p = QDomNodePrivate::replaceChild( newChild, oldChild );
|
|---|
| 2965 | // Update the maps
|
|---|
| 2966 | if ( p ) {
|
|---|
| 2967 | if ( oldChild && oldChild->isEntity() )
|
|---|
| 2968 | entities->map.remove( oldChild->nodeName() );
|
|---|
| 2969 | else if ( oldChild && oldChild->isNotation() )
|
|---|
| 2970 | notations->map.remove( oldChild->nodeName() );
|
|---|
| 2971 |
|
|---|
| 2972 | if ( p->isEntity() )
|
|---|
| 2973 | entities->map.insert( p->nodeName(), p );
|
|---|
| 2974 | else if ( p->isNotation() )
|
|---|
| 2975 | notations->map.insert( p->nodeName(), p );
|
|---|
| 2976 | }
|
|---|
| 2977 |
|
|---|
| 2978 | return p;
|
|---|
| 2979 | }
|
|---|
| 2980 |
|
|---|
| 2981 | QDomNodePrivate* QDomDocumentTypePrivate::removeChild( QDomNodePrivate* oldChild )
|
|---|
| 2982 | {
|
|---|
| 2983 | // Call the origianl implementation
|
|---|
| 2984 | QDomNodePrivate* p = QDomNodePrivate::removeChild( oldChild );
|
|---|
| 2985 | // Update the maps
|
|---|
| 2986 | if ( p && p->isEntity() )
|
|---|
| 2987 | entities->map.remove( p->nodeName() );
|
|---|
| 2988 | else if ( p && p->isNotation() )
|
|---|
| 2989 | notations->map.remove( p ->nodeName() );
|
|---|
| 2990 |
|
|---|
| 2991 | return p;
|
|---|
| 2992 | }
|
|---|
| 2993 |
|
|---|
| 2994 | QDomNodePrivate* QDomDocumentTypePrivate::appendChild( QDomNodePrivate* newChild )
|
|---|
| 2995 | {
|
|---|
| 2996 | return insertAfter( newChild, 0 );
|
|---|
| 2997 | }
|
|---|
| 2998 |
|
|---|
| 2999 | void QDomDocumentTypePrivate::save( QTextStream& s, int, int indent ) const
|
|---|
| 3000 | {
|
|---|
| 3001 | if ( name.isEmpty() )
|
|---|
| 3002 | return;
|
|---|
| 3003 |
|
|---|
| 3004 | s << "<!DOCTYPE " << name;
|
|---|
| 3005 |
|
|---|
| 3006 | if ( !publicId.isNull() ) {
|
|---|
| 3007 | s << " PUBLIC \"" << publicId << "\"";
|
|---|
| 3008 | if ( !systemId.isNull() )
|
|---|
| 3009 | s << " \"" << systemId << "\"";
|
|---|
| 3010 | } else if ( !systemId.isNull() ) {
|
|---|
| 3011 | s << " SYSTEM \"" << systemId << "\"";
|
|---|
| 3012 | }
|
|---|
| 3013 |
|
|---|
| 3014 | if ( entities->length()>0 || notations->length()>0 ) {
|
|---|
| 3015 | s << " [ " << endl;
|
|---|
| 3016 |
|
|---|
| 3017 | QDictIterator<QDomNodePrivate> it2( notations->map );
|
|---|
| 3018 | for ( ; it2.current(); ++it2 )
|
|---|
| 3019 | it2.current()->save( s, 0, indent );
|
|---|
| 3020 |
|
|---|
| 3021 | QDictIterator<QDomNodePrivate> it( entities->map );
|
|---|
| 3022 | for ( ; it.current(); ++it )
|
|---|
| 3023 | it.current()->save( s, 0, indent );
|
|---|
| 3024 |
|
|---|
| 3025 | s << " ]";
|
|---|
| 3026 | }
|
|---|
| 3027 |
|
|---|
| 3028 | s << ">" << endl;
|
|---|
| 3029 | }
|
|---|
| 3030 |
|
|---|
| 3031 | /**************************************************************
|
|---|
| 3032 | *
|
|---|
| 3033 | * QDomDocumentType
|
|---|
| 3034 | *
|
|---|
| 3035 | **************************************************************/
|
|---|
| 3036 |
|
|---|
| 3037 | #define IMPL ((QDomDocumentTypePrivate*)impl)
|
|---|
| 3038 |
|
|---|
| 3039 | /*!
|
|---|
| 3040 | \class QDomDocumentType qdom.h
|
|---|
| 3041 | \reentrant
|
|---|
| 3042 | \brief The QDomDocumentType class is the representation of the DTD
|
|---|
| 3043 | in the document tree.
|
|---|
| 3044 | \if defined(commercial)
|
|---|
| 3045 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
|---|
| 3046 | \endif
|
|---|
| 3047 |
|
|---|
| 3048 | \module XML
|
|---|
| 3049 | \ingroup xml-tools
|
|---|
| 3050 |
|
|---|
| 3051 | The QDomDocumentType class allows read-only access to some of the
|
|---|
| 3052 | data structures in the DTD: it can return a map of all entities()
|
|---|
| 3053 | and notations(). In addition the function name() returns the name
|
|---|
| 3054 | of the document type as specified in the <!DOCTYPE name>
|
|---|
| 3055 | tag. This class also provides the publicId(), systemId() and
|
|---|
| 3056 | internalSubset() functions.
|
|---|
| 3057 |
|
|---|
| 3058 | \sa QDomDocument
|
|---|
| 3059 | */
|
|---|
| 3060 |
|
|---|
| 3061 | /*!
|
|---|
| 3062 | Creates an empty QDomDocumentType object.
|
|---|
| 3063 | */
|
|---|
| 3064 | QDomDocumentType::QDomDocumentType() : QDomNode()
|
|---|
| 3065 | {
|
|---|
| 3066 | }
|
|---|
| 3067 |
|
|---|
| 3068 | /*!
|
|---|
| 3069 | Constructs a copy of \a n.
|
|---|
| 3070 |
|
|---|
| 3071 | The data of the copy is shared (shallow copy): modifying one node
|
|---|
| 3072 | will also change the other. If you want to make a deep copy, use
|
|---|
| 3073 | cloneNode().
|
|---|
| 3074 | */
|
|---|
| 3075 | QDomDocumentType::QDomDocumentType( const QDomDocumentType& n )
|
|---|
| 3076 | : QDomNode( n )
|
|---|
| 3077 | {
|
|---|
| 3078 | }
|
|---|
| 3079 |
|
|---|
| 3080 | QDomDocumentType::QDomDocumentType( QDomDocumentTypePrivate* n )
|
|---|
| 3081 | : QDomNode( n )
|
|---|
| 3082 | {
|
|---|
| 3083 | }
|
|---|
| 3084 |
|
|---|
| 3085 | /*!
|
|---|
| 3086 | Assigns \a n to this document type.
|
|---|
| 3087 |
|
|---|
| 3088 | The data of the copy is shared (shallow copy): modifying one node
|
|---|
| 3089 | will also change the other. If you want to make a deep copy, use
|
|---|
| 3090 | cloneNode().
|
|---|
| 3091 | */
|
|---|
| 3092 | QDomDocumentType& QDomDocumentType::operator= ( const QDomDocumentType& n )
|
|---|
| 3093 | {
|
|---|
| 3094 | return (QDomDocumentType&) QDomNode::operator=( n );
|
|---|
| 3095 | }
|
|---|
| 3096 |
|
|---|
| 3097 | /*!
|
|---|
| 3098 | Destroys the object and frees its resources.
|
|---|
| 3099 | */
|
|---|
| 3100 | QDomDocumentType::~QDomDocumentType()
|
|---|
| 3101 | {
|
|---|
| 3102 | }
|
|---|
| 3103 |
|
|---|
| 3104 | /*!
|
|---|
| 3105 | Returns the name of the document type as specified in the
|
|---|
| 3106 | <!DOCTYPE name> tag.
|
|---|
| 3107 |
|
|---|
| 3108 | \sa nodeName()
|
|---|
| 3109 | */
|
|---|
| 3110 | QString QDomDocumentType::name() const
|
|---|
| 3111 | {
|
|---|
| 3112 | if ( !impl )
|
|---|
| 3113 | return QString::null;
|
|---|
| 3114 |
|
|---|
| 3115 | return IMPL->nodeName();
|
|---|
| 3116 | }
|
|---|
| 3117 |
|
|---|
| 3118 | /*!
|
|---|
| 3119 | Returns a map of all entities described in the DTD.
|
|---|
| 3120 | */
|
|---|
| 3121 | QDomNamedNodeMap QDomDocumentType::entities() const
|
|---|
| 3122 | {
|
|---|
| 3123 | if ( !impl )
|
|---|
| 3124 | return QDomNamedNodeMap();
|
|---|
| 3125 | return QDomNamedNodeMap( IMPL->entities );
|
|---|
| 3126 | }
|
|---|
| 3127 |
|
|---|
| 3128 | /*!
|
|---|
| 3129 | Returns a map of all notations described in the DTD.
|
|---|
| 3130 | */
|
|---|
| 3131 | QDomNamedNodeMap QDomDocumentType::notations() const
|
|---|
| 3132 | {
|
|---|
| 3133 | if ( !impl )
|
|---|
| 3134 | return QDomNamedNodeMap();
|
|---|
| 3135 | return QDomNamedNodeMap( IMPL->notations );
|
|---|
| 3136 | }
|
|---|
| 3137 |
|
|---|
| 3138 | /*!
|
|---|
| 3139 | Returns the public identifier of the external DTD subset or
|
|---|
| 3140 | QString::null if there is no public identifier.
|
|---|
| 3141 |
|
|---|
| 3142 | \sa systemId() internalSubset() QDomImplementation::createDocumentType()
|
|---|
| 3143 | */
|
|---|
| 3144 | QString QDomDocumentType::publicId() const
|
|---|
| 3145 | {
|
|---|
| 3146 | if ( !impl )
|
|---|
| 3147 | return QString::null;
|
|---|
| 3148 | return IMPL->publicId;
|
|---|
| 3149 | }
|
|---|
| 3150 |
|
|---|
| 3151 | /*!
|
|---|
| 3152 | Returns the system identifier of the external DTD subset or
|
|---|
| 3153 | QString::null if there is no system identifier.
|
|---|
| 3154 |
|
|---|
| 3155 | \sa publicId() internalSubset() QDomImplementation::createDocumentType()
|
|---|
| 3156 | */
|
|---|
| 3157 | QString QDomDocumentType::systemId() const
|
|---|
| 3158 | {
|
|---|
| 3159 | if ( !impl )
|
|---|
| 3160 | return QString::null;
|
|---|
| 3161 | return IMPL->systemId;
|
|---|
| 3162 | }
|
|---|
| 3163 |
|
|---|
| 3164 | /*!
|
|---|
| 3165 | Returns the internal subset of the document type or QString::null
|
|---|
| 3166 | if there is no internal subset.
|
|---|
| 3167 |
|
|---|
| 3168 | \sa publicId() systemId()
|
|---|
| 3169 | */
|
|---|
| 3170 | QString QDomDocumentType::internalSubset() const
|
|---|
| 3171 | {
|
|---|
| 3172 | if ( !impl )
|
|---|
| 3173 | return QString::null;
|
|---|
| 3174 | return IMPL->internalSubset;
|
|---|
| 3175 | }
|
|---|
| 3176 |
|
|---|
| 3177 | /*!
|
|---|
| 3178 | Returns \c DocumentTypeNode.
|
|---|
| 3179 |
|
|---|
| 3180 | \sa isDocumentType() QDomNode::toDocumentType()
|
|---|
| 3181 | */
|
|---|
| 3182 | QDomNode::NodeType QDomDocumentType::nodeType() const
|
|---|
| 3183 | {
|
|---|
| 3184 | return DocumentTypeNode;
|
|---|
| 3185 | }
|
|---|
| 3186 |
|
|---|
| 3187 | /*!
|
|---|
| 3188 | This function overloads QDomNode::isDocumentType().
|
|---|
| 3189 |
|
|---|
| 3190 | \sa nodeType() QDomNode::toDocumentType()
|
|---|
| 3191 | */
|
|---|
| 3192 | bool QDomDocumentType::isDocumentType() const
|
|---|
| 3193 | {
|
|---|
| 3194 | return TRUE;
|
|---|
| 3195 | }
|
|---|
| 3196 |
|
|---|
| 3197 | #undef IMPL
|
|---|
| 3198 |
|
|---|
| 3199 | /**************************************************************
|
|---|
| 3200 | *
|
|---|
| 3201 | * QDomDocumentFragmentPrivate
|
|---|
| 3202 | *
|
|---|
| 3203 | **************************************************************/
|
|---|
| 3204 |
|
|---|
| 3205 | QDomDocumentFragmentPrivate::QDomDocumentFragmentPrivate( QDomDocumentPrivate* doc, QDomNodePrivate* parent )
|
|---|
| 3206 | : QDomNodePrivate( doc, parent )
|
|---|
| 3207 | {
|
|---|
| 3208 | name = "#document-fragment";
|
|---|
| 3209 | }
|
|---|
| 3210 |
|
|---|
| 3211 | QDomDocumentFragmentPrivate::QDomDocumentFragmentPrivate( QDomNodePrivate* n, bool deep )
|
|---|
| 3212 | : QDomNodePrivate( n, deep )
|
|---|
| 3213 | {
|
|---|
| 3214 | }
|
|---|
| 3215 |
|
|---|
| 3216 | QDomDocumentFragmentPrivate::~QDomDocumentFragmentPrivate()
|
|---|
| 3217 | {
|
|---|
| 3218 | }
|
|---|
| 3219 |
|
|---|
| 3220 | QDomNodePrivate* QDomDocumentFragmentPrivate::cloneNode( bool deep)
|
|---|
| 3221 | {
|
|---|
| 3222 | QDomNodePrivate* p = new QDomDocumentFragmentPrivate( this, deep );
|
|---|
| 3223 | // We are not interested in this node
|
|---|
| 3224 | p->deref();
|
|---|
| 3225 | return p;
|
|---|
| 3226 | }
|
|---|
| 3227 |
|
|---|
| 3228 | /**************************************************************
|
|---|
| 3229 | *
|
|---|
| 3230 | * QDomDocumentFragment
|
|---|
| 3231 | *
|
|---|
| 3232 | **************************************************************/
|
|---|
| 3233 |
|
|---|
| 3234 | #define IMPL ((QDomDocumentFragmentPrivate*)impl)
|
|---|
| 3235 |
|
|---|
| 3236 | /*!
|
|---|
| 3237 | \class QDomDocumentFragment qdom.h
|
|---|
| 3238 | \reentrant
|
|---|
| 3239 | \brief The QDomDocumentFragment class is a tree of QDomNodes which is not usually a complete QDomDocument.
|
|---|
| 3240 | \if defined(commercial)
|
|---|
| 3241 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
|---|
| 3242 | \endif
|
|---|
| 3243 |
|
|---|
| 3244 | \module XML
|
|---|
| 3245 | \ingroup xml-tools
|
|---|
| 3246 |
|
|---|
| 3247 | If you want to do complex tree operations it is useful to have a
|
|---|
| 3248 | lightweight class to store nodes and their relations.
|
|---|
| 3249 | QDomDocumentFragment stores a subtree of a document which does not
|
|---|
| 3250 | necessarily represent a well-formed XML document.
|
|---|
| 3251 |
|
|---|
| 3252 | QDomDocumentFragment is also useful if you want to group several
|
|---|
| 3253 | nodes in a list and insert them all together as children of some
|
|---|
| 3254 | node. In these cases QDomDocumentFragment can be used as a
|
|---|
| 3255 | temporary container for this list of children.
|
|---|
| 3256 |
|
|---|
| 3257 | The most important feature of QDomDocumentFragment is that it is
|
|---|
| 3258 | treated in a special way by QDomNode::insertAfter(),
|
|---|
| 3259 | QDomNode::insertBefore(), QDomNode::replaceChild() and
|
|---|
| 3260 | QDomNode::appendChild(): instead of inserting the fragment itself, all
|
|---|
| 3261 | the fragment's children are inserted.
|
|---|
| 3262 | */
|
|---|
| 3263 |
|
|---|
| 3264 | /*!
|
|---|
| 3265 | Constructs an empty document fragment.
|
|---|
| 3266 | */
|
|---|
| 3267 | QDomDocumentFragment::QDomDocumentFragment()
|
|---|
| 3268 | {
|
|---|
| 3269 | }
|
|---|
| 3270 |
|
|---|
| 3271 | QDomDocumentFragment::QDomDocumentFragment( QDomDocumentFragmentPrivate* n )
|
|---|
| 3272 | : QDomNode( n )
|
|---|
| 3273 | {
|
|---|
| 3274 | }
|
|---|
| 3275 |
|
|---|
| 3276 | /*!
|
|---|
| 3277 | Constructs a copy of \a x.
|
|---|
| 3278 |
|
|---|
| 3279 | The data of the copy is shared (shallow copy): modifying one node
|
|---|
| 3280 | will also change the other. If you want to make a deep copy, use
|
|---|
| 3281 | cloneNode().
|
|---|
| 3282 | */
|
|---|
| 3283 | QDomDocumentFragment::QDomDocumentFragment( const QDomDocumentFragment& x )
|
|---|
| 3284 | : QDomNode( x )
|
|---|
| 3285 | {
|
|---|
| 3286 | }
|
|---|
| 3287 |
|
|---|
| 3288 | /*!
|
|---|
| 3289 | Assigns \a x to this DOM document fragment.
|
|---|
| 3290 |
|
|---|
| 3291 | The data of the copy is shared (shallow copy): modifying one node
|
|---|
| 3292 | will also change the other. If you want to make a deep copy, use
|
|---|
| 3293 | cloneNode().
|
|---|
| 3294 | */
|
|---|
| 3295 | QDomDocumentFragment& QDomDocumentFragment::operator= ( const QDomDocumentFragment& x )
|
|---|
| 3296 | {
|
|---|
| 3297 | return (QDomDocumentFragment&) QDomNode::operator=( x );
|
|---|
| 3298 | }
|
|---|
| 3299 |
|
|---|
| 3300 | /*!
|
|---|
| 3301 | Destroys the object and frees its resources.
|
|---|
| 3302 | */
|
|---|
| 3303 | QDomDocumentFragment::~QDomDocumentFragment()
|
|---|
| 3304 | {
|
|---|
| 3305 | }
|
|---|
| 3306 |
|
|---|
| 3307 | /*!
|
|---|
| 3308 | Returns \c DocumentFragment.
|
|---|
| 3309 |
|
|---|
| 3310 | \sa isDocumentFragment() QDomNode::toDocumentFragment()
|
|---|
| 3311 | */
|
|---|
| 3312 | QDomNode::NodeType QDomDocumentFragment::nodeType() const
|
|---|
| 3313 | {
|
|---|
| 3314 | return QDomNode::DocumentFragmentNode;
|
|---|
| 3315 | }
|
|---|
| 3316 |
|
|---|
| 3317 | /*!
|
|---|
| 3318 | This function reimplements QDomNode::isDocumentFragment().
|
|---|
| 3319 |
|
|---|
| 3320 | \sa nodeType() QDomNode::toDocumentFragment()
|
|---|
| 3321 | */
|
|---|
| 3322 | bool QDomDocumentFragment::isDocumentFragment() const
|
|---|
| 3323 | {
|
|---|
| 3324 | return TRUE;
|
|---|
| 3325 | }
|
|---|
| 3326 |
|
|---|
| 3327 | #undef IMPL
|
|---|
| 3328 |
|
|---|
| 3329 | /**************************************************************
|
|---|
| 3330 | *
|
|---|
| 3331 | * QDomCharacterDataPrivate
|
|---|
| 3332 | *
|
|---|
| 3333 | **************************************************************/
|
|---|
| 3334 |
|
|---|
| 3335 | QDomCharacterDataPrivate::QDomCharacterDataPrivate( QDomDocumentPrivate* d, QDomNodePrivate* p,
|
|---|
| 3336 | const QString& data )
|
|---|
| 3337 | : QDomNodePrivate( d, p )
|
|---|
| 3338 | {
|
|---|
| 3339 | value = data;
|
|---|
| 3340 |
|
|---|
| 3341 | name = "#character-data";
|
|---|
| 3342 | }
|
|---|
| 3343 |
|
|---|
| 3344 | QDomCharacterDataPrivate::QDomCharacterDataPrivate( QDomCharacterDataPrivate* n, bool deep )
|
|---|
| 3345 | : QDomNodePrivate( n, deep )
|
|---|
| 3346 | {
|
|---|
| 3347 | }
|
|---|
| 3348 |
|
|---|
| 3349 | QDomCharacterDataPrivate::~QDomCharacterDataPrivate()
|
|---|
| 3350 | {
|
|---|
| 3351 | }
|
|---|
| 3352 |
|
|---|
| 3353 | QDomNodePrivate* QDomCharacterDataPrivate::cloneNode( bool deep )
|
|---|
| 3354 | {
|
|---|
| 3355 | QDomNodePrivate* p = new QDomCharacterDataPrivate( this, deep );
|
|---|
| 3356 | // We are not interested in this node
|
|---|
| 3357 | p->deref();
|
|---|
| 3358 | return p;
|
|---|
| 3359 | }
|
|---|
| 3360 |
|
|---|
| 3361 | uint QDomCharacterDataPrivate::dataLength() const
|
|---|
| 3362 | {
|
|---|
| 3363 | return value.length();
|
|---|
| 3364 | }
|
|---|
| 3365 |
|
|---|
| 3366 | QString QDomCharacterDataPrivate::substringData( unsigned long offset, unsigned long n ) const
|
|---|
| 3367 | {
|
|---|
| 3368 | return value.mid( offset, n );
|
|---|
| 3369 | }
|
|---|
| 3370 |
|
|---|
| 3371 | void QDomCharacterDataPrivate::insertData( unsigned long offset, const QString& arg )
|
|---|
| 3372 | {
|
|---|
| 3373 | value.insert( offset, arg );
|
|---|
| 3374 | }
|
|---|
| 3375 |
|
|---|
| 3376 | void QDomCharacterDataPrivate::deleteData( unsigned long offset, unsigned long n )
|
|---|
| 3377 | {
|
|---|
| 3378 | value.remove( offset, n );
|
|---|
| 3379 | }
|
|---|
| 3380 |
|
|---|
| 3381 | void QDomCharacterDataPrivate::replaceData( unsigned long offset, unsigned long n, const QString& arg )
|
|---|
| 3382 | {
|
|---|
| 3383 | value.replace( offset, n, arg );
|
|---|
| 3384 | }
|
|---|
| 3385 |
|
|---|
| 3386 | void QDomCharacterDataPrivate::appendData( const QString& arg )
|
|---|
| 3387 | {
|
|---|
| 3388 | value += arg;
|
|---|
| 3389 | }
|
|---|
| 3390 |
|
|---|
| 3391 | /**************************************************************
|
|---|
| 3392 | *
|
|---|
| 3393 | * QDomCharacterData
|
|---|
| 3394 | *
|
|---|
| 3395 | **************************************************************/
|
|---|
| 3396 |
|
|---|
| 3397 | #define IMPL ((QDomCharacterDataPrivate*)impl)
|
|---|
| 3398 |
|
|---|
| 3399 | /*!
|
|---|
| 3400 | \class QDomCharacterData qdom.h
|
|---|
| 3401 | \reentrant
|
|---|
| 3402 | \brief The QDomCharacterData class represents a generic string in the DOM.
|
|---|
| 3403 | \if defined(commercial)
|
|---|
| 3404 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
|---|
| 3405 | \endif
|
|---|
| 3406 |
|
|---|
| 3407 | \module XML
|
|---|
| 3408 | \ingroup xml-tools
|
|---|
| 3409 |
|
|---|
| 3410 | Character data as used in XML specifies a generic data string.
|
|---|
| 3411 | More specialized versions of this class are QDomText, QDomComment
|
|---|
| 3412 | and QDomCDATASection.
|
|---|
| 3413 |
|
|---|
| 3414 | The data string is set with setData() and retrieved with data().
|
|---|
| 3415 | You can retrieve a portion of the data string using
|
|---|
| 3416 | substringData(). Extra data can be appended with appendData(), or
|
|---|
| 3417 | inserted with insertData(). Portions of the data string can be
|
|---|
| 3418 | deleted with deleteData() or replaced with replaceData(). The
|
|---|
| 3419 | length of the data string is returned by length().
|
|---|
| 3420 |
|
|---|
| 3421 | The node type of the node containing this character data is
|
|---|
| 3422 | returned by nodeType().
|
|---|
| 3423 |
|
|---|
| 3424 | \sa QDomText QDomComment QDomCDATASection
|
|---|
| 3425 | */
|
|---|
| 3426 |
|
|---|
| 3427 | /*!
|
|---|
| 3428 | Constructs an empty character data object.
|
|---|
| 3429 | */
|
|---|
| 3430 | QDomCharacterData::QDomCharacterData()
|
|---|
| 3431 | {
|
|---|
| 3432 | }
|
|---|
| 3433 |
|
|---|
| 3434 | /*!
|
|---|
| 3435 | Constructs a copy of \a x.
|
|---|
| 3436 |
|
|---|
| 3437 | The data of the copy is shared (shallow copy): modifying one node
|
|---|
| 3438 | will also change the other. If you want to make a deep copy, use
|
|---|
| 3439 | cloneNode().
|
|---|
| 3440 | */
|
|---|
| 3441 | QDomCharacterData::QDomCharacterData( const QDomCharacterData& x )
|
|---|
| 3442 | : QDomNode( x )
|
|---|
| 3443 | {
|
|---|
| 3444 | }
|
|---|
| 3445 |
|
|---|
| 3446 | QDomCharacterData::QDomCharacterData( QDomCharacterDataPrivate* n )
|
|---|
| 3447 | : QDomNode( n )
|
|---|
| 3448 | {
|
|---|
| 3449 | }
|
|---|
| 3450 |
|
|---|
| 3451 | /*!
|
|---|
| 3452 | Assigns \a x to this character data.
|
|---|
| 3453 |
|
|---|
| 3454 | The data of the copy is shared (shallow copy): modifying one node
|
|---|
| 3455 | will also change the other. If you want to make a deep copy, use
|
|---|
| 3456 | cloneNode().
|
|---|
| 3457 | */
|
|---|
| 3458 | QDomCharacterData& QDomCharacterData::operator= ( const QDomCharacterData& x )
|
|---|
| 3459 | {
|
|---|
| 3460 | return (QDomCharacterData&) QDomNode::operator=( x );
|
|---|
| 3461 | }
|
|---|
| 3462 |
|
|---|
| 3463 | /*!
|
|---|
| 3464 | Destroys the object and frees its resources.
|
|---|
| 3465 | */
|
|---|
| 3466 | QDomCharacterData::~QDomCharacterData()
|
|---|
| 3467 | {
|
|---|
| 3468 | }
|
|---|
| 3469 |
|
|---|
| 3470 | /*!
|
|---|
| 3471 | Returns the string stored in this object.
|
|---|
| 3472 |
|
|---|
| 3473 | If the node is a \link isNull() null node\endlink, it will return
|
|---|
| 3474 | QString::null.
|
|---|
| 3475 | */
|
|---|
| 3476 | QString QDomCharacterData::data() const
|
|---|
| 3477 | {
|
|---|
| 3478 | if ( !impl )
|
|---|
| 3479 | return QString::null;
|
|---|
| 3480 | return impl->nodeValue();
|
|---|
| 3481 | }
|
|---|
| 3482 |
|
|---|
| 3483 | /*!
|
|---|
| 3484 | Sets this object's string to \a v.
|
|---|
| 3485 | */
|
|---|
| 3486 | void QDomCharacterData::setData( const QString& v )
|
|---|
| 3487 | {
|
|---|
| 3488 | if ( impl )
|
|---|
| 3489 | impl->setNodeValue( v );
|
|---|
| 3490 | }
|
|---|
| 3491 |
|
|---|
| 3492 | /*!
|
|---|
| 3493 | Returns the length of the stored string.
|
|---|
| 3494 | */
|
|---|
| 3495 | uint QDomCharacterData::length() const
|
|---|
| 3496 | {
|
|---|
| 3497 | if ( impl )
|
|---|
| 3498 | return IMPL->dataLength();
|
|---|
| 3499 | return 0;
|
|---|
| 3500 | }
|
|---|
| 3501 |
|
|---|
| 3502 | /*!
|
|---|
| 3503 | Returns the substring of length \a count from position \a offset.
|
|---|
| 3504 | */
|
|---|
| 3505 | QString QDomCharacterData::substringData( unsigned long offset, unsigned long count )
|
|---|
| 3506 | {
|
|---|
| 3507 | if ( !impl )
|
|---|
| 3508 | return QString::null;
|
|---|
| 3509 | return IMPL->substringData( offset, count );
|
|---|
| 3510 | }
|
|---|
| 3511 |
|
|---|
| 3512 | /*!
|
|---|
| 3513 | Appends the string \a arg to the stored string.
|
|---|
| 3514 | */
|
|---|
| 3515 | void QDomCharacterData::appendData( const QString& arg )
|
|---|
| 3516 | {
|
|---|
| 3517 | if ( impl )
|
|---|
| 3518 | IMPL->appendData( arg );
|
|---|
| 3519 | }
|
|---|
| 3520 |
|
|---|
| 3521 | /*!
|
|---|
| 3522 | Inserts the string \a arg into the stored string at position \a offset.
|
|---|
| 3523 | */
|
|---|
| 3524 | void QDomCharacterData::insertData( unsigned long offset, const QString& arg )
|
|---|
| 3525 | {
|
|---|
| 3526 | if ( impl )
|
|---|
| 3527 | IMPL->insertData( offset, arg );
|
|---|
| 3528 | }
|
|---|
| 3529 |
|
|---|
| 3530 | /*!
|
|---|
| 3531 | Deletes a substring of length \a count from position \a offset.
|
|---|
| 3532 | */
|
|---|
| 3533 | void QDomCharacterData::deleteData( unsigned long offset, unsigned long count )
|
|---|
| 3534 | {
|
|---|
| 3535 | if ( impl )
|
|---|
| 3536 | IMPL->deleteData( offset, count );
|
|---|
| 3537 | }
|
|---|
| 3538 |
|
|---|
| 3539 | /*!
|
|---|
| 3540 | Replaces the substring of length \a count starting at position \a
|
|---|
| 3541 | offset with the string \a arg.
|
|---|
| 3542 | */
|
|---|
| 3543 | void QDomCharacterData::replaceData( unsigned long offset, unsigned long count, const QString& arg )
|
|---|
| 3544 | {
|
|---|
| 3545 | if ( impl )
|
|---|
| 3546 | IMPL->replaceData( offset, count, arg );
|
|---|
| 3547 | }
|
|---|
| 3548 |
|
|---|
| 3549 | /*!
|
|---|
| 3550 | Returns the type of node this object refers to (i.e. \c TextNode,
|
|---|
| 3551 | \c CDATASectionNode, \c CommentNode or \c CharacterDataNode). For
|
|---|
| 3552 | a \link isNull() null node\endlink \c CharacterDataNode is
|
|---|
| 3553 | returned.
|
|---|
| 3554 | */
|
|---|
| 3555 | QDomNode::NodeType QDomCharacterData::nodeType() const
|
|---|
| 3556 | {
|
|---|
| 3557 | if( !impl )
|
|---|
| 3558 | return CharacterDataNode;
|
|---|
| 3559 | return QDomNode::nodeType();
|
|---|
| 3560 | }
|
|---|
| 3561 |
|
|---|
| 3562 | /*!
|
|---|
| 3563 | Returns TRUE.
|
|---|
| 3564 | */
|
|---|
| 3565 | bool QDomCharacterData::isCharacterData() const
|
|---|
| 3566 | {
|
|---|
| 3567 | return TRUE;
|
|---|
| 3568 | }
|
|---|
| 3569 |
|
|---|
| 3570 | #undef IMPL
|
|---|
| 3571 |
|
|---|
| 3572 | /**************************************************************
|
|---|
| 3573 | *
|
|---|
| 3574 | * QDomAttrPrivate
|
|---|
| 3575 | *
|
|---|
| 3576 | **************************************************************/
|
|---|
| 3577 |
|
|---|
| 3578 | QDomAttrPrivate::QDomAttrPrivate( QDomDocumentPrivate* d, QDomNodePrivate* parent, const QString& name_ )
|
|---|
| 3579 | : QDomNodePrivate( d, parent )
|
|---|
| 3580 | {
|
|---|
| 3581 | name = name_;
|
|---|
| 3582 | m_specified = FALSE;
|
|---|
| 3583 | }
|
|---|
| 3584 |
|
|---|
| 3585 | QDomAttrPrivate::QDomAttrPrivate( QDomDocumentPrivate* d, QDomNodePrivate* p, const QString& nsURI, const QString& qName )
|
|---|
| 3586 | : QDomNodePrivate( d, p )
|
|---|
| 3587 | {
|
|---|
| 3588 | qt_split_namespace( prefix, name, qName, !nsURI.isNull() );
|
|---|
| 3589 | namespaceURI = nsURI;
|
|---|
| 3590 | createdWithDom1Interface = FALSE;
|
|---|
| 3591 | m_specified = FALSE;
|
|---|
| 3592 | }
|
|---|
| 3593 |
|
|---|
| 3594 | QDomAttrPrivate::QDomAttrPrivate( QDomAttrPrivate* n, bool deep )
|
|---|
| 3595 | : QDomNodePrivate( n, deep )
|
|---|
| 3596 | {
|
|---|
| 3597 | m_specified = n->specified();
|
|---|
| 3598 | }
|
|---|
| 3599 |
|
|---|
| 3600 | QDomAttrPrivate::~QDomAttrPrivate()
|
|---|
| 3601 | {
|
|---|
| 3602 | }
|
|---|
| 3603 |
|
|---|
| 3604 | void QDomAttrPrivate::setNodeValue( const QString& v )
|
|---|
| 3605 | {
|
|---|
| 3606 | value = v;
|
|---|
| 3607 | QDomTextPrivate *t = new QDomTextPrivate( 0, this, v );
|
|---|
| 3608 | // keep the refcount balanced: appendChild() does a ref() anyway.
|
|---|
| 3609 | t->deref();
|
|---|
| 3610 | if ( first ) {
|
|---|
| 3611 | delete removeChild( first );
|
|---|
| 3612 | }
|
|---|
| 3613 | appendChild( t );
|
|---|
| 3614 | }
|
|---|
| 3615 |
|
|---|
| 3616 | QDomNodePrivate* QDomAttrPrivate::cloneNode( bool deep )
|
|---|
| 3617 | {
|
|---|
| 3618 | QDomNodePrivate* p = new QDomAttrPrivate( this, deep );
|
|---|
| 3619 | // We are not interested in this node
|
|---|
| 3620 | p->deref();
|
|---|
| 3621 | return p;
|
|---|
| 3622 | }
|
|---|
| 3623 |
|
|---|
| 3624 | bool QDomAttrPrivate::specified() const
|
|---|
| 3625 | {
|
|---|
| 3626 | return m_specified;
|
|---|
| 3627 | }
|
|---|
| 3628 |
|
|---|
| 3629 | /*
|
|---|
| 3630 | Encode an attribute value upon saving.
|
|---|
| 3631 | */
|
|---|
| 3632 | static QString encodeAttr( const QString& str )
|
|---|
| 3633 | {
|
|---|
| 3634 | QString tmp( str );
|
|---|
| 3635 | uint len = tmp.length();
|
|---|
| 3636 | uint i = 0;
|
|---|
| 3637 | while ( i < len ) {
|
|---|
| 3638 | if ( tmp[(int)i] == '<' ) {
|
|---|
| 3639 | tmp.replace( i, 1, "<" );
|
|---|
| 3640 | len += 3;
|
|---|
| 3641 | i += 4;
|
|---|
| 3642 | } else if ( tmp[(int)i] == '"' ) {
|
|---|
| 3643 | tmp.replace( i, 1, """ );
|
|---|
| 3644 | len += 5;
|
|---|
| 3645 | i += 6;
|
|---|
| 3646 | } else if ( tmp[(int)i] == '&' ) {
|
|---|
| 3647 | tmp.replace( i, 1, "&" );
|
|---|
| 3648 | len += 4;
|
|---|
| 3649 | i += 5;
|
|---|
| 3650 | } else if ( tmp[(int)i] == '>' && i>=2 && tmp[(int)i-1]==']' && tmp[(int)i-2]==']' ) {
|
|---|
| 3651 | tmp.replace( i, 1, ">" );
|
|---|
| 3652 | len += 3;
|
|---|
| 3653 | i += 4;
|
|---|
| 3654 | } else {
|
|---|
| 3655 | ++i;
|
|---|
| 3656 | }
|
|---|
| 3657 | }
|
|---|
| 3658 |
|
|---|
| 3659 | return tmp;
|
|---|
| 3660 | }
|
|---|
| 3661 |
|
|---|
| 3662 | void QDomAttrPrivate::save( QTextStream& s, int, int ) const
|
|---|
| 3663 | {
|
|---|
| 3664 | if ( namespaceURI.isNull() ) {
|
|---|
| 3665 | s << name << "=\"" << encodeAttr( value ) << "\"";
|
|---|
| 3666 | } else {
|
|---|
| 3667 | // ### optimize this (see comment of QDomElementPrivate::save()
|
|---|
| 3668 | s << prefix << ":" << name << "=\"" << encodeAttr( value ) << "\""
|
|---|
| 3669 | << " xmlns:" << prefix << "=\"" << encodeAttr( namespaceURI ) << "\"";
|
|---|
| 3670 | }
|
|---|
| 3671 | }
|
|---|
| 3672 |
|
|---|
| 3673 | /**************************************************************
|
|---|
| 3674 | *
|
|---|
| 3675 | * QDomAttr
|
|---|
| 3676 | *
|
|---|
| 3677 | **************************************************************/
|
|---|
| 3678 |
|
|---|
| 3679 | #define IMPL ((QDomAttrPrivate*)impl)
|
|---|
| 3680 |
|
|---|
| 3681 | /*!
|
|---|
| 3682 | \class QDomAttr qdom.h
|
|---|
| 3683 | \reentrant
|
|---|
| 3684 | \brief The QDomAttr class represents one attribute of a QDomElement.
|
|---|
| 3685 | \if defined(commercial)
|
|---|
| 3686 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
|---|
| 3687 | \endif
|
|---|
| 3688 |
|
|---|
| 3689 | \module XML
|
|---|
| 3690 | \ingroup xml-tools
|
|---|
| 3691 |
|
|---|
| 3692 | For example, the following piece of XML produces an element with
|
|---|
| 3693 | no children, but two attributes:
|
|---|
| 3694 |
|
|---|
| 3695 | \code
|
|---|
| 3696 | <link href="http://www.trolltech.com" color="red" />
|
|---|
| 3697 | \endcode
|
|---|
| 3698 |
|
|---|
| 3699 | You can access the attributes of an element with code like this:
|
|---|
| 3700 |
|
|---|
| 3701 | \code
|
|---|
| 3702 | QDomElement e = //...
|
|---|
| 3703 | //...
|
|---|
| 3704 | QDomAttr a = e.attributeNode( "href" );
|
|---|
| 3705 | cout << a.value() << endl; // prints "http://www.trolltech.com"
|
|---|
| 3706 | a.setValue( "http://doc.trolltech.com" ); // change the node's attribute
|
|---|
| 3707 | QDomAttr a2 = e.attributeNode( "href" );
|
|---|
| 3708 | cout << a2.value() << endl; // prints "http://doc.trolltech.com"
|
|---|
| 3709 | \endcode
|
|---|
| 3710 |
|
|---|
| 3711 | This example also shows that changing an attribute received from
|
|---|
| 3712 | an element changes the attribute of the element. If you do not
|
|---|
| 3713 | want to change the value of the element's attribute you must
|
|---|
| 3714 | use cloneNode() to get an independent copy of the attribute.
|
|---|
| 3715 |
|
|---|
| 3716 | QDomAttr can return the name() and value() of an attribute. An
|
|---|
| 3717 | attribute's value is set with setValue(). If specified() returns
|
|---|
| 3718 | TRUE the value was either set in the document or set with
|
|---|
| 3719 | setValue(); otherwise the value hasn't been set. The node this
|
|---|
| 3720 | attribute is attached to (if any) is returned by ownerElement().
|
|---|
| 3721 |
|
|---|
| 3722 | For further information about the Document Object Model see
|
|---|
| 3723 | \link http://www.w3.org/TR/REC-DOM-Level-1/\endlink and
|
|---|
| 3724 | \link http://www.w3.org/TR/DOM-Level-2-Core/\endlink.
|
|---|
| 3725 | For a more general introduction of the DOM implementation see the
|
|---|
| 3726 | QDomDocument documentation.
|
|---|
| 3727 | */
|
|---|
| 3728 |
|
|---|
| 3729 |
|
|---|
| 3730 | /*!
|
|---|
| 3731 | Constructs an empty attribute.
|
|---|
| 3732 | */
|
|---|
| 3733 | QDomAttr::QDomAttr()
|
|---|
| 3734 | {
|
|---|
| 3735 | }
|
|---|
| 3736 |
|
|---|
| 3737 | /*!
|
|---|
| 3738 | Constructs a copy of \a x.
|
|---|
| 3739 |
|
|---|
| 3740 | The data of the copy is shared (shallow copy): modifying one node
|
|---|
| 3741 | will also change the other. If you want to make a deep copy, use
|
|---|
| 3742 | cloneNode().
|
|---|
| 3743 | */
|
|---|
| 3744 | QDomAttr::QDomAttr( const QDomAttr& x )
|
|---|
| 3745 | : QDomNode( x )
|
|---|
| 3746 | {
|
|---|
| 3747 | }
|
|---|
| 3748 |
|
|---|
| 3749 | QDomAttr::QDomAttr( QDomAttrPrivate* n )
|
|---|
| 3750 | : QDomNode( n )
|
|---|
| 3751 | {
|
|---|
| 3752 | }
|
|---|
| 3753 |
|
|---|
| 3754 | /*!
|
|---|
| 3755 | Assigns \a x to this DOM attribute.
|
|---|
| 3756 |
|
|---|
| 3757 | The data of the copy is shared (shallow copy): modifying one node
|
|---|
| 3758 | will also change the other. If you want to make a deep copy, use
|
|---|
| 3759 | cloneNode().
|
|---|
| 3760 | */
|
|---|
| 3761 | QDomAttr& QDomAttr::operator= ( const QDomAttr& x )
|
|---|
| 3762 | {
|
|---|
| 3763 | return (QDomAttr&) QDomNode::operator=( x );
|
|---|
| 3764 | }
|
|---|
| 3765 |
|
|---|
| 3766 | /*!
|
|---|
| 3767 | Destroys the object and frees its resources.
|
|---|
| 3768 | */
|
|---|
| 3769 | QDomAttr::~QDomAttr()
|
|---|
| 3770 | {
|
|---|
| 3771 | }
|
|---|
| 3772 |
|
|---|
| 3773 | /*!
|
|---|
| 3774 | Returns the attribute's name.
|
|---|
| 3775 | */
|
|---|
| 3776 | QString QDomAttr::name() const
|
|---|
| 3777 | {
|
|---|
| 3778 | if ( !impl )
|
|---|
| 3779 | return QString::null;
|
|---|
| 3780 | return impl->nodeName();
|
|---|
| 3781 | }
|
|---|
| 3782 |
|
|---|
| 3783 | /*!
|
|---|
| 3784 | Returns TRUE if the attribute has either been expicitly specified
|
|---|
| 3785 | in the XML document or was set by the user with setValue().
|
|---|
| 3786 | Returns FALSE if the value hasn't been specified or set.
|
|---|
| 3787 |
|
|---|
| 3788 | \sa setValue()
|
|---|
| 3789 | */
|
|---|
| 3790 | bool QDomAttr::specified() const
|
|---|
| 3791 | {
|
|---|
| 3792 | if ( !impl )
|
|---|
| 3793 | return FALSE;
|
|---|
| 3794 | return IMPL->specified();
|
|---|
| 3795 | }
|
|---|
| 3796 |
|
|---|
| 3797 | /*!
|
|---|
| 3798 | Returns the element node this attribute is attached to or a \link
|
|---|
| 3799 | QDomNode::isNull() null node\endlink if this attribute is not
|
|---|
| 3800 | attached to any element.
|
|---|
| 3801 | */
|
|---|
| 3802 | QDomElement QDomAttr::ownerElement() const
|
|---|
| 3803 | {
|
|---|
| 3804 | if ( !impl && !impl->parent()->isElement() )
|
|---|
| 3805 | return QDomElement();
|
|---|
| 3806 | return QDomElement( (QDomElementPrivate*)(impl->parent()) );
|
|---|
| 3807 | }
|
|---|
| 3808 |
|
|---|
| 3809 | /*!
|
|---|
| 3810 | Returns the value of the attribute or QString::null if the
|
|---|
| 3811 | attribute has not been specified.
|
|---|
| 3812 |
|
|---|
| 3813 | \sa specified() setValue()
|
|---|
| 3814 | */
|
|---|
| 3815 | QString QDomAttr::value() const
|
|---|
| 3816 | {
|
|---|
| 3817 | if ( !impl )
|
|---|
| 3818 | return QString::null;
|
|---|
| 3819 | return impl->nodeValue();
|
|---|
| 3820 | }
|
|---|
| 3821 |
|
|---|
| 3822 | /*!
|
|---|
| 3823 | Sets the attribute's value to \a v.
|
|---|
| 3824 |
|
|---|
| 3825 | \sa value()
|
|---|
| 3826 | */
|
|---|
| 3827 | void QDomAttr::setValue( const QString& v )
|
|---|
| 3828 | {
|
|---|
| 3829 | if ( !impl )
|
|---|
| 3830 | return;
|
|---|
| 3831 | impl->setNodeValue( v );
|
|---|
| 3832 | IMPL->m_specified = TRUE;
|
|---|
| 3833 | }
|
|---|
| 3834 |
|
|---|
| 3835 | /*!
|
|---|
| 3836 | Returns \link QDomNode::NodeType AttributeNode\endlink.
|
|---|
| 3837 | */
|
|---|
| 3838 | QDomNode::NodeType QDomAttr::nodeType() const
|
|---|
| 3839 | {
|
|---|
| 3840 | return AttributeNode;
|
|---|
| 3841 | }
|
|---|
| 3842 |
|
|---|
| 3843 | /*!
|
|---|
| 3844 | Returns TRUE.
|
|---|
| 3845 | */
|
|---|
| 3846 | bool QDomAttr::isAttr() const
|
|---|
| 3847 | {
|
|---|
| 3848 | return TRUE;
|
|---|
| 3849 | }
|
|---|
| 3850 |
|
|---|
| 3851 | #undef IMPL
|
|---|
| 3852 |
|
|---|
| 3853 | /**************************************************************
|
|---|
| 3854 | *
|
|---|
| 3855 | * QDomElementPrivate
|
|---|
| 3856 | *
|
|---|
| 3857 | **************************************************************/
|
|---|
| 3858 |
|
|---|
| 3859 | QDomElementPrivate::QDomElementPrivate( QDomDocumentPrivate* d, QDomNodePrivate* p,
|
|---|
| 3860 | const QString& tagname )
|
|---|
| 3861 | : QDomNodePrivate( d, p )
|
|---|
| 3862 | {
|
|---|
| 3863 | name = tagname;
|
|---|
| 3864 | m_attr = new QDomNamedNodeMapPrivate( this );
|
|---|
| 3865 | }
|
|---|
| 3866 |
|
|---|
| 3867 | QDomElementPrivate::QDomElementPrivate( QDomDocumentPrivate* d, QDomNodePrivate* p,
|
|---|
| 3868 | const QString& nsURI, const QString& qName )
|
|---|
| 3869 | : QDomNodePrivate( d, p )
|
|---|
| 3870 | {
|
|---|
| 3871 | qt_split_namespace( prefix, name, qName, !nsURI.isNull() );
|
|---|
| 3872 | namespaceURI = nsURI;
|
|---|
| 3873 | createdWithDom1Interface = FALSE;
|
|---|
| 3874 | m_attr = new QDomNamedNodeMapPrivate( this );
|
|---|
| 3875 | }
|
|---|
| 3876 |
|
|---|
| 3877 | QDomElementPrivate::QDomElementPrivate( QDomElementPrivate* n, bool deep ) :
|
|---|
| 3878 | QDomNodePrivate( n, deep )
|
|---|
| 3879 | {
|
|---|
| 3880 | m_attr = n->m_attr->clone( this );
|
|---|
| 3881 | // Reference is down to 0, so we set it to 1 here.
|
|---|
| 3882 | m_attr->ref();
|
|---|
| 3883 | }
|
|---|
| 3884 |
|
|---|
| 3885 | QDomElementPrivate::~QDomElementPrivate()
|
|---|
| 3886 | {
|
|---|
| 3887 | if ( m_attr->deref() )
|
|---|
| 3888 | delete m_attr;
|
|---|
| 3889 | }
|
|---|
| 3890 |
|
|---|
| 3891 | QDomNodePrivate* QDomElementPrivate::cloneNode( bool deep)
|
|---|
| 3892 | {
|
|---|
| 3893 | QDomNodePrivate* p = new QDomElementPrivate( this, deep );
|
|---|
| 3894 | // We are not interested in this node
|
|---|
| 3895 | p->deref();
|
|---|
| 3896 | return p;
|
|---|
| 3897 | }
|
|---|
| 3898 |
|
|---|
| 3899 | QString QDomElementPrivate::attribute( const QString& name_, const QString& defValue ) const
|
|---|
| 3900 | {
|
|---|
| 3901 | QDomNodePrivate* n = m_attr->namedItem( name_ );
|
|---|
| 3902 | if ( !n )
|
|---|
| 3903 | return defValue;
|
|---|
| 3904 |
|
|---|
| 3905 | return n->nodeValue();
|
|---|
| 3906 | }
|
|---|
| 3907 |
|
|---|
| 3908 | QString QDomElementPrivate::attributeNS( const QString& nsURI, const QString& localName, const QString& defValue ) const
|
|---|
| 3909 | {
|
|---|
| 3910 | QDomNodePrivate* n = m_attr->namedItemNS( nsURI, localName );
|
|---|
| 3911 | if ( !n )
|
|---|
| 3912 | return defValue;
|
|---|
| 3913 |
|
|---|
| 3914 | return n->nodeValue();
|
|---|
| 3915 | }
|
|---|
| 3916 |
|
|---|
| 3917 | void QDomElementPrivate::setAttribute( const QString& aname, const QString& newValue )
|
|---|
| 3918 | {
|
|---|
| 3919 | QDomNodePrivate* n = m_attr->namedItem( aname );
|
|---|
| 3920 | if ( !n ) {
|
|---|
| 3921 | n = new QDomAttrPrivate( ownerDocument(), this, aname );
|
|---|
| 3922 | n->setNodeValue( newValue );
|
|---|
| 3923 |
|
|---|
| 3924 | // Referencing is done by the map, so we set the reference counter back
|
|---|
| 3925 | // to 0 here. This is ok since we created the QDomAttrPrivate.
|
|---|
| 3926 | n->deref();
|
|---|
| 3927 | m_attr->setNamedItem( n );
|
|---|
| 3928 | } else {
|
|---|
| 3929 | n->setNodeValue( newValue );
|
|---|
| 3930 | }
|
|---|
| 3931 | }
|
|---|
| 3932 |
|
|---|
| 3933 | void QDomElementPrivate::setAttributeNS( const QString& nsURI, const QString& qName, const QString& newValue )
|
|---|
| 3934 | {
|
|---|
| 3935 | QString prefix, localName;
|
|---|
| 3936 | qt_split_namespace( prefix, localName, qName, TRUE );
|
|---|
| 3937 | QDomNodePrivate* n = m_attr->namedItemNS( nsURI, localName );
|
|---|
| 3938 | if ( !n ) {
|
|---|
| 3939 | n = new QDomAttrPrivate( ownerDocument(), this, nsURI, qName );
|
|---|
| 3940 | n->setNodeValue( newValue );
|
|---|
| 3941 |
|
|---|
| 3942 | // Referencing is done by the map, so we set the reference counter back
|
|---|
| 3943 | // to 0 here. This is ok since we created the QDomAttrPrivate.
|
|---|
| 3944 | n->deref();
|
|---|
| 3945 | m_attr->setNamedItem( n );
|
|---|
| 3946 | } else {
|
|---|
| 3947 | n->setNodeValue( newValue );
|
|---|
| 3948 | n->prefix = prefix;
|
|---|
| 3949 | }
|
|---|
| 3950 | }
|
|---|
| 3951 |
|
|---|
| 3952 | void QDomElementPrivate::removeAttribute( const QString& aname )
|
|---|
| 3953 | {
|
|---|
| 3954 | QDomNodePrivate* p = m_attr->removeNamedItem( aname );
|
|---|
| 3955 | if ( p && p->count == 0 )
|
|---|
| 3956 | delete p;
|
|---|
| 3957 | }
|
|---|
| 3958 |
|
|---|
| 3959 | QDomAttrPrivate* QDomElementPrivate::attributeNode( const QString& aname )
|
|---|
| 3960 | {
|
|---|
| 3961 | return (QDomAttrPrivate*)m_attr->namedItem( aname );
|
|---|
| 3962 | }
|
|---|
| 3963 |
|
|---|
| 3964 | QDomAttrPrivate* QDomElementPrivate::attributeNodeNS( const QString& nsURI, const QString& localName )
|
|---|
| 3965 | {
|
|---|
| 3966 | return (QDomAttrPrivate*)m_attr->namedItemNS( nsURI, localName );
|
|---|
| 3967 | }
|
|---|
| 3968 |
|
|---|
| 3969 | QDomAttrPrivate* QDomElementPrivate::setAttributeNode( QDomAttrPrivate* newAttr )
|
|---|
| 3970 | {
|
|---|
| 3971 | QDomNodePrivate* n = m_attr->namedItem( newAttr->nodeName() );
|
|---|
| 3972 |
|
|---|
| 3973 | // Referencing is done by the maps
|
|---|
| 3974 | m_attr->setNamedItem( newAttr );
|
|---|
| 3975 |
|
|---|
| 3976 | return (QDomAttrPrivate*)n;
|
|---|
| 3977 | }
|
|---|
| 3978 |
|
|---|
| 3979 | QDomAttrPrivate* QDomElementPrivate::setAttributeNodeNS( QDomAttrPrivate* newAttr )
|
|---|
| 3980 | {
|
|---|
| 3981 | QDomNodePrivate* n = 0;
|
|---|
| 3982 | if ( !newAttr->prefix.isNull() )
|
|---|
| 3983 | n = m_attr->namedItemNS( newAttr->namespaceURI, newAttr->name );
|
|---|
| 3984 |
|
|---|
| 3985 | // Referencing is done by the maps
|
|---|
| 3986 | m_attr->setNamedItem( newAttr );
|
|---|
| 3987 |
|
|---|
| 3988 | return (QDomAttrPrivate*)n;
|
|---|
| 3989 | }
|
|---|
| 3990 |
|
|---|
| 3991 | QDomAttrPrivate* QDomElementPrivate::removeAttributeNode( QDomAttrPrivate* oldAttr )
|
|---|
| 3992 | {
|
|---|
| 3993 | return (QDomAttrPrivate*)m_attr->removeNamedItem( oldAttr->nodeName() );
|
|---|
| 3994 | }
|
|---|
| 3995 |
|
|---|
| 3996 | bool QDomElementPrivate::hasAttribute( const QString& aname )
|
|---|
| 3997 | {
|
|---|
| 3998 | return m_attr->contains( aname );
|
|---|
| 3999 | }
|
|---|
| 4000 |
|
|---|
| 4001 | bool QDomElementPrivate::hasAttributeNS( const QString& nsURI, const QString& localName )
|
|---|
| 4002 | {
|
|---|
| 4003 | return m_attr->containsNS( nsURI, localName );
|
|---|
| 4004 | }
|
|---|
| 4005 |
|
|---|
| 4006 | QString QDomElementPrivate::text()
|
|---|
| 4007 | {
|
|---|
| 4008 | QString t( "" );
|
|---|
| 4009 |
|
|---|
| 4010 | QDomNodePrivate* p = first;
|
|---|
| 4011 | while ( p ) {
|
|---|
| 4012 | if ( p->isText() || p->isCDATASection() )
|
|---|
| 4013 | t += p->nodeValue();
|
|---|
| 4014 | else if ( p->isElement() )
|
|---|
| 4015 | t += ((QDomElementPrivate*)p)->text();
|
|---|
| 4016 | p = p->next;
|
|---|
| 4017 | }
|
|---|
| 4018 |
|
|---|
| 4019 | return t;
|
|---|
| 4020 | }
|
|---|
| 4021 |
|
|---|
| 4022 | void QDomElementPrivate::save( QTextStream& s, int depth, int indent ) const
|
|---|
| 4023 | {
|
|---|
| 4024 | if ( !( prev && prev->isText() ) )
|
|---|
| 4025 | for ( int i = 0; i < depth*indent; ++i )
|
|---|
| 4026 | s << " ";
|
|---|
| 4027 |
|
|---|
| 4028 | QString qName( name );
|
|---|
| 4029 | QString nsDecl( "" );
|
|---|
| 4030 | if ( !namespaceURI.isNull() ) {
|
|---|
| 4031 | // ### optimize this, so that you only declare namespaces that are not
|
|---|
| 4032 | // yet declared -- we loose default namespace mappings, so maybe we
|
|---|
| 4033 | // should rather store the information that we get from
|
|---|
| 4034 | // startPrefixMapping()/endPrefixMapping() and use them (you have to
|
|---|
| 4035 | // take care if the DOM tree is modified, though)
|
|---|
| 4036 | if ( prefix.isEmpty() ) {
|
|---|
| 4037 | nsDecl = " xmlns";
|
|---|
| 4038 | } else {
|
|---|
| 4039 | qName = prefix + ":" + name;
|
|---|
| 4040 | nsDecl = " xmlns:" + prefix;
|
|---|
| 4041 | }
|
|---|
| 4042 | nsDecl += "=\"" + encodeAttr( namespaceURI ) + "\"";
|
|---|
| 4043 | }
|
|---|
| 4044 | s << "<" << qName << nsDecl;
|
|---|
| 4045 |
|
|---|
| 4046 | if ( !m_attr->map.isEmpty() ) {
|
|---|
| 4047 | s << " ";
|
|---|
| 4048 | QDictIterator<QDomNodePrivate> it( m_attr->map );
|
|---|
| 4049 | for ( ; it.current(); ++it ) {
|
|---|
| 4050 | it.current()->save( s, 0, indent );
|
|---|
| 4051 | s << " ";
|
|---|
| 4052 | }
|
|---|
| 4053 | }
|
|---|
| 4054 |
|
|---|
| 4055 | if ( last ) {
|
|---|
| 4056 | // has child nodes
|
|---|
| 4057 | if ( first->isText() )
|
|---|
| 4058 | s << ">";
|
|---|
| 4059 | else
|
|---|
| 4060 | s << ">" << endl;
|
|---|
| 4061 | QDomNodePrivate::save( s, depth + 1, indent);
|
|---|
| 4062 | if ( !last->isText() )
|
|---|
| 4063 | for( int i = 0; i < depth*indent; ++i )
|
|---|
| 4064 | s << " ";
|
|---|
| 4065 |
|
|---|
| 4066 | s << "</" << qName << ">";
|
|---|
| 4067 | } else {
|
|---|
| 4068 | s << "/>";
|
|---|
| 4069 | }
|
|---|
| 4070 | if ( !( next && next->isText() ) )
|
|---|
| 4071 | s << endl;
|
|---|
| 4072 | }
|
|---|
| 4073 |
|
|---|
| 4074 | /**************************************************************
|
|---|
| 4075 | *
|
|---|
| 4076 | * QDomElement
|
|---|
| 4077 | *
|
|---|
| 4078 | **************************************************************/
|
|---|
| 4079 |
|
|---|
| 4080 | #define IMPL ((QDomElementPrivate*)impl)
|
|---|
| 4081 |
|
|---|
| 4082 | /*!
|
|---|
| 4083 | \class QDomElement qdom.h
|
|---|
| 4084 | \reentrant
|
|---|
| 4085 | \brief The QDomElement class represents one element in the DOM tree.
|
|---|
| 4086 | \if defined(commercial)
|
|---|
| 4087 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
|---|
| 4088 | \endif
|
|---|
| 4089 |
|
|---|
| 4090 | \module XML
|
|---|
| 4091 | \ingroup xml-tools
|
|---|
| 4092 |
|
|---|
| 4093 | Elements have a tagName() and zero or more attributes associated
|
|---|
| 4094 | with them. The tag name can be changed with setTagName().
|
|---|
| 4095 |
|
|---|
| 4096 | Element attributes are represented by QDomAttr objects that can
|
|---|
| 4097 | be queried using the attribute() and attributeNode() functions.
|
|---|
| 4098 | You can set attributes with the setAttribute() and
|
|---|
| 4099 | setAttributeNode() functions. Attributes can be removed with
|
|---|
| 4100 | removeAttribute(). There are namespace-aware equivalents to these
|
|---|
| 4101 | functions, i.e. setAttributeNS(), setAttributeNodeNS() and
|
|---|
| 4102 | removeAttributeNS().
|
|---|
| 4103 |
|
|---|
| 4104 | If you want to access the text of a node use text(), e.g.
|
|---|
| 4105 | \code
|
|---|
| 4106 | QDomElement e = //...
|
|---|
| 4107 | //...
|
|---|
| 4108 | QString s = e.text()
|
|---|
| 4109 | \endcode
|
|---|
| 4110 | The text() function operates recursively to find the text (since
|
|---|
| 4111 | not all elements contain text). If you want to find all the text
|
|---|
| 4112 | in all of a node's children, iterate over the children looking for
|
|---|
| 4113 | QDomText nodes, e.g.
|
|---|
| 4114 | \code
|
|---|
| 4115 | QString text;
|
|---|
| 4116 | QDomElement element = doc.documentElement();
|
|---|
| 4117 | for( QDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling() )
|
|---|
| 4118 | {
|
|---|
| 4119 | QDomText t = n.toText();
|
|---|
| 4120 | if ( !t.isNull() )
|
|---|
| 4121 | text += t.data();
|
|---|
| 4122 | }
|
|---|
| 4123 | \endcode
|
|---|
| 4124 | Note that we attempt to convert each node to a text node and use
|
|---|
| 4125 | text() rather than using firstChild().toText().data() or
|
|---|
| 4126 | n.toText().data() directly on the node, because the node may not
|
|---|
| 4127 | be a text element.
|
|---|
| 4128 |
|
|---|
| 4129 | You can get a list of all the decendents of an element which have
|
|---|
| 4130 | a specified tag name with elementsByTagName() or
|
|---|
| 4131 | elementsByTagNameNS().
|
|---|
| 4132 |
|
|---|
| 4133 | For further information about the Document Object Model see
|
|---|
| 4134 | \link http://www.w3.org/TR/REC-DOM-Level-1/\endlink and
|
|---|
| 4135 | \link http://www.w3.org/TR/DOM-Level-2-Core/\endlink.
|
|---|
| 4136 | For a more general introduction of the DOM implementation see the
|
|---|
| 4137 | QDomDocument documentation.
|
|---|
| 4138 | */
|
|---|
| 4139 |
|
|---|
| 4140 | /*!
|
|---|
| 4141 | Constructs an empty element. Use the QDomDocument::createElement()
|
|---|
| 4142 | function to construct elements with content.
|
|---|
| 4143 | */
|
|---|
| 4144 | QDomElement::QDomElement()
|
|---|
| 4145 | : QDomNode()
|
|---|
| 4146 | {
|
|---|
| 4147 | }
|
|---|
| 4148 |
|
|---|
| 4149 | /*!
|
|---|
| 4150 | Constructs a copy of \a x.
|
|---|
| 4151 |
|
|---|
| 4152 | The data of the copy is shared (shallow copy): modifying one node
|
|---|
| 4153 | will also change the other. If you want to make a deep copy, use
|
|---|
| 4154 | cloneNode().
|
|---|
| 4155 | */
|
|---|
| 4156 | QDomElement::QDomElement( const QDomElement& x )
|
|---|
| 4157 | : QDomNode( x )
|
|---|
| 4158 | {
|
|---|
| 4159 | }
|
|---|
| 4160 |
|
|---|
| 4161 | QDomElement::QDomElement( QDomElementPrivate* n )
|
|---|
| 4162 | : QDomNode( n )
|
|---|
| 4163 | {
|
|---|
| 4164 | }
|
|---|
| 4165 |
|
|---|
| 4166 | /*!
|
|---|
| 4167 | Assigns \a x to this DOM element.
|
|---|
| 4168 |
|
|---|
| 4169 | The data of the copy is shared (shallow copy): modifying one node
|
|---|
| 4170 | will also change the other. If you want to make a deep copy, use
|
|---|
| 4171 | cloneNode().
|
|---|
| 4172 | */
|
|---|
| 4173 | QDomElement& QDomElement::operator= ( const QDomElement& x )
|
|---|
| 4174 | {
|
|---|
| 4175 | return (QDomElement&) QDomNode::operator=( x );
|
|---|
| 4176 | }
|
|---|
| 4177 |
|
|---|
| 4178 | /*!
|
|---|
| 4179 | Destroys the object and frees its resources.
|
|---|
| 4180 | */
|
|---|
| 4181 | QDomElement::~QDomElement()
|
|---|
| 4182 | {
|
|---|
| 4183 | }
|
|---|
| 4184 |
|
|---|
| 4185 | /*!
|
|---|
| 4186 | Returns \c ElementNode.
|
|---|
| 4187 | */
|
|---|
| 4188 | QDomNode::NodeType QDomElement::nodeType() const
|
|---|
| 4189 | {
|
|---|
| 4190 | return ElementNode;
|
|---|
| 4191 | }
|
|---|
| 4192 |
|
|---|
| 4193 | /*!
|
|---|
| 4194 | Sets this element's tag name to \a name.
|
|---|
| 4195 |
|
|---|
| 4196 | \sa tagName()
|
|---|
| 4197 | */
|
|---|
| 4198 | void QDomElement::setTagName( const QString& name )
|
|---|
| 4199 | {
|
|---|
| 4200 | if ( impl )
|
|---|
| 4201 | impl->name = name;
|
|---|
| 4202 | }
|
|---|
| 4203 |
|
|---|
| 4204 | /*!
|
|---|
| 4205 | Returns the tag name of this element. For an XML element like this:
|
|---|
| 4206 | \code
|
|---|
| 4207 | <img src="myimg.png">
|
|---|
| 4208 | \endcode
|
|---|
| 4209 | the tagname would return "img".
|
|---|
| 4210 |
|
|---|
| 4211 | \sa setTagName()
|
|---|
| 4212 | */
|
|---|
| 4213 | QString QDomElement::tagName() const
|
|---|
| 4214 | {
|
|---|
| 4215 | if ( !impl )
|
|---|
| 4216 | return QString::null;
|
|---|
| 4217 | return impl->nodeName();
|
|---|
| 4218 | }
|
|---|
| 4219 |
|
|---|
| 4220 | /*!
|
|---|
| 4221 | Returns the attribute called \a name. If the attribute does not
|
|---|
| 4222 | exist \a defValue is returned.
|
|---|
| 4223 |
|
|---|
| 4224 | \sa setAttribute() attributeNode() setAttributeNode() attributeNS()
|
|---|
| 4225 | */
|
|---|
| 4226 | QString QDomElement::attribute( const QString& name, const QString& defValue ) const
|
|---|
| 4227 | {
|
|---|
| 4228 | if ( !impl )
|
|---|
| 4229 | return defValue;
|
|---|
| 4230 | return IMPL->attribute( name, defValue );
|
|---|
| 4231 | }
|
|---|
| 4232 |
|
|---|
| 4233 | /*!
|
|---|
| 4234 | Adds an attribute called \a name with value \a value. If an
|
|---|
| 4235 | attribute with the same name exists, its value is replaced by \a
|
|---|
| 4236 | value.
|
|---|
| 4237 |
|
|---|
| 4238 | \sa attribute() setAttributeNode() setAttributeNS()
|
|---|
| 4239 | */
|
|---|
| 4240 | void QDomElement::setAttribute( const QString& name, const QString& value )
|
|---|
| 4241 | {
|
|---|
| 4242 | if ( !impl )
|
|---|
| 4243 | return;
|
|---|
| 4244 | IMPL->setAttribute( name, value );
|
|---|
| 4245 | }
|
|---|
| 4246 |
|
|---|
| 4247 | /*!
|
|---|
| 4248 | \overload
|
|---|
| 4249 | */
|
|---|
| 4250 | void QDomElement::setAttribute( const QString& name, int value )
|
|---|
| 4251 | {
|
|---|
| 4252 | // ### 4.0: inline
|
|---|
| 4253 | setAttribute( name, long(value) );
|
|---|
| 4254 | }
|
|---|
| 4255 |
|
|---|
| 4256 | /*!
|
|---|
| 4257 | \overload
|
|---|
| 4258 | */
|
|---|
| 4259 | void QDomElement::setAttribute( const QString& name, uint value )
|
|---|
| 4260 | {
|
|---|
| 4261 | // ### 4.0: inline
|
|---|
| 4262 | setAttribute( name, ulong(value) );
|
|---|
| 4263 | }
|
|---|
| 4264 |
|
|---|
| 4265 | /*!
|
|---|
| 4266 | \overload
|
|---|
| 4267 | */
|
|---|
| 4268 | void QDomElement::setAttribute( const QString& name, long value )
|
|---|
| 4269 | {
|
|---|
| 4270 | if ( !impl )
|
|---|
| 4271 | return;
|
|---|
| 4272 | QString x;
|
|---|
| 4273 | x.setNum( value );
|
|---|
| 4274 | IMPL->setAttribute( name, x );
|
|---|
| 4275 | }
|
|---|
| 4276 |
|
|---|
| 4277 | /*!
|
|---|
| 4278 | \overload
|
|---|
| 4279 | */
|
|---|
| 4280 | void QDomElement::setAttribute( const QString& name, ulong value )
|
|---|
| 4281 | {
|
|---|
| 4282 | if ( !impl )
|
|---|
| 4283 | return;
|
|---|
| 4284 | QString x;
|
|---|
| 4285 | x.setNum( value );
|
|---|
| 4286 | IMPL->setAttribute( name, x );
|
|---|
| 4287 | }
|
|---|
| 4288 |
|
|---|
| 4289 | /*!
|
|---|
| 4290 | \overload
|
|---|
| 4291 | */
|
|---|
| 4292 | void QDomElement::setAttribute( const QString& name, double value )
|
|---|
| 4293 | {
|
|---|
| 4294 | if ( !impl )
|
|---|
| 4295 | return;
|
|---|
| 4296 | QString x;
|
|---|
| 4297 | x.setNum( value );
|
|---|
| 4298 | IMPL->setAttribute( name, x );
|
|---|
| 4299 | }
|
|---|
| 4300 |
|
|---|
| 4301 | /*!
|
|---|
| 4302 | Removes the attribute called name \a name from this element.
|
|---|
| 4303 |
|
|---|
| 4304 | \sa setAttribute() attribute() removeAttributeNS()
|
|---|
| 4305 | */
|
|---|
| 4306 | void QDomElement::removeAttribute( const QString& name )
|
|---|
| 4307 | {
|
|---|
| 4308 | if ( !impl )
|
|---|
| 4309 | return;
|
|---|
| 4310 | IMPL->removeAttribute( name );
|
|---|
| 4311 | }
|
|---|
| 4312 |
|
|---|
| 4313 | /*!
|
|---|
| 4314 | Returns the QDomAttr object that corresponds to the attribute
|
|---|
| 4315 | called \a name. If no such attribute exists a \link
|
|---|
| 4316 | QDomNode::isNull() null attribute\endlink is returned.
|
|---|
| 4317 |
|
|---|
| 4318 | \sa setAttributeNode() attribute() setAttribute() attributeNodeNS()
|
|---|
| 4319 | */
|
|---|
| 4320 | QDomAttr QDomElement::attributeNode( const QString& name)
|
|---|
| 4321 | {
|
|---|
| 4322 | if ( !impl )
|
|---|
| 4323 | return QDomAttr();
|
|---|
| 4324 | return QDomAttr( IMPL->attributeNode( name ) );
|
|---|
| 4325 | }
|
|---|
| 4326 |
|
|---|
| 4327 | /*!
|
|---|
| 4328 | Adds the attribute \a newAttr to this element.
|
|---|
| 4329 |
|
|---|
| 4330 | If the element has another attribute that has the same name as \a
|
|---|
| 4331 | newAttr, this function replaces that attribute and returns it;
|
|---|
| 4332 | otherwise the function returns a \link QDomNode::isNull() null
|
|---|
| 4333 | attribute\endlink.
|
|---|
| 4334 |
|
|---|
| 4335 | \sa attributeNode() setAttribute() setAttributeNodeNS()
|
|---|
| 4336 | */
|
|---|
| 4337 | QDomAttr QDomElement::setAttributeNode( const QDomAttr& newAttr )
|
|---|
| 4338 | {
|
|---|
| 4339 | if ( !impl )
|
|---|
| 4340 | return QDomAttr();
|
|---|
| 4341 | return QDomAttr( IMPL->setAttributeNode( ((QDomAttrPrivate*)newAttr.impl) ) );
|
|---|
| 4342 | }
|
|---|
| 4343 |
|
|---|
| 4344 | /*!
|
|---|
| 4345 | Removes the attribute \a oldAttr from the element and returns it.
|
|---|
| 4346 |
|
|---|
| 4347 | \sa attributeNode() setAttributeNode()
|
|---|
| 4348 | */
|
|---|
| 4349 | QDomAttr QDomElement::removeAttributeNode( const QDomAttr& oldAttr )
|
|---|
| 4350 | {
|
|---|
| 4351 | if ( !impl )
|
|---|
| 4352 | return QDomAttr(); // ### should this return oldAttr?
|
|---|
| 4353 | return QDomAttr( IMPL->removeAttributeNode( ((QDomAttrPrivate*)oldAttr.impl) ) );
|
|---|
| 4354 | }
|
|---|
| 4355 |
|
|---|
| 4356 | /*!
|
|---|
| 4357 | Returns a QDomNodeList containing all descendent elements of this
|
|---|
| 4358 | element that are called \a tagname. The order they are in the node
|
|---|
| 4359 | list is the order they are encountered in a preorder traversal of
|
|---|
| 4360 | the element tree.
|
|---|
| 4361 |
|
|---|
| 4362 | \sa elementsByTagNameNS() QDomDocument::elementsByTagName()
|
|---|
| 4363 | */
|
|---|
| 4364 | QDomNodeList QDomElement::elementsByTagName( const QString& tagname ) const
|
|---|
| 4365 | {
|
|---|
| 4366 | return QDomNodeList( new QDomNodeListPrivate( impl, tagname ) );
|
|---|
| 4367 | }
|
|---|
| 4368 |
|
|---|
| 4369 | /*!
|
|---|
| 4370 | Returns TRUE.
|
|---|
| 4371 | */
|
|---|
| 4372 | bool QDomElement::isElement() const
|
|---|
| 4373 | {
|
|---|
| 4374 | return TRUE;
|
|---|
| 4375 | }
|
|---|
| 4376 |
|
|---|
| 4377 | /*!
|
|---|
| 4378 | Returns a QDomNamedNodeMap containing all this element's attributes.
|
|---|
| 4379 |
|
|---|
| 4380 | \sa attribute() setAttribute() attributeNode() setAttributeNode()
|
|---|
| 4381 | */
|
|---|
| 4382 | QDomNamedNodeMap QDomElement::attributes() const
|
|---|
| 4383 | {
|
|---|
| 4384 | if ( !impl )
|
|---|
| 4385 | return QDomNamedNodeMap();
|
|---|
| 4386 | return QDomNamedNodeMap( IMPL->attributes() );
|
|---|
| 4387 | }
|
|---|
| 4388 |
|
|---|
| 4389 | /*!
|
|---|
| 4390 | Returns TRUE if this element has an attribute called \a name;
|
|---|
| 4391 | otherwise returns FALSE.
|
|---|
| 4392 | */
|
|---|
| 4393 | bool QDomElement::hasAttribute( const QString& name ) const
|
|---|
| 4394 | {
|
|---|
| 4395 | if ( !impl )
|
|---|
| 4396 | return FALSE;
|
|---|
| 4397 | return IMPL->hasAttribute( name );
|
|---|
| 4398 | }
|
|---|
| 4399 |
|
|---|
| 4400 | /*!
|
|---|
| 4401 | Returns the attribute with the local name \a localName and the
|
|---|
| 4402 | namespace URI \a nsURI. If the attribute does not exist \a
|
|---|
| 4403 | defValue is returned.
|
|---|
| 4404 |
|
|---|
| 4405 | \sa setAttributeNS() attributeNodeNS() setAttributeNodeNS() attribute()
|
|---|
| 4406 | */
|
|---|
| 4407 | QString QDomElement::attributeNS( const QString nsURI, const QString& localName, const QString& defValue ) const
|
|---|
| 4408 | {
|
|---|
| 4409 | if ( !impl )
|
|---|
| 4410 | return defValue;
|
|---|
| 4411 | return IMPL->attributeNS( nsURI, localName, defValue );
|
|---|
| 4412 | }
|
|---|
| 4413 |
|
|---|
| 4414 | /*!
|
|---|
| 4415 | Adds an attribute with the qualified name \a qName and the
|
|---|
| 4416 | namespace URI \a nsURI with the value \a value. If an attribute
|
|---|
| 4417 | with the same local name and namespace URI exists, its prefix is
|
|---|
| 4418 | replaced by the prefix of \a qName and its value is repaced by \a
|
|---|
| 4419 | value.
|
|---|
| 4420 |
|
|---|
| 4421 | Although \a qName is the qualified name, the local name is used to
|
|---|
| 4422 | decide if an existing attribute's value should be replaced.
|
|---|
| 4423 |
|
|---|
| 4424 | \sa attributeNS() setAttributeNodeNS() setAttribute()
|
|---|
| 4425 | */
|
|---|
| 4426 | void QDomElement::setAttributeNS( const QString nsURI, const QString& qName, const QString& value )
|
|---|
| 4427 | {
|
|---|
| 4428 | if ( !impl )
|
|---|
| 4429 | return;
|
|---|
| 4430 | IMPL->setAttributeNS( nsURI, qName, value );
|
|---|
| 4431 | }
|
|---|
| 4432 |
|
|---|
| 4433 | /*!
|
|---|
| 4434 | \overload
|
|---|
| 4435 | */
|
|---|
| 4436 | void QDomElement::setAttributeNS( const QString nsURI, const QString& qName, int value )
|
|---|
| 4437 | {
|
|---|
| 4438 | // ### 4.0: inline
|
|---|
| 4439 | setAttributeNS( nsURI, qName, long(value) );
|
|---|
| 4440 | }
|
|---|
| 4441 |
|
|---|
| 4442 | /*!
|
|---|
| 4443 | \overload
|
|---|
| 4444 | */
|
|---|
| 4445 | void QDomElement::setAttributeNS( const QString nsURI, const QString& qName, uint value )
|
|---|
| 4446 | {
|
|---|
| 4447 | // ### 4.0: inline
|
|---|
| 4448 | setAttributeNS( nsURI, qName, ulong(value) );
|
|---|
| 4449 | }
|
|---|
| 4450 |
|
|---|
| 4451 | /*!
|
|---|
| 4452 | \overload
|
|---|
| 4453 | */
|
|---|
| 4454 | void QDomElement::setAttributeNS( const QString nsURI, const QString& qName, long value )
|
|---|
| 4455 | {
|
|---|
| 4456 | if ( !impl )
|
|---|
| 4457 | return;
|
|---|
| 4458 | QString x;
|
|---|
| 4459 | x.setNum( value );
|
|---|
| 4460 | IMPL->setAttributeNS( nsURI, qName, x );
|
|---|
| 4461 | }
|
|---|
| 4462 |
|
|---|
| 4463 | /*!
|
|---|
| 4464 | \overload
|
|---|
| 4465 | */
|
|---|
| 4466 | void QDomElement::setAttributeNS( const QString nsURI, const QString& qName, ulong value )
|
|---|
| 4467 | {
|
|---|
| 4468 | if ( !impl )
|
|---|
| 4469 | return;
|
|---|
| 4470 | QString x;
|
|---|
| 4471 | x.setNum( value );
|
|---|
| 4472 | IMPL->setAttributeNS( nsURI, qName, x );
|
|---|
| 4473 | }
|
|---|
| 4474 |
|
|---|
| 4475 | /*!
|
|---|
| 4476 | \overload
|
|---|
| 4477 | */
|
|---|
| 4478 | void QDomElement::setAttributeNS( const QString nsURI, const QString& qName, double value )
|
|---|
| 4479 | {
|
|---|
| 4480 | if ( !impl )
|
|---|
| 4481 | return;
|
|---|
| 4482 | QString x;
|
|---|
| 4483 | x.setNum( value );
|
|---|
| 4484 | IMPL->setAttributeNS( nsURI, qName, x );
|
|---|
| 4485 | }
|
|---|
| 4486 |
|
|---|
| 4487 | /*!
|
|---|
| 4488 | Removes the attribute with the local name \a localName and the
|
|---|
| 4489 | namespace URI \a nsURI from this element.
|
|---|
| 4490 |
|
|---|
| 4491 | \sa setAttributeNS() attributeNS() removeAttribute()
|
|---|
| 4492 | */
|
|---|
| 4493 | void QDomElement::removeAttributeNS( const QString& nsURI, const QString& localName )
|
|---|
| 4494 | {
|
|---|
| 4495 | if ( !impl )
|
|---|
| 4496 | return;
|
|---|
| 4497 | QDomNodePrivate *n = IMPL->attributeNodeNS( nsURI, localName );
|
|---|
| 4498 | if ( !n )
|
|---|
| 4499 | return;
|
|---|
| 4500 | IMPL->removeAttribute( n->nodeName() );
|
|---|
| 4501 | }
|
|---|
| 4502 |
|
|---|
| 4503 | /*!
|
|---|
| 4504 | Returns the QDomAttr object that corresponds to the attribute with
|
|---|
| 4505 | the local name \a localName and the namespace URI \a nsURI. If no
|
|---|
| 4506 | such attribute exists a \link QDomNode::isNull() null
|
|---|
| 4507 | attribute\endlink is returned.
|
|---|
| 4508 |
|
|---|
| 4509 | \sa setAttributeNode() attribute() setAttribute() attributeNodeNS()
|
|---|
| 4510 | */
|
|---|
| 4511 | QDomAttr QDomElement::attributeNodeNS( const QString& nsURI, const QString& localName )
|
|---|
| 4512 | {
|
|---|
| 4513 | if ( !impl )
|
|---|
| 4514 | return QDomAttr();
|
|---|
| 4515 | return QDomAttr( IMPL->attributeNodeNS( nsURI, localName ) );
|
|---|
| 4516 | }
|
|---|
| 4517 |
|
|---|
| 4518 | /*!
|
|---|
| 4519 | Adds the attribute \a newAttr to this element.
|
|---|
| 4520 |
|
|---|
| 4521 | If the element has another attribute that has the same local name
|
|---|
| 4522 | and namespace URI as \a newAttr, this function replaces that
|
|---|
| 4523 | attribute and returns it; otherwise the function returns a \link
|
|---|
| 4524 | QDomNode::isNull() null attribute\endlink.
|
|---|
| 4525 |
|
|---|
| 4526 | \sa attributeNodeNS() setAttributeNS() setAttributeNode()
|
|---|
| 4527 | */
|
|---|
| 4528 | QDomAttr QDomElement::setAttributeNodeNS( const QDomAttr& newAttr )
|
|---|
| 4529 | {
|
|---|
| 4530 | if ( !impl )
|
|---|
| 4531 | return QDomAttr();
|
|---|
| 4532 | return QDomAttr( IMPL->setAttributeNodeNS( ((QDomAttrPrivate*)newAttr.impl) ) );
|
|---|
| 4533 | }
|
|---|
| 4534 |
|
|---|
| 4535 | /*!
|
|---|
| 4536 | Returns a QDomNodeList containing all the descendent elements of
|
|---|
| 4537 | this element with the local name \a localName and the namespace
|
|---|
| 4538 | URI \a nsURI. The order they are in the node list is the order
|
|---|
| 4539 | they are encountered in a preorder traversal of the element tree.
|
|---|
| 4540 |
|
|---|
| 4541 | \sa elementsByTagName() QDomDocument::elementsByTagNameNS()
|
|---|
| 4542 | */
|
|---|
| 4543 | QDomNodeList QDomElement::elementsByTagNameNS( const QString& nsURI, const QString& localName ) const
|
|---|
| 4544 | {
|
|---|
| 4545 | return QDomNodeList( new QDomNodeListPrivate( impl, nsURI, localName ) );
|
|---|
| 4546 | }
|
|---|
| 4547 |
|
|---|
| 4548 | /*!
|
|---|
| 4549 | Returns TRUE if this element has an attribute with the local name
|
|---|
| 4550 | \a localName and the namespace URI \a nsURI; otherwise returns
|
|---|
| 4551 | FALSE.
|
|---|
| 4552 | */
|
|---|
| 4553 | bool QDomElement::hasAttributeNS( const QString& nsURI, const QString& localName ) const
|
|---|
| 4554 | {
|
|---|
| 4555 | if ( !impl )
|
|---|
| 4556 | return FALSE;
|
|---|
| 4557 | return IMPL->hasAttributeNS( nsURI, localName );
|
|---|
| 4558 | }
|
|---|
| 4559 |
|
|---|
| 4560 | /*!
|
|---|
| 4561 | Returns the element's text or QString::null.
|
|---|
| 4562 |
|
|---|
| 4563 | Example:
|
|---|
| 4564 | \code
|
|---|
| 4565 | <h1>Hello <b>Qt</b> <![CDATA[<xml is cool>]]></h1>
|
|---|
| 4566 | \endcode
|
|---|
| 4567 |
|
|---|
| 4568 | The function text() of the QDomElement for the <h1> tag,
|
|---|
| 4569 | will return "Hello Qt <xml is cool>".
|
|---|
| 4570 |
|
|---|
| 4571 | Comments are ignored by this function. It only evaluates QDomText
|
|---|
| 4572 | and QDomCDATASection objects.
|
|---|
| 4573 | */
|
|---|
| 4574 | QString QDomElement::text() const
|
|---|
| 4575 | {
|
|---|
| 4576 | if ( !impl )
|
|---|
| 4577 | return QString::null;
|
|---|
| 4578 | return IMPL->text();
|
|---|
| 4579 | }
|
|---|
| 4580 |
|
|---|
| 4581 | #undef IMPL
|
|---|
| 4582 |
|
|---|
| 4583 | /**************************************************************
|
|---|
| 4584 | *
|
|---|
| 4585 | * QDomTextPrivate
|
|---|
| 4586 | *
|
|---|
| 4587 | **************************************************************/
|
|---|
| 4588 |
|
|---|
| 4589 | QDomTextPrivate::QDomTextPrivate( QDomDocumentPrivate* d, QDomNodePrivate* parent, const QString& value )
|
|---|
| 4590 | : QDomCharacterDataPrivate( d, parent, value )
|
|---|
| 4591 | {
|
|---|
| 4592 | name = "#text";
|
|---|
| 4593 | }
|
|---|
| 4594 |
|
|---|
| 4595 | QDomTextPrivate::QDomTextPrivate( QDomTextPrivate* n, bool deep )
|
|---|
| 4596 | : QDomCharacterDataPrivate( n, deep )
|
|---|
| 4597 | {
|
|---|
| 4598 | }
|
|---|
| 4599 |
|
|---|
| 4600 | QDomTextPrivate::~QDomTextPrivate()
|
|---|
| 4601 | {
|
|---|
| 4602 | }
|
|---|
| 4603 |
|
|---|
| 4604 | QDomNodePrivate* QDomTextPrivate::cloneNode( bool deep)
|
|---|
| 4605 | {
|
|---|
| 4606 | QDomNodePrivate* p = new QDomTextPrivate( this, deep );
|
|---|
| 4607 | // We are not interested in this node
|
|---|
| 4608 | p->deref();
|
|---|
| 4609 | return p;
|
|---|
| 4610 | }
|
|---|
| 4611 |
|
|---|
| 4612 | QDomTextPrivate* QDomTextPrivate::splitText( int offset )
|
|---|
| 4613 | {
|
|---|
| 4614 | if ( !parent() ) {
|
|---|
| 4615 | qWarning( "QDomText::splitText The node has no parent. So I can not split" );
|
|---|
| 4616 | return 0;
|
|---|
| 4617 | }
|
|---|
| 4618 |
|
|---|
| 4619 | QDomTextPrivate* t = new QDomTextPrivate( ownerDocument(), 0, value.mid( offset ) );
|
|---|
| 4620 | value.truncate( offset );
|
|---|
| 4621 |
|
|---|
| 4622 | parent()->insertAfter( t, this );
|
|---|
| 4623 |
|
|---|
| 4624 | return t;
|
|---|
| 4625 | }
|
|---|
| 4626 |
|
|---|
| 4627 | void QDomTextPrivate::save( QTextStream& s, int, int ) const
|
|---|
| 4628 | {
|
|---|
| 4629 | s << encodeAttr( value );
|
|---|
| 4630 | }
|
|---|
| 4631 |
|
|---|
| 4632 | /**************************************************************
|
|---|
| 4633 | *
|
|---|
| 4634 | * QDomText
|
|---|
| 4635 | *
|
|---|
| 4636 | **************************************************************/
|
|---|
| 4637 |
|
|---|
| 4638 | #define IMPL ((QDomTextPrivate*)impl)
|
|---|
| 4639 |
|
|---|
| 4640 | /*!
|
|---|
| 4641 | \class QDomText qdom.h
|
|---|
| 4642 | \reentrant
|
|---|
| 4643 | \brief The QDomText class represents text data in the parsed XML document.
|
|---|
| 4644 | \if defined(commercial)
|
|---|
| 4645 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
|---|
| 4646 | \endif
|
|---|
| 4647 |
|
|---|
| 4648 | \module XML
|
|---|
| 4649 | \ingroup xml-tools
|
|---|
| 4650 |
|
|---|
| 4651 | You can split the text in a QDomText object over two QDomText
|
|---|
| 4652 | objecs with splitText().
|
|---|
| 4653 |
|
|---|
| 4654 | For further information about the Document Object Model see
|
|---|
| 4655 | \link http://www.w3.org/TR/REC-DOM-Level-1/\endlink and
|
|---|
| 4656 | \link http://www.w3.org/TR/DOM-Level-2-Core/\endlink.
|
|---|
| 4657 | For a more general introduction of the DOM implementation see the
|
|---|
| 4658 | QDomDocument documentation.
|
|---|
| 4659 | */
|
|---|
| 4660 |
|
|---|
| 4661 | /*!
|
|---|
| 4662 | Constructs an empty QDomText object.
|
|---|
| 4663 |
|
|---|
| 4664 | To construct a QDomText with content, use QDomDocument::createTextNode().
|
|---|
| 4665 | */
|
|---|
| 4666 | QDomText::QDomText()
|
|---|
| 4667 | : QDomCharacterData()
|
|---|
| 4668 | {
|
|---|
| 4669 | }
|
|---|
| 4670 |
|
|---|
| 4671 | /*!
|
|---|
| 4672 | Constructs a copy of \a x.
|
|---|
| 4673 |
|
|---|
| 4674 | The data of the copy is shared (shallow copy): modifying one node
|
|---|
| 4675 | will also change the other. If you want to make a deep copy, use
|
|---|
| 4676 | cloneNode().
|
|---|
| 4677 | */
|
|---|
| 4678 | QDomText::QDomText( const QDomText& x )
|
|---|
| 4679 | : QDomCharacterData( x )
|
|---|
| 4680 | {
|
|---|
| 4681 | }
|
|---|
| 4682 |
|
|---|
| 4683 | QDomText::QDomText( QDomTextPrivate* n )
|
|---|
| 4684 | : QDomCharacterData( n )
|
|---|
| 4685 | {
|
|---|
| 4686 | }
|
|---|
| 4687 |
|
|---|
| 4688 | /*!
|
|---|
| 4689 | Assigns \a x to this DOM text.
|
|---|
| 4690 |
|
|---|
| 4691 | The data of the copy is shared (shallow copy): modifying one node
|
|---|
| 4692 | will also change the other. If you want to make a deep copy, use
|
|---|
| 4693 | cloneNode().
|
|---|
| 4694 | */
|
|---|
| 4695 | QDomText& QDomText::operator= ( const QDomText& x )
|
|---|
| 4696 | {
|
|---|
| 4697 | return (QDomText&) QDomNode::operator=( x );
|
|---|
| 4698 | }
|
|---|
| 4699 |
|
|---|
| 4700 | /*!
|
|---|
| 4701 | Destroys the object and frees its resources.
|
|---|
| 4702 | */
|
|---|
| 4703 | QDomText::~QDomText()
|
|---|
| 4704 | {
|
|---|
| 4705 | }
|
|---|
| 4706 |
|
|---|
| 4707 | /*!
|
|---|
| 4708 | Returns \c TextNode.
|
|---|
| 4709 | */
|
|---|
| 4710 | QDomNode::NodeType QDomText::nodeType() const
|
|---|
| 4711 | {
|
|---|
| 4712 | return TextNode;
|
|---|
| 4713 | }
|
|---|
| 4714 |
|
|---|
| 4715 | /*!
|
|---|
| 4716 | Splits this DOM text object into two QDomText objects. This object
|
|---|
| 4717 | keeps its first \a offset characters and the second (newly
|
|---|
| 4718 | created) object is inserted into the document tree after this
|
|---|
| 4719 | object with the remaining characters.
|
|---|
| 4720 |
|
|---|
| 4721 | The function returns the newly created object.
|
|---|
| 4722 |
|
|---|
| 4723 | \sa QDomNode::normalize()
|
|---|
| 4724 | */
|
|---|
| 4725 | QDomText QDomText::splitText( int offset )
|
|---|
| 4726 | {
|
|---|
| 4727 | if ( !impl )
|
|---|
| 4728 | return QDomText();
|
|---|
| 4729 | return QDomText( IMPL->splitText( offset ) );
|
|---|
| 4730 | }
|
|---|
| 4731 |
|
|---|
| 4732 | /*!
|
|---|
| 4733 | Returns TRUE.
|
|---|
| 4734 | */
|
|---|
| 4735 | bool QDomText::isText() const
|
|---|
| 4736 | {
|
|---|
| 4737 | return TRUE;
|
|---|
| 4738 | }
|
|---|
| 4739 |
|
|---|
| 4740 | #undef IMPL
|
|---|
| 4741 |
|
|---|
| 4742 | /**************************************************************
|
|---|
| 4743 | *
|
|---|
| 4744 | * QDomCommentPrivate
|
|---|
| 4745 | *
|
|---|
| 4746 | **************************************************************/
|
|---|
| 4747 |
|
|---|
| 4748 | QDomCommentPrivate::QDomCommentPrivate( QDomDocumentPrivate* d, QDomNodePrivate* parent, const QString& value )
|
|---|
| 4749 | : QDomCharacterDataPrivate( d, parent, value )
|
|---|
| 4750 | {
|
|---|
| 4751 | name = "#comment";
|
|---|
| 4752 | }
|
|---|
| 4753 |
|
|---|
| 4754 | QDomCommentPrivate::QDomCommentPrivate( QDomCommentPrivate* n, bool deep )
|
|---|
| 4755 | : QDomCharacterDataPrivate( n, deep )
|
|---|
| 4756 | {
|
|---|
| 4757 | }
|
|---|
| 4758 |
|
|---|
| 4759 | QDomCommentPrivate::~QDomCommentPrivate()
|
|---|
| 4760 | {
|
|---|
| 4761 | }
|
|---|
| 4762 |
|
|---|
| 4763 | QDomNodePrivate* QDomCommentPrivate::cloneNode( bool deep)
|
|---|
| 4764 | {
|
|---|
| 4765 | QDomNodePrivate* p = new QDomCommentPrivate( this, deep );
|
|---|
| 4766 | // We are not interested in this node
|
|---|
| 4767 | p->deref();
|
|---|
| 4768 | return p;
|
|---|
| 4769 | }
|
|---|
| 4770 |
|
|---|
| 4771 | void QDomCommentPrivate::save( QTextStream& s, int, int ) const
|
|---|
| 4772 | {
|
|---|
| 4773 | s << "<!--" << value << "-->";
|
|---|
| 4774 | }
|
|---|
| 4775 |
|
|---|
| 4776 | /**************************************************************
|
|---|
| 4777 | *
|
|---|
| 4778 | * QDomComment
|
|---|
| 4779 | *
|
|---|
| 4780 | **************************************************************/
|
|---|
| 4781 |
|
|---|
| 4782 | #define IMPL ((QDomCommentPrivate*)impl)
|
|---|
| 4783 |
|
|---|
| 4784 | /*!
|
|---|
| 4785 | \class QDomComment qdom.h
|
|---|
| 4786 | \reentrant
|
|---|
| 4787 | \brief The QDomComment class represents an XML comment.
|
|---|
| 4788 | \if defined(commercial)
|
|---|
| 4789 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
|---|
| 4790 | \endif
|
|---|
| 4791 |
|
|---|
| 4792 | \module XML
|
|---|
| 4793 | \ingroup xml-tools
|
|---|
| 4794 |
|
|---|
| 4795 | A comment in the parsed XML such as this:
|
|---|
| 4796 | \code
|
|---|
| 4797 | <!-- this is a comment -->
|
|---|
| 4798 | \endcode
|
|---|
| 4799 | is represented by QDomComment objects in the parsed Dom tree.
|
|---|
| 4800 |
|
|---|
| 4801 | For further information about the Document Object Model see
|
|---|
| 4802 | \link http://www.w3.org/TR/REC-DOM-Level-1/\endlink and
|
|---|
| 4803 | \link http://www.w3.org/TR/DOM-Level-2-Core/\endlink.
|
|---|
| 4804 | For a more general introduction of the DOM implementation see the
|
|---|
| 4805 | QDomDocument documentation.
|
|---|
| 4806 | */
|
|---|
| 4807 |
|
|---|
| 4808 | /*!
|
|---|
| 4809 | Constructs an empty comment. To construct a comment with content,
|
|---|
| 4810 | use the QDomDocument::createComment() function.
|
|---|
| 4811 | */
|
|---|
| 4812 | QDomComment::QDomComment()
|
|---|
| 4813 | : QDomCharacterData()
|
|---|
| 4814 | {
|
|---|
| 4815 | }
|
|---|
| 4816 |
|
|---|
| 4817 | /*!
|
|---|
| 4818 | Constructs a copy of \a x.
|
|---|
| 4819 |
|
|---|
| 4820 | The data of the copy is shared (shallow copy): modifying one node
|
|---|
| 4821 | will also change the other. If you want to make a deep copy, use
|
|---|
| 4822 | cloneNode().
|
|---|
| 4823 | */
|
|---|
| 4824 | QDomComment::QDomComment( const QDomComment& x )
|
|---|
| 4825 | : QDomCharacterData( x )
|
|---|
| 4826 | {
|
|---|
| 4827 | }
|
|---|
| 4828 |
|
|---|
| 4829 | QDomComment::QDomComment( QDomCommentPrivate* n )
|
|---|
| 4830 | : QDomCharacterData( n )
|
|---|
| 4831 | {
|
|---|
| 4832 | }
|
|---|
| 4833 |
|
|---|
| 4834 | /*!
|
|---|
| 4835 | Assigns \a x to this DOM comment.
|
|---|
| 4836 |
|
|---|
| 4837 | The data of the copy is shared (shallow copy): modifying one node
|
|---|
| 4838 | will also change the other. If you want to make a deep copy, use
|
|---|
| 4839 | cloneNode().
|
|---|
| 4840 | */
|
|---|
| 4841 | QDomComment& QDomComment::operator= ( const QDomComment& x )
|
|---|
| 4842 | {
|
|---|
| 4843 | return (QDomComment&) QDomNode::operator=( x );
|
|---|
| 4844 | }
|
|---|
| 4845 |
|
|---|
| 4846 | /*!
|
|---|
| 4847 | Destroys the object and frees its resources.
|
|---|
| 4848 | */
|
|---|
| 4849 | QDomComment::~QDomComment()
|
|---|
| 4850 | {
|
|---|
| 4851 | }
|
|---|
| 4852 |
|
|---|
| 4853 | /*!
|
|---|
| 4854 | Returns \c CommentNode.
|
|---|
| 4855 | */
|
|---|
| 4856 | QDomNode::NodeType QDomComment::nodeType() const
|
|---|
| 4857 | {
|
|---|
| 4858 | return CommentNode;
|
|---|
| 4859 | }
|
|---|
| 4860 |
|
|---|
| 4861 | /*!
|
|---|
| 4862 | Returns TRUE.
|
|---|
| 4863 | */
|
|---|
| 4864 | bool QDomComment::isComment() const
|
|---|
| 4865 | {
|
|---|
| 4866 | return TRUE;
|
|---|
| 4867 | }
|
|---|
| 4868 |
|
|---|
| 4869 | #undef IMPL
|
|---|
| 4870 |
|
|---|
| 4871 | /**************************************************************
|
|---|
| 4872 | *
|
|---|
| 4873 | * QDomCDATASectionPrivate
|
|---|
| 4874 | *
|
|---|
| 4875 | **************************************************************/
|
|---|
| 4876 |
|
|---|
| 4877 | QDomCDATASectionPrivate::QDomCDATASectionPrivate( QDomDocumentPrivate* d, QDomNodePrivate* parent,
|
|---|
| 4878 | const QString& value )
|
|---|
| 4879 | : QDomTextPrivate( d, parent, value )
|
|---|
| 4880 | {
|
|---|
| 4881 | name = "#cdata-section";
|
|---|
| 4882 | }
|
|---|
| 4883 |
|
|---|
| 4884 | QDomCDATASectionPrivate::QDomCDATASectionPrivate( QDomCDATASectionPrivate* n, bool deep )
|
|---|
| 4885 | : QDomTextPrivate( n, deep )
|
|---|
| 4886 | {
|
|---|
| 4887 | }
|
|---|
| 4888 |
|
|---|
| 4889 | QDomCDATASectionPrivate::~QDomCDATASectionPrivate()
|
|---|
| 4890 | {
|
|---|
| 4891 | }
|
|---|
| 4892 |
|
|---|
| 4893 | QDomNodePrivate* QDomCDATASectionPrivate::cloneNode( bool deep)
|
|---|
| 4894 | {
|
|---|
| 4895 | QDomNodePrivate* p = new QDomCDATASectionPrivate( this, deep );
|
|---|
| 4896 | // We are not interested in this node
|
|---|
| 4897 | p->deref();
|
|---|
| 4898 | return p;
|
|---|
| 4899 | }
|
|---|
| 4900 |
|
|---|
| 4901 | void QDomCDATASectionPrivate::save( QTextStream& s, int, int ) const
|
|---|
| 4902 | {
|
|---|
| 4903 | // ### How do we escape "]]>" ?
|
|---|
| 4904 | // "]]>" is not allowed; so there should be none in value anyway
|
|---|
| 4905 | s << "<![CDATA[" << value << "]]>";
|
|---|
| 4906 | }
|
|---|
| 4907 |
|
|---|
| 4908 | /**************************************************************
|
|---|
| 4909 | *
|
|---|
| 4910 | * QDomCDATASection
|
|---|
| 4911 | *
|
|---|
| 4912 | **************************************************************/
|
|---|
| 4913 |
|
|---|
| 4914 | #define IMPL ((QDomCDATASectionPrivate*)impl)
|
|---|
| 4915 |
|
|---|
| 4916 | /*!
|
|---|
| 4917 | \class QDomCDATASection qdom.h
|
|---|
| 4918 | \reentrant
|
|---|
| 4919 | \brief The QDomCDATASection class represents an XML CDATA section.
|
|---|
| 4920 | \if defined(commercial)
|
|---|
| 4921 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
|---|
| 4922 | \endif
|
|---|
| 4923 |
|
|---|
| 4924 | \module XML
|
|---|
| 4925 | \ingroup xml-tools
|
|---|
| 4926 |
|
|---|
| 4927 | CDATA sections are used to escape blocks of text containing
|
|---|
| 4928 | characters that would otherwise be regarded as markup. The only
|
|---|
| 4929 | delimiter that is recognized in a CDATA section is the "]]>"
|
|---|
| 4930 | string that terminates the CDATA section. CDATA sections cannot be
|
|---|
| 4931 | nested. Their primary purpose is for including material such as
|
|---|
| 4932 | XML fragments, without needing to escape all the delimiters.
|
|---|
| 4933 |
|
|---|
| 4934 | Adjacent QDomCDATASection nodes are not merged by the
|
|---|
| 4935 | QDomNode::normalize() function.
|
|---|
| 4936 |
|
|---|
| 4937 | For further information about the Document Object Model see
|
|---|
| 4938 | \link http://www.w3.org/TR/REC-DOM-Level-1/\endlink and
|
|---|
| 4939 | \link http://www.w3.org/TR/DOM-Level-2-Core/\endlink.
|
|---|
| 4940 | For a more general introduction of the DOM implementation see the
|
|---|
| 4941 | QDomDocument documentation.
|
|---|
| 4942 | */
|
|---|
| 4943 |
|
|---|
| 4944 | /*!
|
|---|
| 4945 | Constructs an empty CDATA section. To create a CDATA section with
|
|---|
| 4946 | content, use the QDomDocument::createCDATASection() function.
|
|---|
| 4947 | */
|
|---|
| 4948 | QDomCDATASection::QDomCDATASection()
|
|---|
| 4949 | : QDomText()
|
|---|
| 4950 | {
|
|---|
| 4951 | }
|
|---|
| 4952 |
|
|---|
| 4953 | /*!
|
|---|
| 4954 | Constructs a copy of \a x.
|
|---|
| 4955 |
|
|---|
| 4956 | The data of the copy is shared (shallow copy): modifying one node
|
|---|
| 4957 | will also change the other. If you want to make a deep copy, use
|
|---|
| 4958 | cloneNode().
|
|---|
| 4959 | */
|
|---|
| 4960 | QDomCDATASection::QDomCDATASection( const QDomCDATASection& x )
|
|---|
| 4961 | : QDomText( x )
|
|---|
| 4962 | {
|
|---|
| 4963 | }
|
|---|
| 4964 |
|
|---|
| 4965 | QDomCDATASection::QDomCDATASection( QDomCDATASectionPrivate* n )
|
|---|
| 4966 | : QDomText( n )
|
|---|
| 4967 | {
|
|---|
| 4968 | }
|
|---|
| 4969 |
|
|---|
| 4970 | /*!
|
|---|
| 4971 | Assigns \a x to this CDATA section.
|
|---|
| 4972 |
|
|---|
| 4973 | The data of the copy is shared (shallow copy): modifying one node
|
|---|
| 4974 | will also change the other. If you want to make a deep copy, use
|
|---|
| 4975 | cloneNode().
|
|---|
| 4976 | */
|
|---|
| 4977 | QDomCDATASection& QDomCDATASection::operator= ( const QDomCDATASection& x )
|
|---|
| 4978 | {
|
|---|
| 4979 | return (QDomCDATASection&) QDomNode::operator=( x );
|
|---|
| 4980 | }
|
|---|
| 4981 |
|
|---|
| 4982 | /*!
|
|---|
| 4983 | Destroys the object and frees its resources.
|
|---|
| 4984 | */
|
|---|
| 4985 | QDomCDATASection::~QDomCDATASection()
|
|---|
| 4986 | {
|
|---|
| 4987 | }
|
|---|
| 4988 |
|
|---|
| 4989 | /*!
|
|---|
| 4990 | Returns \c CDATASection.
|
|---|
| 4991 | */
|
|---|
| 4992 | QDomNode::NodeType QDomCDATASection::nodeType() const
|
|---|
| 4993 | {
|
|---|
| 4994 | return CDATASectionNode;
|
|---|
| 4995 | }
|
|---|
| 4996 |
|
|---|
| 4997 | /*!
|
|---|
| 4998 | Returns TRUE.
|
|---|
| 4999 | */
|
|---|
| 5000 | bool QDomCDATASection::isCDATASection() const
|
|---|
| 5001 | {
|
|---|
| 5002 | return TRUE;
|
|---|
| 5003 | }
|
|---|
| 5004 |
|
|---|
| 5005 | #undef IMPL
|
|---|
| 5006 |
|
|---|
| 5007 | /**************************************************************
|
|---|
| 5008 | *
|
|---|
| 5009 | * QDomNotationPrivate
|
|---|
| 5010 | *
|
|---|
| 5011 | **************************************************************/
|
|---|
| 5012 |
|
|---|
| 5013 | QDomNotationPrivate::QDomNotationPrivate( QDomDocumentPrivate* d, QDomNodePrivate* parent,
|
|---|
| 5014 | const QString& aname,
|
|---|
| 5015 | const QString& pub, const QString& sys )
|
|---|
| 5016 | : QDomNodePrivate( d, parent )
|
|---|
| 5017 | {
|
|---|
| 5018 | name = aname;
|
|---|
| 5019 | m_pub = pub;
|
|---|
| 5020 | m_sys = sys;
|
|---|
| 5021 | }
|
|---|
| 5022 |
|
|---|
| 5023 | QDomNotationPrivate::QDomNotationPrivate( QDomNotationPrivate* n, bool deep )
|
|---|
| 5024 | : QDomNodePrivate( n, deep )
|
|---|
| 5025 | {
|
|---|
| 5026 | m_sys = n->m_sys;
|
|---|
| 5027 | m_pub = n->m_pub;
|
|---|
| 5028 | }
|
|---|
| 5029 |
|
|---|
| 5030 | QDomNotationPrivate::~QDomNotationPrivate()
|
|---|
| 5031 | {
|
|---|
| 5032 | }
|
|---|
| 5033 |
|
|---|
| 5034 | QDomNodePrivate* QDomNotationPrivate::cloneNode( bool deep)
|
|---|
| 5035 | {
|
|---|
| 5036 | QDomNodePrivate* p = new QDomNotationPrivate( this, deep );
|
|---|
| 5037 | // We are not interested in this node
|
|---|
| 5038 | p->deref();
|
|---|
| 5039 | return p;
|
|---|
| 5040 | }
|
|---|
| 5041 |
|
|---|
| 5042 | void QDomNotationPrivate::save( QTextStream& s, int, int ) const
|
|---|
| 5043 | {
|
|---|
| 5044 | s << "<!NOTATION " << name << " ";
|
|---|
| 5045 | if ( !m_pub.isNull() ) {
|
|---|
| 5046 | s << "PUBLIC \"" << m_pub << "\"";
|
|---|
| 5047 | if ( !m_sys.isNull() )
|
|---|
| 5048 | s << " \"" << m_sys << "\"";
|
|---|
| 5049 | } else {
|
|---|
| 5050 | s << "SYSTEM \"" << m_sys << "\"";
|
|---|
| 5051 | }
|
|---|
| 5052 | s << ">" << endl;
|
|---|
| 5053 | }
|
|---|
| 5054 |
|
|---|
| 5055 | /**************************************************************
|
|---|
| 5056 | *
|
|---|
| 5057 | * QDomNotation
|
|---|
| 5058 | *
|
|---|
| 5059 | **************************************************************/
|
|---|
| 5060 |
|
|---|
| 5061 | #define IMPL ((QDomNotationPrivate*)impl)
|
|---|
| 5062 |
|
|---|
| 5063 | /*!
|
|---|
| 5064 | \class QDomNotation qdom.h
|
|---|
| 5065 | \reentrant
|
|---|
| 5066 | \brief The QDomNotation class represents an XML notation.
|
|---|
| 5067 | \if defined(commercial)
|
|---|
| 5068 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
|---|
| 5069 | \endif
|
|---|
| 5070 |
|
|---|
| 5071 | \module XML
|
|---|
| 5072 | \ingroup xml-tools
|
|---|
| 5073 |
|
|---|
| 5074 | A notation either declares, by name, the format of an unparsed
|
|---|
| 5075 | entity (see section 4.7 of the XML 1.0 specification), or is used
|
|---|
| 5076 | for formal declaration of processing instruction targets (see
|
|---|
| 5077 | section 2.6 of the XML 1.0 specification).
|
|---|
| 5078 |
|
|---|
| 5079 | DOM does not support editing notation nodes; they are therefore
|
|---|
| 5080 | read-only.
|
|---|
| 5081 |
|
|---|
| 5082 | A notation node does not have any parent.
|
|---|
| 5083 |
|
|---|
| 5084 | You can retrieve the publicId() and systemId() from a notation
|
|---|
| 5085 | node.
|
|---|
| 5086 |
|
|---|
| 5087 | For further information about the Document Object Model see
|
|---|
| 5088 | \link http://www.w3.org/TR/REC-DOM-Level-1/\endlink and
|
|---|
| 5089 | \link http://www.w3.org/TR/DOM-Level-2-Core/\endlink.
|
|---|
| 5090 | For a more general introduction of the DOM implementation see the
|
|---|
| 5091 | QDomDocument documentation.
|
|---|
| 5092 | */
|
|---|
| 5093 |
|
|---|
| 5094 |
|
|---|
| 5095 | /*!
|
|---|
| 5096 | Constructor.
|
|---|
| 5097 | */
|
|---|
| 5098 | QDomNotation::QDomNotation()
|
|---|
| 5099 | : QDomNode()
|
|---|
| 5100 | {
|
|---|
| 5101 | }
|
|---|
| 5102 |
|
|---|
| 5103 | /*!
|
|---|
| 5104 | Constructs a copy of \a x.
|
|---|
| 5105 |
|
|---|
| 5106 | The data of the copy is shared (shallow copy): modifying one node
|
|---|
| 5107 | will also change the other. If you want to make a deep copy, use
|
|---|
| 5108 | cloneNode().
|
|---|
| 5109 | */
|
|---|
| 5110 | QDomNotation::QDomNotation( const QDomNotation& x )
|
|---|
| 5111 | : QDomNode( x )
|
|---|
| 5112 | {
|
|---|
| 5113 | }
|
|---|
| 5114 |
|
|---|
| 5115 | QDomNotation::QDomNotation( QDomNotationPrivate* n )
|
|---|
| 5116 | : QDomNode( n )
|
|---|
| 5117 | {
|
|---|
| 5118 | }
|
|---|
| 5119 |
|
|---|
| 5120 | /*!
|
|---|
| 5121 | Assigns \a x to this DOM notation.
|
|---|
| 5122 |
|
|---|
| 5123 | The data of the copy is shared (shallow copy): modifying one node
|
|---|
| 5124 | will also change the other. If you want to make a deep copy, use
|
|---|
| 5125 | cloneNode().
|
|---|
| 5126 | */
|
|---|
| 5127 | QDomNotation& QDomNotation::operator= ( const QDomNotation& x )
|
|---|
| 5128 | {
|
|---|
| 5129 | return (QDomNotation&) QDomNode::operator=( x );
|
|---|
| 5130 | }
|
|---|
| 5131 |
|
|---|
| 5132 | /*!
|
|---|
| 5133 | Destroys the object and frees its resources.
|
|---|
| 5134 | */
|
|---|
| 5135 | QDomNotation::~QDomNotation()
|
|---|
| 5136 | {
|
|---|
| 5137 | }
|
|---|
| 5138 |
|
|---|
| 5139 | /*!
|
|---|
| 5140 | Returns \c NotationNode.
|
|---|
| 5141 | */
|
|---|
| 5142 | QDomNode::NodeType QDomNotation::nodeType() const
|
|---|
| 5143 | {
|
|---|
| 5144 | return NotationNode;
|
|---|
| 5145 | }
|
|---|
| 5146 |
|
|---|
| 5147 | /*!
|
|---|
| 5148 | Returns the public identifier of this notation.
|
|---|
| 5149 | */
|
|---|
| 5150 | QString QDomNotation::publicId() const
|
|---|
| 5151 | {
|
|---|
| 5152 | if ( !impl )
|
|---|
| 5153 | return QString::null;
|
|---|
| 5154 | return IMPL->m_pub;
|
|---|
| 5155 | }
|
|---|
| 5156 |
|
|---|
| 5157 | /*!
|
|---|
| 5158 | Returns the system identifier of this notation.
|
|---|
| 5159 | */
|
|---|
| 5160 | QString QDomNotation::systemId() const
|
|---|
| 5161 | {
|
|---|
| 5162 | if ( !impl )
|
|---|
| 5163 | return QString::null;
|
|---|
| 5164 | return IMPL->m_sys;
|
|---|
| 5165 | }
|
|---|
| 5166 |
|
|---|
| 5167 | /*!
|
|---|
| 5168 | Returns TRUE.
|
|---|
| 5169 | */
|
|---|
| 5170 | bool QDomNotation::isNotation() const
|
|---|
| 5171 | {
|
|---|
| 5172 | return TRUE;
|
|---|
| 5173 | }
|
|---|
| 5174 |
|
|---|
| 5175 | #undef IMPL
|
|---|
| 5176 |
|
|---|
| 5177 | /**************************************************************
|
|---|
| 5178 | *
|
|---|
| 5179 | * QDomEntityPrivate
|
|---|
| 5180 | *
|
|---|
| 5181 | **************************************************************/
|
|---|
| 5182 |
|
|---|
| 5183 | QDomEntityPrivate::QDomEntityPrivate( QDomDocumentPrivate* d, QDomNodePrivate* parent,
|
|---|
| 5184 | const QString& aname,
|
|---|
| 5185 | const QString& pub, const QString& sys, const QString& notation )
|
|---|
| 5186 | : QDomNodePrivate( d, parent )
|
|---|
| 5187 | {
|
|---|
| 5188 | name = aname;
|
|---|
| 5189 | m_pub = pub;
|
|---|
| 5190 | m_sys = sys;
|
|---|
| 5191 | m_notationName = notation;
|
|---|
| 5192 | }
|
|---|
| 5193 |
|
|---|
| 5194 | QDomEntityPrivate::QDomEntityPrivate( QDomEntityPrivate* n, bool deep )
|
|---|
| 5195 | : QDomNodePrivate( n, deep )
|
|---|
| 5196 | {
|
|---|
| 5197 | m_sys = n->m_sys;
|
|---|
| 5198 | m_pub = n->m_pub;
|
|---|
| 5199 | m_notationName = n->m_notationName;
|
|---|
| 5200 | }
|
|---|
| 5201 |
|
|---|
| 5202 | QDomEntityPrivate::~QDomEntityPrivate()
|
|---|
| 5203 | {
|
|---|
| 5204 | }
|
|---|
| 5205 |
|
|---|
| 5206 | QDomNodePrivate* QDomEntityPrivate::cloneNode( bool deep)
|
|---|
| 5207 | {
|
|---|
| 5208 | QDomNodePrivate* p = new QDomEntityPrivate( this, deep );
|
|---|
| 5209 | // We are not interested in this node
|
|---|
| 5210 | p->deref();
|
|---|
| 5211 | return p;
|
|---|
| 5212 | }
|
|---|
| 5213 |
|
|---|
| 5214 | /*
|
|---|
| 5215 | Encode an entity value upon saving.
|
|---|
| 5216 | */
|
|---|
| 5217 | static QCString encodeEntity( const QCString& str )
|
|---|
| 5218 | {
|
|---|
| 5219 | QCString tmp( str );
|
|---|
| 5220 | uint len = tmp.length();
|
|---|
| 5221 | uint i = 0;
|
|---|
| 5222 | const char* d = tmp.data();
|
|---|
| 5223 | while ( i < len ) {
|
|---|
| 5224 | if ( d[i] == '%' ){
|
|---|
| 5225 | tmp.replace( i, 1, "<" );
|
|---|
| 5226 | d = tmp.data();
|
|---|
| 5227 | len += 4;
|
|---|
| 5228 | i += 5;
|
|---|
| 5229 | }
|
|---|
| 5230 | else if ( d[i] == '"' ) {
|
|---|
| 5231 | tmp.replace( i, 1, """ );
|
|---|
| 5232 | d = tmp.data();
|
|---|
| 5233 | len += 4;
|
|---|
| 5234 | i += 5;
|
|---|
| 5235 | } else if ( d[i] == '&' && i + 1 < len && d[i+1] == '#' ) {
|
|---|
| 5236 | // Dont encode < or " or &custom;.
|
|---|
| 5237 | // Only encode character references
|
|---|
| 5238 | tmp.replace( i, 1, "&" );
|
|---|
| 5239 | d = tmp.data();
|
|---|
| 5240 | len += 4;
|
|---|
| 5241 | i += 5;
|
|---|
| 5242 | } else {
|
|---|
| 5243 | ++i;
|
|---|
| 5244 | }
|
|---|
| 5245 | }
|
|---|
| 5246 |
|
|---|
| 5247 | return tmp;
|
|---|
| 5248 | }
|
|---|
| 5249 |
|
|---|
| 5250 | void QDomEntityPrivate::save( QTextStream& s, int, int ) const
|
|---|
| 5251 | {
|
|---|
| 5252 | if ( m_sys.isNull() && m_pub.isNull() ) {
|
|---|
| 5253 | s << "<!ENTITY " << name << " \"" << encodeEntity( value.utf8() ) << "\">" << endl;
|
|---|
| 5254 | } else {
|
|---|
| 5255 | s << "<!ENTITY " << name << " ";
|
|---|
| 5256 | if ( m_pub.isNull() ) {
|
|---|
| 5257 | s << "SYSTEM \"" << m_sys << "\"";
|
|---|
| 5258 | } else {
|
|---|
| 5259 | s << "PUBLIC \"" << m_pub << "\" \"" << m_sys << "\"";
|
|---|
| 5260 | }
|
|---|
| 5261 | if (! m_notationName.isNull() ) {
|
|---|
| 5262 | s << " NDATA " << m_notationName;
|
|---|
| 5263 | }
|
|---|
| 5264 | s << ">" << endl;
|
|---|
| 5265 | }
|
|---|
| 5266 | }
|
|---|
| 5267 |
|
|---|
| 5268 | /**************************************************************
|
|---|
| 5269 | *
|
|---|
| 5270 | * QDomEntity
|
|---|
| 5271 | *
|
|---|
| 5272 | **************************************************************/
|
|---|
| 5273 |
|
|---|
| 5274 | #define IMPL ((QDomEntityPrivate*)impl)
|
|---|
| 5275 |
|
|---|
| 5276 | /*!
|
|---|
| 5277 | \class QDomEntity qdom.h
|
|---|
| 5278 | \reentrant
|
|---|
| 5279 | \brief The QDomEntity class represents an XML entity.
|
|---|
| 5280 | \if defined(commercial)
|
|---|
| 5281 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
|---|
| 5282 | \endif
|
|---|
| 5283 |
|
|---|
| 5284 | \module XML
|
|---|
| 5285 | \ingroup xml-tools
|
|---|
| 5286 |
|
|---|
| 5287 | This class represents an entity in an XML document, either parsed
|
|---|
| 5288 | or unparsed. Note that this models the entity itself not the
|
|---|
| 5289 | entity declaration.
|
|---|
| 5290 |
|
|---|
| 5291 | DOM does not support editing entity nodes; if a user wants to make
|
|---|
| 5292 | changes to the contents of an entity, every related
|
|---|
| 5293 | QDomEntityReference node must be replaced in the DOM tree by a
|
|---|
| 5294 | clone of the entity's contents, and then the desired changes must
|
|---|
| 5295 | be made to each of the clones instead. All the descendents of an
|
|---|
| 5296 | entity node are read-only.
|
|---|
| 5297 |
|
|---|
| 5298 | An entity node does not have any parent.
|
|---|
| 5299 |
|
|---|
| 5300 | You can access the entity's publicId(), systemId() and
|
|---|
| 5301 | notationName() when available.
|
|---|
| 5302 |
|
|---|
| 5303 | For further information about the Document Object Model see
|
|---|
| 5304 | \link http://www.w3.org/TR/REC-DOM-Level-1/\endlink and
|
|---|
| 5305 | \link http://www.w3.org/TR/DOM-Level-2-Core/\endlink.
|
|---|
| 5306 | For a more general introduction of the DOM implementation see the
|
|---|
| 5307 | QDomDocument documentation.
|
|---|
| 5308 | */
|
|---|
| 5309 |
|
|---|
| 5310 |
|
|---|
| 5311 | /*!
|
|---|
| 5312 | Constructs an empty entity.
|
|---|
| 5313 | */
|
|---|
| 5314 | QDomEntity::QDomEntity()
|
|---|
| 5315 | : QDomNode()
|
|---|
| 5316 | {
|
|---|
| 5317 | }
|
|---|
| 5318 |
|
|---|
| 5319 |
|
|---|
| 5320 | /*!
|
|---|
| 5321 | Constructs a copy of \a x.
|
|---|
| 5322 |
|
|---|
| 5323 | The data of the copy is shared (shallow copy): modifying one node
|
|---|
| 5324 | will also change the other. If you want to make a deep copy, use
|
|---|
| 5325 | cloneNode().
|
|---|
| 5326 | */
|
|---|
| 5327 | QDomEntity::QDomEntity( const QDomEntity& x )
|
|---|
| 5328 | : QDomNode( x )
|
|---|
| 5329 | {
|
|---|
| 5330 | }
|
|---|
| 5331 |
|
|---|
| 5332 | QDomEntity::QDomEntity( QDomEntityPrivate* n )
|
|---|
| 5333 | : QDomNode( n )
|
|---|
| 5334 | {
|
|---|
| 5335 | }
|
|---|
| 5336 |
|
|---|
| 5337 | /*!
|
|---|
| 5338 | Assigns \a x to this DOM entity.
|
|---|
| 5339 |
|
|---|
| 5340 | The data of the copy is shared (shallow copy): modifying one node
|
|---|
| 5341 | will also change the other. If you want to make a deep copy, use
|
|---|
| 5342 | cloneNode().
|
|---|
| 5343 | */
|
|---|
| 5344 | QDomEntity& QDomEntity::operator= ( const QDomEntity& x )
|
|---|
| 5345 | {
|
|---|
| 5346 | return (QDomEntity&) QDomNode::operator=( x );
|
|---|
| 5347 | }
|
|---|
| 5348 |
|
|---|
| 5349 | /*!
|
|---|
| 5350 | Destroys the object and frees its resources.
|
|---|
| 5351 | */
|
|---|
| 5352 | QDomEntity::~QDomEntity()
|
|---|
| 5353 | {
|
|---|
| 5354 | }
|
|---|
| 5355 |
|
|---|
| 5356 | /*!
|
|---|
| 5357 | Returns \c EntityNode.
|
|---|
| 5358 | */
|
|---|
| 5359 | QDomNode::NodeType QDomEntity::nodeType() const
|
|---|
| 5360 | {
|
|---|
| 5361 | return EntityNode;
|
|---|
| 5362 | }
|
|---|
| 5363 |
|
|---|
| 5364 | /*!
|
|---|
| 5365 | Returns the public identifier associated with this entity. If the
|
|---|
| 5366 | public identifier was not specified QString::null is returned.
|
|---|
| 5367 | */
|
|---|
| 5368 | QString QDomEntity::publicId() const
|
|---|
| 5369 | {
|
|---|
| 5370 | if ( !impl )
|
|---|
| 5371 | return QString::null;
|
|---|
| 5372 | return IMPL->m_pub;
|
|---|
| 5373 | }
|
|---|
| 5374 |
|
|---|
| 5375 | /*!
|
|---|
| 5376 | Returns the system identifier associated with this entity. If the
|
|---|
| 5377 | system identifier was not specified QString::null is returned.
|
|---|
| 5378 | */
|
|---|
| 5379 | QString QDomEntity::systemId() const
|
|---|
| 5380 | {
|
|---|
| 5381 | if ( !impl )
|
|---|
| 5382 | return QString::null;
|
|---|
| 5383 | return IMPL->m_sys;
|
|---|
| 5384 | }
|
|---|
| 5385 |
|
|---|
| 5386 | /*!
|
|---|
| 5387 | For unparsed entities this function returns the name of the
|
|---|
| 5388 | notation for the entity. For parsed entities this function returns
|
|---|
| 5389 | QString::null.
|
|---|
| 5390 | */
|
|---|
| 5391 | QString QDomEntity::notationName() const
|
|---|
| 5392 | {
|
|---|
| 5393 | if ( !impl )
|
|---|
| 5394 | return QString::null;
|
|---|
| 5395 | return IMPL->m_notationName;
|
|---|
| 5396 | }
|
|---|
| 5397 |
|
|---|
| 5398 | /*!
|
|---|
| 5399 | Returns TRUE.
|
|---|
| 5400 | */
|
|---|
| 5401 | bool QDomEntity::isEntity() const
|
|---|
| 5402 | {
|
|---|
| 5403 | return TRUE;
|
|---|
| 5404 | }
|
|---|
| 5405 |
|
|---|
| 5406 | #undef IMPL
|
|---|
| 5407 |
|
|---|
| 5408 | /**************************************************************
|
|---|
| 5409 | *
|
|---|
| 5410 | * QDomEntityReferencePrivate
|
|---|
| 5411 | *
|
|---|
| 5412 | **************************************************************/
|
|---|
| 5413 |
|
|---|
| 5414 | QDomEntityReferencePrivate::QDomEntityReferencePrivate( QDomDocumentPrivate* d, QDomNodePrivate* parent, const QString& aname )
|
|---|
| 5415 | : QDomNodePrivate( d, parent )
|
|---|
| 5416 | {
|
|---|
| 5417 | name = aname;
|
|---|
| 5418 | }
|
|---|
| 5419 |
|
|---|
| 5420 | QDomEntityReferencePrivate::QDomEntityReferencePrivate( QDomNodePrivate* n, bool deep )
|
|---|
| 5421 | : QDomNodePrivate( n, deep )
|
|---|
| 5422 | {
|
|---|
| 5423 | }
|
|---|
| 5424 |
|
|---|
| 5425 | QDomEntityReferencePrivate::~QDomEntityReferencePrivate()
|
|---|
| 5426 | {
|
|---|
| 5427 | }
|
|---|
| 5428 |
|
|---|
| 5429 | QDomNodePrivate* QDomEntityReferencePrivate::cloneNode( bool deep)
|
|---|
| 5430 | {
|
|---|
| 5431 | QDomNodePrivate* p = new QDomEntityReferencePrivate( this, deep );
|
|---|
| 5432 | // We are not interested in this node
|
|---|
| 5433 | p->deref();
|
|---|
| 5434 | return p;
|
|---|
| 5435 | }
|
|---|
| 5436 |
|
|---|
| 5437 | void QDomEntityReferencePrivate::save( QTextStream& s, int, int ) const
|
|---|
| 5438 | {
|
|---|
| 5439 | s << "&" << name << ";";
|
|---|
| 5440 | }
|
|---|
| 5441 |
|
|---|
| 5442 | /**************************************************************
|
|---|
| 5443 | *
|
|---|
| 5444 | * QDomEntityReference
|
|---|
| 5445 | *
|
|---|
| 5446 | **************************************************************/
|
|---|
| 5447 |
|
|---|
| 5448 | #define IMPL ((QDomEntityReferencePrivate*)impl)
|
|---|
| 5449 |
|
|---|
| 5450 | /*!
|
|---|
| 5451 | \class QDomEntityReference qdom.h
|
|---|
| 5452 | \reentrant
|
|---|
| 5453 | \brief The QDomEntityReference class represents an XML entity reference.
|
|---|
| 5454 | \if defined(commercial)
|
|---|
| 5455 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
|---|
| 5456 | \endif
|
|---|
| 5457 |
|
|---|
| 5458 | \module XML
|
|---|
| 5459 | \ingroup xml-tools
|
|---|
| 5460 |
|
|---|
| 5461 | A QDomEntityReference object may be inserted into the DOM tree
|
|---|
| 5462 | when an entity reference is in the source document, or when the
|
|---|
| 5463 | user wishes to insert an entity reference.
|
|---|
| 5464 |
|
|---|
| 5465 | Note that character references and references to predefined
|
|---|
| 5466 | entities are expanded by the XML processor so that characters are
|
|---|
| 5467 | represented by their Unicode equivalent rather than by an entity
|
|---|
| 5468 | reference.
|
|---|
| 5469 |
|
|---|
| 5470 | Moreover, the XML processor may completely expand references to
|
|---|
| 5471 | entities while building the DOM tree, instead of providing
|
|---|
| 5472 | QDomEntityReference objects.
|
|---|
| 5473 |
|
|---|
| 5474 | If it does provide such objects, then for a given entity reference
|
|---|
| 5475 | node, it may be that there is no entity node representing the
|
|---|
| 5476 | referenced entity; but if such an entity exists, then the child
|
|---|
| 5477 | list of the entity reference node is the same as that of the
|
|---|
| 5478 | entity node. As with the entity node, all descendents of the
|
|---|
| 5479 | entity reference are read-only.
|
|---|
| 5480 |
|
|---|
| 5481 | For further information about the Document Object Model see
|
|---|
| 5482 | \link http://www.w3.org/TR/REC-DOM-Level-1/\endlink and
|
|---|
| 5483 | \link http://www.w3.org/TR/DOM-Level-2-Core/\endlink.
|
|---|
| 5484 | For a more general introduction of the DOM implementation see the
|
|---|
| 5485 | QDomDocument documentation.
|
|---|
| 5486 | */
|
|---|
| 5487 |
|
|---|
| 5488 | /*!
|
|---|
| 5489 | Constructs an empty entity reference. Use
|
|---|
| 5490 | QDomDocument::createEntityReference() to create a entity reference
|
|---|
| 5491 | with content.
|
|---|
| 5492 | */
|
|---|
| 5493 | QDomEntityReference::QDomEntityReference()
|
|---|
| 5494 | : QDomNode()
|
|---|
| 5495 | {
|
|---|
| 5496 | }
|
|---|
| 5497 |
|
|---|
| 5498 | /*!
|
|---|
| 5499 | Constructs a copy of \a x.
|
|---|
| 5500 |
|
|---|
| 5501 | The data of the copy is shared (shallow copy): modifying one node
|
|---|
| 5502 | will also change the other. If you want to make a deep copy, use
|
|---|
| 5503 | cloneNode().
|
|---|
| 5504 | */
|
|---|
| 5505 | QDomEntityReference::QDomEntityReference( const QDomEntityReference& x )
|
|---|
| 5506 | : QDomNode( x )
|
|---|
| 5507 | {
|
|---|
| 5508 | }
|
|---|
| 5509 |
|
|---|
| 5510 | QDomEntityReference::QDomEntityReference( QDomEntityReferencePrivate* n )
|
|---|
| 5511 | : QDomNode( n )
|
|---|
| 5512 | {
|
|---|
| 5513 | }
|
|---|
| 5514 |
|
|---|
| 5515 | /*!
|
|---|
| 5516 | Assigns \a x to this entity reference.
|
|---|
| 5517 |
|
|---|
| 5518 | The data of the copy is shared (shallow copy): modifying one node
|
|---|
| 5519 | will also change the other. If you want to make a deep copy, use
|
|---|
| 5520 | cloneNode().
|
|---|
| 5521 | */
|
|---|
| 5522 | QDomEntityReference& QDomEntityReference::operator= ( const QDomEntityReference& x )
|
|---|
| 5523 | {
|
|---|
| 5524 | return (QDomEntityReference&) QDomNode::operator=( x );
|
|---|
| 5525 | }
|
|---|
| 5526 |
|
|---|
| 5527 | /*!
|
|---|
| 5528 | Destroys the object and frees its resources.
|
|---|
| 5529 | */
|
|---|
| 5530 | QDomEntityReference::~QDomEntityReference()
|
|---|
| 5531 | {
|
|---|
| 5532 | }
|
|---|
| 5533 |
|
|---|
| 5534 | /*!
|
|---|
| 5535 | Returns \c EntityReference.
|
|---|
| 5536 | */
|
|---|
| 5537 | QDomNode::NodeType QDomEntityReference::nodeType() const
|
|---|
| 5538 | {
|
|---|
| 5539 | return EntityReferenceNode;
|
|---|
| 5540 | }
|
|---|
| 5541 |
|
|---|
| 5542 | /*!
|
|---|
| 5543 | Returns TRUE.
|
|---|
| 5544 | */
|
|---|
| 5545 | bool QDomEntityReference::isEntityReference() const
|
|---|
| 5546 | {
|
|---|
| 5547 | return TRUE;
|
|---|
| 5548 | }
|
|---|
| 5549 |
|
|---|
| 5550 | #undef IMPL
|
|---|
| 5551 |
|
|---|
| 5552 | /**************************************************************
|
|---|
| 5553 | *
|
|---|
| 5554 | * QDomProcessingInstructionPrivate
|
|---|
| 5555 | *
|
|---|
| 5556 | **************************************************************/
|
|---|
| 5557 |
|
|---|
| 5558 | QDomProcessingInstructionPrivate::QDomProcessingInstructionPrivate( QDomDocumentPrivate* d,
|
|---|
| 5559 | QDomNodePrivate* parent, const QString& target, const QString& data )
|
|---|
| 5560 | : QDomNodePrivate( d, parent )
|
|---|
| 5561 | {
|
|---|
| 5562 | name = target;
|
|---|
| 5563 | value = data;
|
|---|
| 5564 | }
|
|---|
| 5565 |
|
|---|
| 5566 | QDomProcessingInstructionPrivate::QDomProcessingInstructionPrivate( QDomProcessingInstructionPrivate* n, bool deep )
|
|---|
| 5567 | : QDomNodePrivate( n, deep )
|
|---|
| 5568 | {
|
|---|
| 5569 | }
|
|---|
| 5570 |
|
|---|
| 5571 | QDomProcessingInstructionPrivate::~QDomProcessingInstructionPrivate()
|
|---|
| 5572 | {
|
|---|
| 5573 | }
|
|---|
| 5574 |
|
|---|
| 5575 | QDomNodePrivate* QDomProcessingInstructionPrivate::cloneNode( bool deep)
|
|---|
| 5576 | {
|
|---|
| 5577 | QDomNodePrivate* p = new QDomProcessingInstructionPrivate( this, deep );
|
|---|
| 5578 | // We are not interested in this node
|
|---|
| 5579 | p->deref();
|
|---|
| 5580 | return p;
|
|---|
| 5581 | }
|
|---|
| 5582 |
|
|---|
| 5583 | void QDomProcessingInstructionPrivate::save( QTextStream& s, int, int ) const
|
|---|
| 5584 | {
|
|---|
| 5585 | s << "<?" << name << " " << value << "?>" << endl;
|
|---|
| 5586 | }
|
|---|
| 5587 |
|
|---|
| 5588 | /**************************************************************
|
|---|
| 5589 | *
|
|---|
| 5590 | * QDomProcessingInstruction
|
|---|
| 5591 | *
|
|---|
| 5592 | **************************************************************/
|
|---|
| 5593 |
|
|---|
| 5594 | #define IMPL ((QDomProcessingInstructionPrivate*)impl)
|
|---|
| 5595 |
|
|---|
| 5596 | /*!
|
|---|
| 5597 | \class QDomProcessingInstruction qdom.h
|
|---|
| 5598 | \reentrant
|
|---|
| 5599 | \brief The QDomProcessingInstruction class represents an XML processing
|
|---|
| 5600 | instruction.
|
|---|
| 5601 | \if defined(commercial)
|
|---|
| 5602 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
|---|
| 5603 | \endif
|
|---|
| 5604 |
|
|---|
| 5605 | \module XML
|
|---|
| 5606 | \ingroup xml-tools
|
|---|
| 5607 |
|
|---|
| 5608 | Processing instructions are used in XML to keep processor-specific
|
|---|
| 5609 | information in the text of the document.
|
|---|
| 5610 |
|
|---|
| 5611 | The content of the processing instruction is retrieved with data()
|
|---|
| 5612 | and set with setData(). The processing instruction's target is
|
|---|
| 5613 | retrieved with target().
|
|---|
| 5614 |
|
|---|
| 5615 | For further information about the Document Object Model see
|
|---|
| 5616 | \link http://www.w3.org/TR/REC-DOM-Level-1/\endlink and
|
|---|
| 5617 | \link http://www.w3.org/TR/DOM-Level-2-Core/\endlink.
|
|---|
| 5618 | For a more general introduction of the DOM implementation see the
|
|---|
| 5619 | QDomDocument documentation.
|
|---|
| 5620 | */
|
|---|
| 5621 |
|
|---|
| 5622 | /*!
|
|---|
| 5623 | Constructs an empty processing instruction. Use
|
|---|
| 5624 | QDomDocument::createProcessingInstruction() to create a processing
|
|---|
| 5625 | instruction with content.
|
|---|
| 5626 | */
|
|---|
| 5627 | QDomProcessingInstruction::QDomProcessingInstruction()
|
|---|
| 5628 | : QDomNode()
|
|---|
| 5629 | {
|
|---|
| 5630 | }
|
|---|
| 5631 |
|
|---|
| 5632 | /*!
|
|---|
| 5633 | Constructs a copy of \a x.
|
|---|
| 5634 |
|
|---|
| 5635 | The data of the copy is shared (shallow copy): modifying one node
|
|---|
| 5636 | will also change the other. If you want to make a deep copy, use
|
|---|
| 5637 | cloneNode().
|
|---|
| 5638 | */
|
|---|
| 5639 | QDomProcessingInstruction::QDomProcessingInstruction( const QDomProcessingInstruction& x )
|
|---|
| 5640 | : QDomNode( x )
|
|---|
| 5641 | {
|
|---|
| 5642 | }
|
|---|
| 5643 |
|
|---|
| 5644 | QDomProcessingInstruction::QDomProcessingInstruction( QDomProcessingInstructionPrivate* n )
|
|---|
| 5645 | : QDomNode( n )
|
|---|
| 5646 | {
|
|---|
| 5647 | }
|
|---|
| 5648 |
|
|---|
| 5649 | /*!
|
|---|
| 5650 | Assigns \a x to this processing instruction.
|
|---|
| 5651 |
|
|---|
| 5652 | The data of the copy is shared (shallow copy): modifying one node
|
|---|
| 5653 | will also change the other. If you want to make a deep copy, use
|
|---|
| 5654 | cloneNode().
|
|---|
| 5655 | */
|
|---|
| 5656 | QDomProcessingInstruction& QDomProcessingInstruction::operator= ( const QDomProcessingInstruction& x )
|
|---|
| 5657 | {
|
|---|
| 5658 | return (QDomProcessingInstruction&) QDomNode::operator=( x );
|
|---|
| 5659 | }
|
|---|
| 5660 |
|
|---|
| 5661 | /*!
|
|---|
| 5662 | Destroys the object and frees its resources.
|
|---|
| 5663 | */
|
|---|
| 5664 | QDomProcessingInstruction::~QDomProcessingInstruction()
|
|---|
| 5665 | {
|
|---|
| 5666 | }
|
|---|
| 5667 |
|
|---|
| 5668 | /*!
|
|---|
| 5669 | Returns \c ProcessingInstructionNode.
|
|---|
| 5670 | */
|
|---|
| 5671 | QDomNode::NodeType QDomProcessingInstruction::nodeType() const
|
|---|
| 5672 | {
|
|---|
| 5673 | return ProcessingInstructionNode;
|
|---|
| 5674 | }
|
|---|
| 5675 |
|
|---|
| 5676 | /*!
|
|---|
| 5677 | Returns the target of this processing instruction.
|
|---|
| 5678 |
|
|---|
| 5679 | \sa data()
|
|---|
| 5680 | */
|
|---|
| 5681 | QString QDomProcessingInstruction::target() const
|
|---|
| 5682 | {
|
|---|
| 5683 | if ( !impl )
|
|---|
| 5684 | return QString::null;
|
|---|
| 5685 | return impl->nodeName();
|
|---|
| 5686 | }
|
|---|
| 5687 |
|
|---|
| 5688 | /*!
|
|---|
| 5689 | Returns the content of this processing instruction.
|
|---|
| 5690 |
|
|---|
| 5691 | \sa setData() target()
|
|---|
| 5692 | */
|
|---|
| 5693 | QString QDomProcessingInstruction::data() const
|
|---|
| 5694 | {
|
|---|
| 5695 | if ( !impl )
|
|---|
| 5696 | return QString::null;
|
|---|
| 5697 | return impl->nodeValue();
|
|---|
| 5698 | }
|
|---|
| 5699 |
|
|---|
| 5700 | /*!
|
|---|
| 5701 | Sets the data contained in the processing instruction to \a d.
|
|---|
| 5702 |
|
|---|
| 5703 | \sa data()
|
|---|
| 5704 | */
|
|---|
| 5705 | void QDomProcessingInstruction::setData( const QString& d )
|
|---|
| 5706 | {
|
|---|
| 5707 | if ( !impl )
|
|---|
| 5708 | return;
|
|---|
| 5709 | impl->setNodeValue( d );
|
|---|
| 5710 | }
|
|---|
| 5711 |
|
|---|
| 5712 | /*!
|
|---|
| 5713 | Returns TRUE.
|
|---|
| 5714 | */
|
|---|
| 5715 | bool QDomProcessingInstruction::isProcessingInstruction() const
|
|---|
| 5716 | {
|
|---|
| 5717 | return TRUE;
|
|---|
| 5718 | }
|
|---|
| 5719 |
|
|---|
| 5720 | #undef IMPL
|
|---|
| 5721 |
|
|---|
| 5722 | /**************************************************************
|
|---|
| 5723 | *
|
|---|
| 5724 | * QDomDocumentPrivate
|
|---|
| 5725 | *
|
|---|
| 5726 | **************************************************************/
|
|---|
| 5727 |
|
|---|
| 5728 | QDomDocumentPrivate::QDomDocumentPrivate()
|
|---|
| 5729 | : QDomNodePrivate( 0 )
|
|---|
| 5730 | {
|
|---|
| 5731 | impl = new QDomImplementationPrivate();
|
|---|
| 5732 | type = new QDomDocumentTypePrivate( this, this );
|
|---|
| 5733 |
|
|---|
| 5734 | name = "#document";
|
|---|
| 5735 | }
|
|---|
| 5736 |
|
|---|
| 5737 | QDomDocumentPrivate::QDomDocumentPrivate( const QString& aname )
|
|---|
| 5738 | : QDomNodePrivate( 0 )
|
|---|
| 5739 | {
|
|---|
| 5740 | impl = new QDomImplementationPrivate();
|
|---|
| 5741 | type = new QDomDocumentTypePrivate( this, this );
|
|---|
| 5742 | type->name = aname;
|
|---|
| 5743 |
|
|---|
| 5744 | name = "#document";
|
|---|
| 5745 | }
|
|---|
| 5746 |
|
|---|
| 5747 | QDomDocumentPrivate::QDomDocumentPrivate( QDomDocumentTypePrivate* dt )
|
|---|
| 5748 | : QDomNodePrivate( 0 )
|
|---|
| 5749 | {
|
|---|
| 5750 | impl = new QDomImplementationPrivate();
|
|---|
| 5751 | if ( dt != 0 ) {
|
|---|
| 5752 | type = dt;
|
|---|
| 5753 | type->ref();
|
|---|
| 5754 | } else {
|
|---|
| 5755 | type = new QDomDocumentTypePrivate( this, this );
|
|---|
| 5756 | }
|
|---|
| 5757 |
|
|---|
| 5758 | name = "#document";
|
|---|
| 5759 | }
|
|---|
| 5760 |
|
|---|
| 5761 | QDomDocumentPrivate::QDomDocumentPrivate( QDomDocumentPrivate* n, bool deep )
|
|---|
| 5762 | : QDomNodePrivate( n, deep )
|
|---|
| 5763 | {
|
|---|
| 5764 | impl = n->impl->clone();
|
|---|
| 5765 | // Reference count is down to 0, so we set it to 1 here.
|
|---|
| 5766 | impl->ref();
|
|---|
| 5767 | type = (QDomDocumentTypePrivate*)n->type->cloneNode();
|
|---|
| 5768 | type->setParent( this );
|
|---|
| 5769 | // Reference count is down to 0, so we set it to 1 here.
|
|---|
| 5770 | type->ref();
|
|---|
| 5771 | }
|
|---|
| 5772 |
|
|---|
| 5773 | QDomDocumentPrivate::~QDomDocumentPrivate()
|
|---|
| 5774 | {
|
|---|
| 5775 | if ( impl->deref() ) delete impl;
|
|---|
| 5776 | if ( type->deref() ) delete type;
|
|---|
| 5777 | }
|
|---|
| 5778 |
|
|---|
| 5779 | void QDomDocumentPrivate::clear()
|
|---|
| 5780 | {
|
|---|
| 5781 | if ( impl->deref() ) delete impl;
|
|---|
| 5782 | if ( type->deref() ) delete type;
|
|---|
| 5783 | impl = 0;
|
|---|
| 5784 | type = 0;
|
|---|
| 5785 | QDomNodePrivate::clear();
|
|---|
| 5786 | }
|
|---|
| 5787 |
|
|---|
| 5788 | bool QDomDocumentPrivate::setContent( QXmlInputSource *source, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn )
|
|---|
| 5789 | {
|
|---|
| 5790 | QXmlSimpleReader reader;
|
|---|
| 5791 | if ( namespaceProcessing ) {
|
|---|
| 5792 | reader.setFeature( "http://xml.org/sax/features/namespaces", TRUE );
|
|---|
| 5793 | reader.setFeature( "http://xml.org/sax/features/namespace-prefixes", FALSE );
|
|---|
| 5794 | } else {
|
|---|
| 5795 | reader.setFeature( "http://xml.org/sax/features/namespaces", FALSE );
|
|---|
| 5796 | reader.setFeature( "http://xml.org/sax/features/namespace-prefixes", TRUE );
|
|---|
| 5797 | }
|
|---|
| 5798 | reader.setFeature( "http://trolltech.com/xml/features/report-whitespace-only-CharData", FALSE );
|
|---|
| 5799 |
|
|---|
| 5800 | return setContent( source, &reader, errorMsg, errorLine, errorColumn );
|
|---|
| 5801 | }
|
|---|
| 5802 |
|
|---|
| 5803 | bool QDomDocumentPrivate::setContent( QXmlInputSource *source, QXmlReader *reader, QString *errorMsg, int *errorLine, int *errorColumn )
|
|---|
| 5804 | {
|
|---|
| 5805 | clear();
|
|---|
| 5806 | impl = new QDomImplementationPrivate;
|
|---|
| 5807 | type = new QDomDocumentTypePrivate( this, this );
|
|---|
| 5808 |
|
|---|
| 5809 | bool namespaceProcessing = reader->feature( "http://xml.org/sax/features/namespaces" )
|
|---|
| 5810 | && !reader->feature( "http://xml.org/sax/features/namespace-prefixes" );
|
|---|
| 5811 |
|
|---|
| 5812 | QDomHandler hnd( this, namespaceProcessing );
|
|---|
| 5813 | reader->setContentHandler( &hnd );
|
|---|
| 5814 | reader->setErrorHandler( &hnd );
|
|---|
| 5815 | reader->setLexicalHandler( &hnd );
|
|---|
| 5816 | reader->setDeclHandler( &hnd );
|
|---|
| 5817 | reader->setDTDHandler( &hnd );
|
|---|
| 5818 |
|
|---|
| 5819 | if ( !reader->parse( source ) ) {
|
|---|
| 5820 | if ( errorMsg )
|
|---|
| 5821 | *errorMsg = hnd.errorMsg;
|
|---|
| 5822 | if ( errorLine )
|
|---|
| 5823 | *errorLine = hnd.errorLine;
|
|---|
| 5824 | if ( errorColumn )
|
|---|
| 5825 | *errorColumn = hnd.errorColumn;
|
|---|
| 5826 | return FALSE;
|
|---|
| 5827 | }
|
|---|
| 5828 |
|
|---|
| 5829 | return TRUE;
|
|---|
| 5830 | }
|
|---|
| 5831 |
|
|---|
| 5832 | QDomNodePrivate* QDomDocumentPrivate::cloneNode( bool deep)
|
|---|
| 5833 | {
|
|---|
| 5834 | QDomNodePrivate* p = new QDomDocumentPrivate( this, deep );
|
|---|
| 5835 | // We are not interested in this node
|
|---|
| 5836 | p->deref();
|
|---|
| 5837 | return p;
|
|---|
| 5838 | }
|
|---|
| 5839 |
|
|---|
| 5840 | QDomElementPrivate* QDomDocumentPrivate::documentElement()
|
|---|
| 5841 | {
|
|---|
| 5842 | QDomNodePrivate* p = first;
|
|---|
| 5843 | while ( p && !p->isElement() )
|
|---|
| 5844 | p = p->next;
|
|---|
| 5845 |
|
|---|
| 5846 | return (QDomElementPrivate*)p;
|
|---|
| 5847 | }
|
|---|
| 5848 |
|
|---|
| 5849 | QDomElementPrivate* QDomDocumentPrivate::createElement( const QString& tagName )
|
|---|
| 5850 | {
|
|---|
| 5851 | QDomElementPrivate* e = new QDomElementPrivate( this, 0, tagName );
|
|---|
| 5852 | e->deref();
|
|---|
| 5853 | return e;
|
|---|
| 5854 | }
|
|---|
| 5855 |
|
|---|
| 5856 | QDomElementPrivate* QDomDocumentPrivate::createElementNS( const QString& nsURI, const QString& qName )
|
|---|
| 5857 | {
|
|---|
| 5858 | QDomElementPrivate* e = new QDomElementPrivate( this, 0, nsURI, qName );
|
|---|
| 5859 | e->deref();
|
|---|
| 5860 | return e;
|
|---|
| 5861 | }
|
|---|
| 5862 |
|
|---|
| 5863 | QDomDocumentFragmentPrivate* QDomDocumentPrivate::createDocumentFragment()
|
|---|
| 5864 | {
|
|---|
| 5865 | QDomDocumentFragmentPrivate* f = new QDomDocumentFragmentPrivate( this, (QDomNodePrivate*)0 );
|
|---|
| 5866 | f->deref();
|
|---|
| 5867 | return f;
|
|---|
| 5868 | }
|
|---|
| 5869 |
|
|---|
| 5870 | QDomTextPrivate* QDomDocumentPrivate::createTextNode( const QString& data )
|
|---|
| 5871 | {
|
|---|
| 5872 | QDomTextPrivate* t = new QDomTextPrivate( this, 0, data );
|
|---|
| 5873 | t->deref();
|
|---|
| 5874 | return t;
|
|---|
| 5875 | }
|
|---|
| 5876 |
|
|---|
| 5877 | QDomCommentPrivate* QDomDocumentPrivate::createComment( const QString& data )
|
|---|
| 5878 | {
|
|---|
| 5879 | QDomCommentPrivate* c = new QDomCommentPrivate( this, 0, data );
|
|---|
| 5880 | c->deref();
|
|---|
| 5881 | return c;
|
|---|
| 5882 | }
|
|---|
| 5883 |
|
|---|
| 5884 | QDomCDATASectionPrivate* QDomDocumentPrivate::createCDATASection( const QString& data )
|
|---|
| 5885 | {
|
|---|
| 5886 | QDomCDATASectionPrivate* c = new QDomCDATASectionPrivate( this, 0, data );
|
|---|
| 5887 | c->deref();
|
|---|
| 5888 | return c;
|
|---|
| 5889 | }
|
|---|
| 5890 |
|
|---|
| 5891 | QDomProcessingInstructionPrivate* QDomDocumentPrivate::createProcessingInstruction( const QString& target, const QString& data )
|
|---|
| 5892 | {
|
|---|
| 5893 | QDomProcessingInstructionPrivate* p = new QDomProcessingInstructionPrivate( this, 0, target, data );
|
|---|
| 5894 | p->deref();
|
|---|
| 5895 | return p;
|
|---|
| 5896 | }
|
|---|
| 5897 |
|
|---|
| 5898 | QDomAttrPrivate* QDomDocumentPrivate::createAttribute( const QString& aname )
|
|---|
| 5899 | {
|
|---|
| 5900 | QDomAttrPrivate* a = new QDomAttrPrivate( this, 0, aname );
|
|---|
| 5901 | a->deref();
|
|---|
| 5902 | return a;
|
|---|
| 5903 | }
|
|---|
| 5904 |
|
|---|
| 5905 | QDomAttrPrivate* QDomDocumentPrivate::createAttributeNS( const QString& nsURI, const QString& qName )
|
|---|
| 5906 | {
|
|---|
| 5907 | QDomAttrPrivate* a = new QDomAttrPrivate( this, 0, nsURI, qName );
|
|---|
| 5908 | a->deref();
|
|---|
| 5909 | return a;
|
|---|
| 5910 | }
|
|---|
| 5911 |
|
|---|
| 5912 | QDomEntityReferencePrivate* QDomDocumentPrivate::createEntityReference( const QString& aname )
|
|---|
| 5913 | {
|
|---|
| 5914 | QDomEntityReferencePrivate* e = new QDomEntityReferencePrivate( this, 0, aname );
|
|---|
| 5915 | e->deref();
|
|---|
| 5916 | return e;
|
|---|
| 5917 | }
|
|---|
| 5918 |
|
|---|
| 5919 | QDomNodePrivate* QDomDocumentPrivate::importNode( const QDomNodePrivate* importedNode, bool deep )
|
|---|
| 5920 | {
|
|---|
| 5921 | QDomNodePrivate *node = 0;
|
|---|
| 5922 | switch ( importedNode->nodeType() ) {
|
|---|
| 5923 | case QDomNode::AttributeNode:
|
|---|
| 5924 | node = new QDomAttrPrivate( (QDomAttrPrivate*)importedNode, TRUE );
|
|---|
| 5925 | break;
|
|---|
| 5926 | case QDomNode::DocumentFragmentNode:
|
|---|
| 5927 | node = new QDomDocumentFragmentPrivate( (QDomDocumentFragmentPrivate*)importedNode, deep );
|
|---|
| 5928 | break;
|
|---|
| 5929 | case QDomNode::ElementNode:
|
|---|
| 5930 | node = new QDomElementPrivate( (QDomElementPrivate*)importedNode, deep );
|
|---|
| 5931 | break;
|
|---|
| 5932 | case QDomNode::EntityNode:
|
|---|
| 5933 | node = new QDomEntityPrivate( (QDomEntityPrivate*)importedNode, deep );
|
|---|
| 5934 | break;
|
|---|
| 5935 | case QDomNode::EntityReferenceNode:
|
|---|
| 5936 | node = new QDomEntityReferencePrivate( (QDomEntityReferencePrivate*)importedNode, FALSE );
|
|---|
| 5937 | break;
|
|---|
| 5938 | case QDomNode::NotationNode:
|
|---|
| 5939 | node = new QDomNotationPrivate( (QDomNotationPrivate*)importedNode, deep );
|
|---|
| 5940 | break;
|
|---|
| 5941 | case QDomNode::ProcessingInstructionNode:
|
|---|
| 5942 | node = new QDomProcessingInstructionPrivate( (QDomProcessingInstructionPrivate*)importedNode, deep );
|
|---|
| 5943 | break;
|
|---|
| 5944 | case QDomNode::TextNode:
|
|---|
| 5945 | node = new QDomTextPrivate( (QDomTextPrivate*)importedNode, deep );
|
|---|
| 5946 | break;
|
|---|
| 5947 | case QDomNode::CDATASectionNode:
|
|---|
| 5948 | node = new QDomCDATASectionPrivate( (QDomCDATASectionPrivate*)importedNode, deep );
|
|---|
| 5949 | break;
|
|---|
| 5950 | case QDomNode::CommentNode:
|
|---|
| 5951 | node = new QDomCommentPrivate( (QDomCommentPrivate*)importedNode, deep );
|
|---|
| 5952 | break;
|
|---|
| 5953 | default:
|
|---|
| 5954 | break;
|
|---|
| 5955 | }
|
|---|
| 5956 | if ( node ) {
|
|---|
| 5957 | node->setOwnerDocument( this );
|
|---|
| 5958 | // The QDomNode constructor increases the refcount, so deref() first to
|
|---|
| 5959 | // keep refcount balanced.
|
|---|
| 5960 | node->deref();
|
|---|
| 5961 | }
|
|---|
| 5962 | return node;
|
|---|
| 5963 | }
|
|---|
| 5964 |
|
|---|
| 5965 | void QDomDocumentPrivate::save( QTextStream& s, int, int indent ) const
|
|---|
| 5966 | {
|
|---|
| 5967 | bool doc = FALSE;
|
|---|
| 5968 |
|
|---|
| 5969 | QDomNodePrivate* n = first;
|
|---|
| 5970 | if ( n && n->isProcessingInstruction() && n->nodeName()=="xml" ) {
|
|---|
| 5971 | // we have an XML declaration
|
|---|
| 5972 | QString data = n->nodeValue();
|
|---|
| 5973 | QRegExp encoding( QString::fromLatin1("encoding\\s*=\\s*((\"([^\"]*)\")|('([^']*)'))") );
|
|---|
| 5974 | encoding.search( data );
|
|---|
| 5975 | QString enc = encoding.cap(3);
|
|---|
| 5976 | if ( enc.isEmpty() ) {
|
|---|
| 5977 | enc = encoding.cap(5);
|
|---|
| 5978 | }
|
|---|
| 5979 | if ( enc.isEmpty() ) {
|
|---|
| 5980 | s.setEncoding( QTextStream::UnicodeUTF8 );
|
|---|
| 5981 | } else {
|
|---|
| 5982 | s.setCodec( QTextCodec::codecForName( enc ) );
|
|---|
| 5983 | }
|
|---|
| 5984 | } else {
|
|---|
| 5985 | s.setEncoding( QTextStream::UnicodeUTF8 );
|
|---|
| 5986 | }
|
|---|
| 5987 | while ( n ) {
|
|---|
| 5988 | if ( !doc && !(n->isProcessingInstruction()&&n->nodeName()=="xml") ) {
|
|---|
| 5989 | // save doctype after XML declaration
|
|---|
| 5990 | type->save( s, 0, indent );
|
|---|
| 5991 | doc = TRUE;
|
|---|
| 5992 | }
|
|---|
| 5993 | n->save( s, 0, indent );
|
|---|
| 5994 | n = n->next;
|
|---|
| 5995 | }
|
|---|
| 5996 | }
|
|---|
| 5997 |
|
|---|
| 5998 | /**************************************************************
|
|---|
| 5999 | *
|
|---|
| 6000 | * QDomDocument
|
|---|
| 6001 | *
|
|---|
| 6002 | **************************************************************/
|
|---|
| 6003 |
|
|---|
| 6004 | #define IMPL ((QDomDocumentPrivate*)impl)
|
|---|
| 6005 |
|
|---|
| 6006 | /*!
|
|---|
| 6007 | \class QDomDocument qdom.h
|
|---|
| 6008 | \reentrant
|
|---|
| 6009 | \brief The QDomDocument class represents an XML document.
|
|---|
| 6010 | \if defined(commercial)
|
|---|
| 6011 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
|---|
| 6012 | \endif
|
|---|
| 6013 |
|
|---|
| 6014 | \module XML
|
|---|
| 6015 | \ingroup xml-tools
|
|---|
| 6016 |
|
|---|
| 6017 | The QDomDocument class represents the entire XML document.
|
|---|
| 6018 | Conceptually, it is the root of the document tree, and provides
|
|---|
| 6019 | the primary access to the document's data.
|
|---|
| 6020 |
|
|---|
| 6021 | Since elements, text nodes, comments, processing instructions,
|
|---|
| 6022 | etc., cannot exist outside the context of a document, the document
|
|---|
| 6023 | class also contains the factory functions needed to create these
|
|---|
| 6024 | objects. The node objects created have an ownerDocument() function
|
|---|
| 6025 | which associates them with the document within whose context they
|
|---|
| 6026 | were created. The DOM classes that will be used most often are
|
|---|
| 6027 | QDomNode, QDomDocument, QDomElement and QDomText.
|
|---|
| 6028 |
|
|---|
| 6029 | The parsed XML is represented internally by a tree of objects that
|
|---|
| 6030 | can be accessed using the various QDom classes. All QDom classes
|
|---|
| 6031 | only \e reference objects in the internal tree. The internal
|
|---|
| 6032 | objects in the DOM tree will get deleted once the last QDom
|
|---|
| 6033 | object referencing them and the QDomDocument itself are deleted.
|
|---|
| 6034 |
|
|---|
| 6035 | Creation of elements, text nodes, etc. is done using the various
|
|---|
| 6036 | factory functions provided in this class. Using the default
|
|---|
| 6037 | constructors of the QDom classes will only result in empty
|
|---|
| 6038 | objects that cannot be manipulated or inserted into the Document.
|
|---|
| 6039 |
|
|---|
| 6040 | The QDomDocument class has several functions for creating document
|
|---|
| 6041 | data, for example, createElement(), createTextNode(),
|
|---|
| 6042 | createComment(), createCDATASection(),
|
|---|
| 6043 | createProcessingInstruction(), createAttribute() and
|
|---|
| 6044 | createEntityReference(). Some of these functions have versions
|
|---|
| 6045 | that support namespaces, i.e. createElementNS() and
|
|---|
| 6046 | createAttributeNS(). The createDocumentFragment() function is used
|
|---|
| 6047 | to hold parts of the document; this is useful for manipulating for
|
|---|
| 6048 | complex documents.
|
|---|
| 6049 |
|
|---|
| 6050 | The entire content of the document is set with setContent(). This
|
|---|
| 6051 | function parses the string it is passed as an XML document and
|
|---|
| 6052 | creates the DOM tree that represents the document. The root
|
|---|
| 6053 | element is available using documentElement(). The textual
|
|---|
| 6054 | representation of the document can be obtained using toString().
|
|---|
| 6055 |
|
|---|
| 6056 | It is possible to insert a node from another document into the
|
|---|
| 6057 | document using importNode().
|
|---|
| 6058 |
|
|---|
| 6059 | You can obtain a list of all the elements that have a particular
|
|---|
| 6060 | tag with elementsByTagName() or with elementsByTagNameNS().
|
|---|
| 6061 |
|
|---|
| 6062 | The QDom classes are typically used as follows:
|
|---|
| 6063 | \code
|
|---|
| 6064 | QDomDocument doc( "mydocument" );
|
|---|
| 6065 | QFile file( "mydocument.xml" );
|
|---|
| 6066 | if ( !file.open( IO_ReadOnly ) )
|
|---|
| 6067 | return;
|
|---|
| 6068 | if ( !doc.setContent( &file ) ) {
|
|---|
| 6069 | file.close();
|
|---|
| 6070 | return;
|
|---|
| 6071 | }
|
|---|
| 6072 | file.close();
|
|---|
| 6073 |
|
|---|
| 6074 | // print out the element names of all elements that are direct children
|
|---|
| 6075 | // of the outermost element.
|
|---|
| 6076 | QDomElement docElem = doc.documentElement();
|
|---|
| 6077 |
|
|---|
| 6078 | QDomNode n = docElem.firstChild();
|
|---|
| 6079 | while( !n.isNull() ) {
|
|---|
| 6080 | QDomElement e = n.toElement(); // try to convert the node to an element.
|
|---|
| 6081 | if( !e.isNull() ) {
|
|---|
| 6082 | cout << e.tagName() << endl; // the node really is an element.
|
|---|
| 6083 | }
|
|---|
| 6084 | n = n.nextSibling();
|
|---|
| 6085 | }
|
|---|
| 6086 |
|
|---|
| 6087 | // Here we append a new element to the end of the document
|
|---|
| 6088 | QDomElement elem = doc.createElement( "img" );
|
|---|
| 6089 | elem.setAttribute( "src", "myimage.png" );
|
|---|
| 6090 | docElem.appendChild( elem );
|
|---|
| 6091 | \endcode
|
|---|
| 6092 |
|
|---|
| 6093 | Once \c doc and \c elem go out of scope, the whole internal tree
|
|---|
| 6094 | representing the XML document is deleted.
|
|---|
| 6095 |
|
|---|
| 6096 | To create a document using DOM use code like this:
|
|---|
| 6097 | \code
|
|---|
| 6098 | QDomDocument doc( "MyML" );
|
|---|
| 6099 | QDomElement root = doc.createElement( "MyML" );
|
|---|
| 6100 | doc.appendChild( root );
|
|---|
| 6101 |
|
|---|
| 6102 | QDomElement tag = doc.createElement( "Greeting" );
|
|---|
| 6103 | root.appendChild( tag );
|
|---|
| 6104 |
|
|---|
| 6105 | QDomText t = doc.createTextNode( "Hello World" );
|
|---|
| 6106 | tag.appendChild( t );
|
|---|
| 6107 |
|
|---|
| 6108 | QString xml = doc.toString();
|
|---|
| 6109 | \endcode
|
|---|
| 6110 |
|
|---|
| 6111 | For further information about the Document Object Model see
|
|---|
| 6112 | \link http://www.w3.org/TR/REC-DOM-Level-1/\endlink and
|
|---|
| 6113 | \link http://www.w3.org/TR/DOM-Level-2-Core/\endlink.
|
|---|
| 6114 | For a more general introduction of the DOM implementation see the
|
|---|
| 6115 | QDomDocument documentation.
|
|---|
| 6116 | */
|
|---|
| 6117 |
|
|---|
| 6118 |
|
|---|
| 6119 | /*!
|
|---|
| 6120 | Constructs an empty document.
|
|---|
| 6121 | */
|
|---|
| 6122 | QDomDocument::QDomDocument()
|
|---|
| 6123 | {
|
|---|
| 6124 | impl = new QDomDocumentPrivate;
|
|---|
| 6125 | }
|
|---|
| 6126 |
|
|---|
| 6127 | /*!
|
|---|
| 6128 | Creates a document and sets the name of the document type to \a
|
|---|
| 6129 | name.
|
|---|
| 6130 | */
|
|---|
| 6131 | QDomDocument::QDomDocument( const QString& name )
|
|---|
| 6132 | {
|
|---|
| 6133 | // We take over ownership
|
|---|
| 6134 | impl = new QDomDocumentPrivate( name );
|
|---|
| 6135 | }
|
|---|
| 6136 |
|
|---|
| 6137 | /*!
|
|---|
| 6138 | Creates a document with the document type \a doctype.
|
|---|
| 6139 |
|
|---|
| 6140 | \sa QDomImplementation::createDocumentType()
|
|---|
| 6141 | */
|
|---|
| 6142 | QDomDocument::QDomDocument( const QDomDocumentType& doctype )
|
|---|
| 6143 | {
|
|---|
| 6144 | impl = new QDomDocumentPrivate( (QDomDocumentTypePrivate*)(doctype.impl) );
|
|---|
| 6145 | }
|
|---|
| 6146 |
|
|---|
| 6147 | /*!
|
|---|
| 6148 | Constructs a copy of \a x.
|
|---|
| 6149 |
|
|---|
| 6150 | The data of the copy is shared (shallow copy): modifying one node
|
|---|
| 6151 | will also change the other. If you want to make a deep copy, use
|
|---|
| 6152 | cloneNode().
|
|---|
| 6153 | */
|
|---|
| 6154 | QDomDocument::QDomDocument( const QDomDocument& x )
|
|---|
| 6155 | : QDomNode( x )
|
|---|
| 6156 | {
|
|---|
| 6157 | }
|
|---|
| 6158 |
|
|---|
| 6159 | QDomDocument::QDomDocument( QDomDocumentPrivate* x )
|
|---|
| 6160 | : QDomNode( x )
|
|---|
| 6161 | {
|
|---|
| 6162 | }
|
|---|
| 6163 |
|
|---|
| 6164 | /*!
|
|---|
| 6165 | Assigns \a x to this DOM document.
|
|---|
| 6166 |
|
|---|
| 6167 | The data of the copy is shared (shallow copy): modifying one node
|
|---|
| 6168 | will also change the other. If you want to make a deep copy, use
|
|---|
| 6169 | cloneNode().
|
|---|
| 6170 | */
|
|---|
| 6171 | QDomDocument& QDomDocument::operator= ( const QDomDocument& x )
|
|---|
| 6172 | {
|
|---|
| 6173 | return (QDomDocument&) QDomNode::operator=( x );
|
|---|
| 6174 | }
|
|---|
| 6175 |
|
|---|
| 6176 | /*!
|
|---|
| 6177 | Destroys the object and frees its resources.
|
|---|
| 6178 | */
|
|---|
| 6179 | QDomDocument::~QDomDocument()
|
|---|
| 6180 | {
|
|---|
| 6181 | }
|
|---|
| 6182 |
|
|---|
| 6183 | /*!
|
|---|
| 6184 | \overload
|
|---|
| 6185 |
|
|---|
| 6186 | This function reads the XML document from the string \a text.
|
|---|
| 6187 | Since \a text is already a Unicode string, no encoding detection
|
|---|
| 6188 | is done.
|
|---|
| 6189 | */
|
|---|
| 6190 | bool QDomDocument::setContent( const QString& text, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn )
|
|---|
| 6191 | {
|
|---|
| 6192 | if ( !impl )
|
|---|
| 6193 | impl = new QDomDocumentPrivate;
|
|---|
| 6194 | QXmlInputSource source;
|
|---|
| 6195 | source.setData( text );
|
|---|
| 6196 | return IMPL->setContent( &source, namespaceProcessing, errorMsg, errorLine, errorColumn );
|
|---|
| 6197 | }
|
|---|
| 6198 |
|
|---|
| 6199 | /*!
|
|---|
| 6200 | This function parses the XML document from the byte array \a
|
|---|
| 6201 | buffer and sets it as the content of the document. It tries to
|
|---|
| 6202 | detect the encoding of the document as required by the XML
|
|---|
| 6203 | specification.
|
|---|
| 6204 |
|
|---|
| 6205 | If \a namespaceProcessing is TRUE, the parser recognizes
|
|---|
| 6206 | namespaces in the XML file and sets the prefix name, local name
|
|---|
| 6207 | and namespace URI to appropriate values. If \a namespaceProcessing
|
|---|
| 6208 | is FALSE, the parser does no namespace processing when it reads
|
|---|
| 6209 | the XML file.
|
|---|
| 6210 |
|
|---|
| 6211 | If a parse error occurs, the function returns FALSE; otherwise it
|
|---|
| 6212 | returns TRUE. If a parse error occurs and \a errorMsg, \a
|
|---|
| 6213 | errorLine and \a errorColumn are not 0, the error message is
|
|---|
| 6214 | placed in \a *errorMsg, the line number \a *errorLine and the
|
|---|
| 6215 | column number in \a *errorColumn.
|
|---|
| 6216 |
|
|---|
| 6217 | If \a namespaceProcessing is TRUE, the function QDomNode::prefix()
|
|---|
| 6218 | returns a string for all elements and attributes. It returns an
|
|---|
| 6219 | empty string if the element or attribute has no prefix.
|
|---|
| 6220 |
|
|---|
| 6221 | If \a namespaceProcessing is FALSE, the functions
|
|---|
| 6222 | QDomNode::prefix(), QDomNode::localName() and
|
|---|
| 6223 | QDomNode::namespaceURI() return QString::null.
|
|---|
| 6224 |
|
|---|
| 6225 | \sa QDomNode::namespaceURI() QDomNode::localName()
|
|---|
| 6226 | QDomNode::prefix() QString::isNull() QString::isEmpty()
|
|---|
| 6227 | */
|
|---|
| 6228 | bool QDomDocument::setContent( const QByteArray& buffer, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn )
|
|---|
| 6229 | {
|
|---|
| 6230 | if ( !impl )
|
|---|
| 6231 | impl = new QDomDocumentPrivate;
|
|---|
| 6232 | QBuffer buf( buffer );
|
|---|
| 6233 | QXmlInputSource source( &buf );
|
|---|
| 6234 | return IMPL->setContent( &source, namespaceProcessing, errorMsg, errorLine, errorColumn );
|
|---|
| 6235 | }
|
|---|
| 6236 |
|
|---|
| 6237 | /*!
|
|---|
| 6238 | \overload
|
|---|
| 6239 |
|
|---|
| 6240 | This function reads the XML document from the C string \a buffer.
|
|---|
| 6241 |
|
|---|
| 6242 | \warning This function does not try to detect the encoding:
|
|---|
| 6243 | instead it assumes that the C string is UTF-8 encoded.
|
|---|
| 6244 | */
|
|---|
| 6245 | bool QDomDocument::setContent( const QCString& buffer, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn )
|
|---|
| 6246 | {
|
|---|
| 6247 | return setContent( QString::fromUtf8( buffer, buffer.length() ), namespaceProcessing, errorMsg, errorLine, errorColumn );
|
|---|
| 6248 | }
|
|---|
| 6249 |
|
|---|
| 6250 | /*!
|
|---|
| 6251 | \overload
|
|---|
| 6252 |
|
|---|
| 6253 | This function reads the XML document from the IO device \a dev.
|
|---|
| 6254 | */
|
|---|
| 6255 | bool QDomDocument::setContent( QIODevice* dev, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn )
|
|---|
| 6256 | {
|
|---|
| 6257 | if ( !impl )
|
|---|
| 6258 | impl = new QDomDocumentPrivate;
|
|---|
| 6259 | QXmlInputSource source( dev );
|
|---|
| 6260 | return IMPL->setContent( &source, namespaceProcessing, errorMsg, errorLine, errorColumn );
|
|---|
| 6261 | }
|
|---|
| 6262 |
|
|---|
| 6263 | /*!
|
|---|
| 6264 | \overload
|
|---|
| 6265 |
|
|---|
| 6266 | This function reads the XML document from the string \a text.
|
|---|
| 6267 | Since \a text is already a Unicode string, no encoding detection
|
|---|
| 6268 | is performed.
|
|---|
| 6269 |
|
|---|
| 6270 | No namespace processing is performed either.
|
|---|
| 6271 | */
|
|---|
| 6272 | bool QDomDocument::setContent( const QString& text, QString *errorMsg, int *errorLine, int *errorColumn )
|
|---|
| 6273 | {
|
|---|
| 6274 | return setContent( text, FALSE, errorMsg, errorLine, errorColumn );
|
|---|
| 6275 | }
|
|---|
| 6276 |
|
|---|
| 6277 | /*!
|
|---|
| 6278 | \overload
|
|---|
| 6279 |
|
|---|
| 6280 | This function reads the XML document from the byte array \a
|
|---|
| 6281 | buffer.
|
|---|
| 6282 |
|
|---|
| 6283 | No namespace processing is performed.
|
|---|
| 6284 | */
|
|---|
| 6285 | bool QDomDocument::setContent( const QByteArray& buffer, QString *errorMsg, int *errorLine, int *errorColumn )
|
|---|
| 6286 | {
|
|---|
| 6287 | return setContent( buffer, FALSE, errorMsg, errorLine, errorColumn );
|
|---|
| 6288 | }
|
|---|
| 6289 |
|
|---|
| 6290 | /*!
|
|---|
| 6291 | \overload
|
|---|
| 6292 |
|
|---|
| 6293 | This function reads the XML document from the C string \a buffer.
|
|---|
| 6294 |
|
|---|
| 6295 | No namespace processing is performed.
|
|---|
| 6296 |
|
|---|
| 6297 | \warning This function does not try to detect the encoding:
|
|---|
| 6298 | instead it assumes that the C string is UTF-8 encoded.
|
|---|
| 6299 | */
|
|---|
| 6300 | bool QDomDocument::setContent( const QCString& buffer, QString *errorMsg, int *errorLine, int *errorColumn )
|
|---|
| 6301 | {
|
|---|
| 6302 | return setContent( buffer, FALSE, errorMsg, errorLine, errorColumn );
|
|---|
| 6303 | }
|
|---|
| 6304 |
|
|---|
| 6305 | /*!
|
|---|
| 6306 | \overload
|
|---|
| 6307 |
|
|---|
| 6308 | This function reads the XML document from the IO device \a dev.
|
|---|
| 6309 |
|
|---|
| 6310 | No namespace processing is performed.
|
|---|
| 6311 | */
|
|---|
| 6312 | bool QDomDocument::setContent( QIODevice* dev, QString *errorMsg, int *errorLine, int *errorColumn )
|
|---|
| 6313 | {
|
|---|
| 6314 | return setContent( dev, FALSE, errorMsg, errorLine, errorColumn );
|
|---|
| 6315 | }
|
|---|
| 6316 |
|
|---|
| 6317 | /*!
|
|---|
| 6318 | \overload
|
|---|
| 6319 |
|
|---|
| 6320 | This function reads the XML document from the QXmlInputSource \a source and
|
|---|
| 6321 | parses it with the QXmlReader \a reader.
|
|---|
| 6322 |
|
|---|
| 6323 | This function doesn't change the features of the \a reader. If you want to
|
|---|
| 6324 | use certain features for parsing you can use this function to set up the
|
|---|
| 6325 | reader appropriate.
|
|---|
| 6326 |
|
|---|
| 6327 | \sa QXmlSimpleReader
|
|---|
| 6328 | */
|
|---|
| 6329 | bool QDomDocument::setContent( QXmlInputSource *source, QXmlReader *reader, QString *errorMsg, int *errorLine, int *errorColumn )
|
|---|
| 6330 | {
|
|---|
| 6331 | if ( !impl )
|
|---|
| 6332 | impl = new QDomDocumentPrivate;
|
|---|
| 6333 | return IMPL->setContent( source, reader, errorMsg, errorLine, errorColumn );
|
|---|
| 6334 | }
|
|---|
| 6335 |
|
|---|
| 6336 | /*!
|
|---|
| 6337 | Converts the parsed document back to its textual representation.
|
|---|
| 6338 |
|
|---|
| 6339 | \sa toCString()
|
|---|
| 6340 | */
|
|---|
| 6341 | QString QDomDocument::toString() const
|
|---|
| 6342 | {
|
|---|
| 6343 | QString str;
|
|---|
| 6344 | QTextStream s( str, IO_WriteOnly );
|
|---|
| 6345 | save( s, 1 );
|
|---|
| 6346 |
|
|---|
| 6347 | return str;
|
|---|
| 6348 | }
|
|---|
| 6349 |
|
|---|
| 6350 | /*!
|
|---|
| 6351 | \overload
|
|---|
| 6352 |
|
|---|
| 6353 | This function uses \a indent as the amount of space to indent
|
|---|
| 6354 | subelements.
|
|---|
| 6355 | */
|
|---|
| 6356 | QString QDomDocument::toString( int indent ) const
|
|---|
| 6357 | {
|
|---|
| 6358 | QString str;
|
|---|
| 6359 | QTextStream s( str, IO_WriteOnly );
|
|---|
| 6360 | save( s, indent );
|
|---|
| 6361 |
|
|---|
| 6362 | return str;
|
|---|
| 6363 | }
|
|---|
| 6364 |
|
|---|
| 6365 | /*!
|
|---|
| 6366 | Converts the parsed document back to its textual representation
|
|---|
| 6367 | and returns a QCString for that is encoded in UTF-8.
|
|---|
| 6368 |
|
|---|
| 6369 | \sa toString()
|
|---|
| 6370 | */
|
|---|
| 6371 | QCString QDomDocument::toCString() const
|
|---|
| 6372 | {
|
|---|
| 6373 | // ### if there is an encoding specified in the xml declaration, this
|
|---|
| 6374 | // encoding declaration should be changed to utf8
|
|---|
| 6375 | return toString().utf8();
|
|---|
| 6376 | }
|
|---|
| 6377 |
|
|---|
| 6378 | /*!
|
|---|
| 6379 | \overload
|
|---|
| 6380 |
|
|---|
| 6381 | This function uses \a indent as the amount of space to indent
|
|---|
| 6382 | subelements.
|
|---|
| 6383 | */
|
|---|
| 6384 | QCString QDomDocument::toCString( int indent ) const
|
|---|
| 6385 | {
|
|---|
| 6386 | // ### if there is an encoding specified in the xml declaration, this
|
|---|
| 6387 | // encoding declaration should be changed to utf8
|
|---|
| 6388 | return toString( indent ).utf8();
|
|---|
| 6389 | }
|
|---|
| 6390 |
|
|---|
| 6391 |
|
|---|
| 6392 | /*!
|
|---|
| 6393 | Returns the document type of this document.
|
|---|
| 6394 | */
|
|---|
| 6395 | QDomDocumentType QDomDocument::doctype() const
|
|---|
| 6396 | {
|
|---|
| 6397 | if ( !impl )
|
|---|
| 6398 | return QDomDocumentType();
|
|---|
| 6399 | return QDomDocumentType( IMPL->doctype() );
|
|---|
| 6400 | }
|
|---|
| 6401 |
|
|---|
| 6402 | /*!
|
|---|
| 6403 | Returns a QDomImplementation object.
|
|---|
| 6404 | */
|
|---|
| 6405 | QDomImplementation QDomDocument::implementation() const
|
|---|
| 6406 | {
|
|---|
| 6407 | if ( !impl )
|
|---|
| 6408 | return QDomImplementation();
|
|---|
| 6409 | return QDomImplementation( IMPL->implementation() );
|
|---|
| 6410 | }
|
|---|
| 6411 |
|
|---|
| 6412 | /*!
|
|---|
| 6413 | Returns the root element of the document.
|
|---|
| 6414 | */
|
|---|
| 6415 | QDomElement QDomDocument::documentElement() const
|
|---|
| 6416 | {
|
|---|
| 6417 | if ( !impl )
|
|---|
| 6418 | return QDomElement();
|
|---|
| 6419 | return QDomElement( IMPL->documentElement() );
|
|---|
| 6420 | }
|
|---|
| 6421 |
|
|---|
| 6422 | /*!
|
|---|
| 6423 | Creates a new element called \a tagName that can be inserted into
|
|---|
| 6424 | the DOM tree, e.g. using QDomNode::appendChild().
|
|---|
| 6425 |
|
|---|
| 6426 | \sa createElementNS() QDomNode::appendChild() QDomNode::insertBefore()
|
|---|
| 6427 | QDomNode::insertAfter()
|
|---|
| 6428 | */
|
|---|
| 6429 | QDomElement QDomDocument::createElement( const QString& tagName )
|
|---|
| 6430 | {
|
|---|
| 6431 | if ( !impl )
|
|---|
| 6432 | return QDomElement();
|
|---|
| 6433 | return QDomElement( IMPL->createElement( tagName ) );
|
|---|
| 6434 | }
|
|---|
| 6435 |
|
|---|
| 6436 | /*!
|
|---|
| 6437 | Creates a new document fragment, that can be used to hold parts of
|
|---|
| 6438 | the document, e.g. when doing complex manipulations of the
|
|---|
| 6439 | document tree.
|
|---|
| 6440 | */
|
|---|
| 6441 | QDomDocumentFragment QDomDocument::createDocumentFragment()
|
|---|
| 6442 | {
|
|---|
| 6443 | if ( !impl )
|
|---|
| 6444 | return QDomDocumentFragment();
|
|---|
| 6445 | return QDomDocumentFragment( IMPL->createDocumentFragment() );
|
|---|
| 6446 | }
|
|---|
| 6447 |
|
|---|
| 6448 | /*!
|
|---|
| 6449 | Creates a text node for the string \a value that can be inserted
|
|---|
| 6450 | into the document tree, e.g. using QDomNode::appendChild().
|
|---|
| 6451 |
|
|---|
| 6452 | \sa QDomNode::appendChild() QDomNode::insertBefore() QDomNode::insertAfter()
|
|---|
| 6453 | */
|
|---|
| 6454 | QDomText QDomDocument::createTextNode( const QString& value )
|
|---|
| 6455 | {
|
|---|
| 6456 | if ( !impl )
|
|---|
| 6457 | return QDomText();
|
|---|
| 6458 | return QDomText( IMPL->createTextNode( value ) );
|
|---|
| 6459 | }
|
|---|
| 6460 |
|
|---|
| 6461 | /*!
|
|---|
| 6462 | Creates a new comment for the string \a value that can be inserted
|
|---|
| 6463 | into the document, e.g. using QDomNode::appendChild().
|
|---|
| 6464 |
|
|---|
| 6465 | \sa QDomNode::appendChild() QDomNode::insertBefore() QDomNode::insertAfter()
|
|---|
| 6466 | */
|
|---|
| 6467 | QDomComment QDomDocument::createComment( const QString& value )
|
|---|
| 6468 | {
|
|---|
| 6469 | if ( !impl )
|
|---|
| 6470 | return QDomComment();
|
|---|
| 6471 | return QDomComment( IMPL->createComment( value ) );
|
|---|
| 6472 | }
|
|---|
| 6473 |
|
|---|
| 6474 | /*!
|
|---|
| 6475 | Creates a new CDATA section for the string \a value that can be
|
|---|
| 6476 | inserted into the document, e.g. using QDomNode::appendChild().
|
|---|
| 6477 |
|
|---|
| 6478 | \sa QDomNode::appendChild() QDomNode::insertBefore() QDomNode::insertAfter()
|
|---|
| 6479 | */
|
|---|
| 6480 | QDomCDATASection QDomDocument::createCDATASection( const QString& value )
|
|---|
| 6481 | {
|
|---|
| 6482 | if ( !impl )
|
|---|
| 6483 | return QDomCDATASection();
|
|---|
| 6484 | return QDomCDATASection( IMPL->createCDATASection( value ) );
|
|---|
| 6485 | }
|
|---|
| 6486 |
|
|---|
| 6487 | /*!
|
|---|
| 6488 | Creates a new processing instruction that can be inserted into the
|
|---|
| 6489 | document, e.g. using QDomNode::appendChild(). This function sets
|
|---|
| 6490 | the target for the processing instruction to \a target and the
|
|---|
| 6491 | data to \a data.
|
|---|
| 6492 |
|
|---|
| 6493 | \sa QDomNode::appendChild() QDomNode::insertBefore() QDomNode::insertAfter()
|
|---|
| 6494 | */
|
|---|
| 6495 | QDomProcessingInstruction QDomDocument::createProcessingInstruction( const QString& target,
|
|---|
| 6496 | const QString& data )
|
|---|
| 6497 | {
|
|---|
| 6498 | if ( !impl )
|
|---|
| 6499 | return QDomProcessingInstruction();
|
|---|
| 6500 | return QDomProcessingInstruction( IMPL->createProcessingInstruction( target, data ) );
|
|---|
| 6501 | }
|
|---|
| 6502 |
|
|---|
| 6503 |
|
|---|
| 6504 | /*!
|
|---|
| 6505 | Creates a new attribute called \a name that can be inserted into
|
|---|
| 6506 | an element, e.g. using QDomElement::setAttributeNode().
|
|---|
| 6507 |
|
|---|
| 6508 | \sa createAttributeNS()
|
|---|
| 6509 | */
|
|---|
| 6510 | QDomAttr QDomDocument::createAttribute( const QString& name )
|
|---|
| 6511 | {
|
|---|
| 6512 | if ( !impl )
|
|---|
| 6513 | return QDomAttr();
|
|---|
| 6514 | return QDomAttr( IMPL->createAttribute( name ) );
|
|---|
| 6515 | }
|
|---|
| 6516 |
|
|---|
| 6517 | /*!
|
|---|
| 6518 | Creates a new entity reference called \a name that can be inserted
|
|---|
| 6519 | into the document, e.g. using QDomNode::appendChild().
|
|---|
| 6520 |
|
|---|
| 6521 | \sa QDomNode::appendChild() QDomNode::insertBefore() QDomNode::insertAfter()
|
|---|
| 6522 | */
|
|---|
| 6523 | QDomEntityReference QDomDocument::createEntityReference( const QString& name )
|
|---|
| 6524 | {
|
|---|
| 6525 | if ( !impl )
|
|---|
| 6526 | return QDomEntityReference();
|
|---|
| 6527 | return QDomEntityReference( IMPL->createEntityReference( name ) );
|
|---|
| 6528 | }
|
|---|
| 6529 |
|
|---|
| 6530 | /*!
|
|---|
| 6531 | Returns a QDomNodeList, that contains all the elements in the
|
|---|
| 6532 | document with the name \a tagname. The order of the node list is
|
|---|
| 6533 | the order they are encountered in a preorder traversal of the
|
|---|
| 6534 | element tree.
|
|---|
| 6535 |
|
|---|
| 6536 | \sa elementsByTagNameNS() QDomElement::elementsByTagName()
|
|---|
| 6537 | */
|
|---|
| 6538 | QDomNodeList QDomDocument::elementsByTagName( const QString& tagname ) const
|
|---|
| 6539 | {
|
|---|
| 6540 | return QDomNodeList( new QDomNodeListPrivate( impl, tagname ) );
|
|---|
| 6541 | }
|
|---|
| 6542 |
|
|---|
| 6543 | /*!
|
|---|
| 6544 | Imports the node \a importedNode from another document to this
|
|---|
| 6545 | document. \a importedNode remains in the original document; this
|
|---|
| 6546 | function creates a copy that can be used within this document.
|
|---|
| 6547 |
|
|---|
| 6548 | This function returns the imported node that belongs to this
|
|---|
| 6549 | document. The returned node has no parent. It is not possible to
|
|---|
| 6550 | import QDomDocument and QDomDocumentType nodes. In those cases
|
|---|
| 6551 | this function returns a \link QDomNode::isNull() null node\endlink.
|
|---|
| 6552 |
|
|---|
| 6553 | If \a deep is TRUE, this function imports not only the node \a
|
|---|
| 6554 | importedNode but its whole subtree; if it is FALSE, only the \a
|
|---|
| 6555 | importedNode is imported. The argument \a deep has no effect on
|
|---|
| 6556 | QDomAttr and QDomEntityReference nodes, since the descendents of
|
|---|
| 6557 | QDomAttr nodes are always imported and those of
|
|---|
| 6558 | QDomEntityReference nodes are never imported.
|
|---|
| 6559 |
|
|---|
| 6560 | The behavior of this function is slightly different depending on
|
|---|
| 6561 | the node types:
|
|---|
| 6562 | \table
|
|---|
| 6563 | \header \i Node Type \i Behaviour
|
|---|
| 6564 | \row \i QDomAttr
|
|---|
| 6565 | \i The owner element is set to 0 and the specified flag is
|
|---|
| 6566 | set to TRUE in the generated attribute. The whole subtree
|
|---|
| 6567 | of \a importedNode is always imported for attribute nodes:
|
|---|
| 6568 | \a deep has no effect.
|
|---|
| 6569 | \row \i QDomDocument
|
|---|
| 6570 | \i Document nodes cannot be imported.
|
|---|
| 6571 | \row \i QDomDocumentFragment
|
|---|
| 6572 | \i If \a deep is TRUE, this function imports the whole
|
|---|
| 6573 | document fragment; otherwise it only generates an empty
|
|---|
| 6574 | document fragment.
|
|---|
| 6575 | \row \i QDomDocumentType
|
|---|
| 6576 | \i Document type nodes cannot be imported.
|
|---|
| 6577 | \row \i QDomElement
|
|---|
| 6578 | \i Attributes for which QDomAttr::specified() is TRUE are
|
|---|
| 6579 | also imported, other attributes are not imported. If \a
|
|---|
| 6580 | deep is TRUE, this function also imports the subtree of \a
|
|---|
| 6581 | importedNode; otherwise it imports only the element node
|
|---|
| 6582 | (and some attributes, see above).
|
|---|
| 6583 | \row \i QDomEntity
|
|---|
| 6584 | \i Entity nodes can be imported, but at the moment there is
|
|---|
| 6585 | no way to use them since the document type is read-only in
|
|---|
| 6586 | DOM level 2.
|
|---|
| 6587 | \row \i QDomEntityReference
|
|---|
| 6588 | \i Descendents of entity reference nodes are never imported:
|
|---|
| 6589 | \a deep has no effect.
|
|---|
| 6590 | \row \i QDomNotation
|
|---|
| 6591 | \i Notation nodes can be imported, but at the moment there is
|
|---|
| 6592 | no way to use them since the document type is read-only in
|
|---|
| 6593 | DOM level 2.
|
|---|
| 6594 | \row \i QDomProcessingInstruction
|
|---|
| 6595 | \i The target and value of the processing instruction is
|
|---|
| 6596 | copied to the new node.
|
|---|
| 6597 | \row \i QDomText
|
|---|
| 6598 | \i The text is copied to the new node.
|
|---|
| 6599 | \row \i QDomCDATASection
|
|---|
| 6600 | \i The text is copied to the new node.
|
|---|
| 6601 | \row \i QDomComment
|
|---|
| 6602 | \i The text is copied to the new node.
|
|---|
| 6603 | \endtable
|
|---|
| 6604 |
|
|---|
| 6605 | \sa QDomElement::setAttribute() QDomNode::insertBefore()
|
|---|
| 6606 | QDomNode::insertAfter() QDomNode::replaceChild() QDomNode::removeChild()
|
|---|
| 6607 | QDomNode::appendChild()
|
|---|
| 6608 | */
|
|---|
| 6609 | QDomNode QDomDocument::importNode( const QDomNode& importedNode, bool deep )
|
|---|
| 6610 | {
|
|---|
| 6611 | if ( !impl )
|
|---|
| 6612 | return QDomNode();
|
|---|
| 6613 | return QDomNode( IMPL->importNode( importedNode.impl, deep ) );
|
|---|
| 6614 | }
|
|---|
| 6615 |
|
|---|
| 6616 | /*!
|
|---|
| 6617 | Creates a new element with namespace support that can be inserted
|
|---|
| 6618 | into the DOM tree. The name of the element is \a qName and the
|
|---|
| 6619 | namespace URI is \a nsURI. This function also sets
|
|---|
| 6620 | QDomNode::prefix() and QDomNode::localName() to appropriate values
|
|---|
| 6621 | (depending on \a qName).
|
|---|
| 6622 |
|
|---|
| 6623 | \sa createElement()
|
|---|
| 6624 | */
|
|---|
| 6625 | QDomElement QDomDocument::createElementNS( const QString& nsURI, const QString& qName )
|
|---|
| 6626 | {
|
|---|
| 6627 | if ( !impl )
|
|---|
| 6628 | return QDomElement();
|
|---|
| 6629 | return QDomElement( IMPL->createElementNS( nsURI, qName ) );
|
|---|
| 6630 | }
|
|---|
| 6631 |
|
|---|
| 6632 | /*!
|
|---|
| 6633 | Creates a new attribute with namespace support that can be
|
|---|
| 6634 | inserted into an element. The name of the attribute is \a qName
|
|---|
| 6635 | and the namespace URI is \a nsURI. This function also sets
|
|---|
| 6636 | QDomNode::prefix() and QDomNode::localName() to appropriate values
|
|---|
| 6637 | (depending on \a qName).
|
|---|
| 6638 |
|
|---|
| 6639 | \sa createAttribute()
|
|---|
| 6640 | */
|
|---|
| 6641 | QDomAttr QDomDocument::createAttributeNS( const QString& nsURI, const QString& qName )
|
|---|
| 6642 | {
|
|---|
| 6643 | if ( !impl )
|
|---|
| 6644 | return QDomAttr();
|
|---|
| 6645 | return QDomAttr( IMPL->createAttributeNS( nsURI, qName ) );
|
|---|
| 6646 | }
|
|---|
| 6647 |
|
|---|
| 6648 | /*!
|
|---|
| 6649 | Returns a QDomNodeList that contains all the elements in the
|
|---|
| 6650 | document with the local name \a localName and a namespace URI of
|
|---|
| 6651 | \a nsURI. The order of the node list is the order they are
|
|---|
| 6652 | encountered in a preorder traversal of the element tree.
|
|---|
| 6653 |
|
|---|
| 6654 | \sa elementsByTagName() QDomElement::elementsByTagNameNS()
|
|---|
| 6655 | */
|
|---|
| 6656 | QDomNodeList QDomDocument::elementsByTagNameNS( const QString& nsURI, const QString& localName )
|
|---|
| 6657 | {
|
|---|
| 6658 | return QDomNodeList( new QDomNodeListPrivate( impl, nsURI, localName ) );
|
|---|
| 6659 | }
|
|---|
| 6660 |
|
|---|
| 6661 | /*!
|
|---|
| 6662 | Returns the element whose ID is equal to \a elementId. If no
|
|---|
| 6663 | element with the ID was found, this function returns a \link
|
|---|
| 6664 | QDomNode::isNull() null element\endlink.
|
|---|
| 6665 |
|
|---|
| 6666 | Since the QDomClasses do not know which attributes are element
|
|---|
| 6667 | IDs, this function returns always a \link QDomNode::isNull() null
|
|---|
| 6668 | element\endlink. This may change in a future version.
|
|---|
| 6669 | */
|
|---|
| 6670 | QDomElement QDomDocument::elementById( const QString& /*elementId*/ )
|
|---|
| 6671 | {
|
|---|
| 6672 | return QDomElement();
|
|---|
| 6673 | }
|
|---|
| 6674 |
|
|---|
| 6675 | /*!
|
|---|
| 6676 | Returns \c DocumentNode.
|
|---|
| 6677 | */
|
|---|
| 6678 | QDomNode::NodeType QDomDocument::nodeType() const
|
|---|
| 6679 | {
|
|---|
| 6680 | return DocumentNode;
|
|---|
| 6681 | }
|
|---|
| 6682 |
|
|---|
| 6683 | /*!
|
|---|
| 6684 | Returns TRUE.
|
|---|
| 6685 | */
|
|---|
| 6686 | bool QDomDocument::isDocument() const
|
|---|
| 6687 | {
|
|---|
| 6688 | return TRUE;
|
|---|
| 6689 | }
|
|---|
| 6690 |
|
|---|
| 6691 |
|
|---|
| 6692 | #undef IMPL
|
|---|
| 6693 |
|
|---|
| 6694 | /**************************************************************
|
|---|
| 6695 | *
|
|---|
| 6696 | * Node casting functions
|
|---|
| 6697 | *
|
|---|
| 6698 | **************************************************************/
|
|---|
| 6699 |
|
|---|
| 6700 | /*!
|
|---|
| 6701 | Converts a QDomNode into a QDomAttr. If the node is not an
|
|---|
| 6702 | attribute, the returned object will be \link QDomNode::isNull()
|
|---|
| 6703 | null\endlink.
|
|---|
| 6704 |
|
|---|
| 6705 | \sa isAttr()
|
|---|
| 6706 | */
|
|---|
| 6707 | QDomAttr QDomNode::toAttr()
|
|---|
| 6708 | {
|
|---|
| 6709 | if ( impl && impl->isAttr() )
|
|---|
| 6710 | return QDomAttr( ((QDomAttrPrivate*)impl) );
|
|---|
| 6711 | return QDomAttr();
|
|---|
| 6712 | }
|
|---|
| 6713 |
|
|---|
| 6714 | /*!
|
|---|
| 6715 | Converts a QDomNode into a QDomCDATASection. If the node is not a
|
|---|
| 6716 | CDATA section, the returned object will be \link
|
|---|
| 6717 | QDomNode::isNull() null\endlink.
|
|---|
| 6718 |
|
|---|
| 6719 | \sa isCDATASection()
|
|---|
| 6720 | */
|
|---|
| 6721 | QDomCDATASection QDomNode::toCDATASection()
|
|---|
| 6722 | {
|
|---|
| 6723 | if ( impl && impl->isCDATASection() )
|
|---|
| 6724 | return QDomCDATASection( ((QDomCDATASectionPrivate*)impl) );
|
|---|
| 6725 | return QDomCDATASection();
|
|---|
| 6726 | }
|
|---|
| 6727 |
|
|---|
| 6728 | /*!
|
|---|
| 6729 | Converts a QDomNode into a QDomDocumentFragment. If the node is
|
|---|
| 6730 | not a document fragment the returned object will be \link
|
|---|
| 6731 | QDomNode::isNull() null\endlink.
|
|---|
| 6732 |
|
|---|
| 6733 | \sa isDocumentFragment()
|
|---|
| 6734 | */
|
|---|
| 6735 | QDomDocumentFragment QDomNode::toDocumentFragment()
|
|---|
| 6736 | {
|
|---|
| 6737 | if ( impl && impl->isDocumentFragment() )
|
|---|
| 6738 | return QDomDocumentFragment( ((QDomDocumentFragmentPrivate*)impl) );
|
|---|
| 6739 | return QDomDocumentFragment();
|
|---|
| 6740 | }
|
|---|
| 6741 |
|
|---|
| 6742 | /*!
|
|---|
| 6743 | Converts a QDomNode into a QDomDocument. If the node is not a
|
|---|
| 6744 | document the returned object will be \link QDomNode::isNull()
|
|---|
| 6745 | null\endlink.
|
|---|
| 6746 |
|
|---|
| 6747 | \sa isDocument()
|
|---|
| 6748 | */
|
|---|
| 6749 | QDomDocument QDomNode::toDocument()
|
|---|
| 6750 | {
|
|---|
| 6751 | if ( impl && impl->isDocument() )
|
|---|
| 6752 | return QDomDocument( ((QDomDocumentPrivate*)impl) );
|
|---|
| 6753 | return QDomDocument();
|
|---|
| 6754 | }
|
|---|
| 6755 |
|
|---|
| 6756 | /*!
|
|---|
| 6757 | Converts a QDomNode into a QDomDocumentType. If the node is not a
|
|---|
| 6758 | document type the returned object will be \link QDomNode::isNull()
|
|---|
| 6759 | null\endlink.
|
|---|
| 6760 |
|
|---|
| 6761 | \sa isDocumentType()
|
|---|
| 6762 | */
|
|---|
| 6763 | QDomDocumentType QDomNode::toDocumentType()
|
|---|
| 6764 | {
|
|---|
| 6765 | if ( impl && impl->isDocumentType() )
|
|---|
| 6766 | return QDomDocumentType( ((QDomDocumentTypePrivate*)impl) );
|
|---|
| 6767 | return QDomDocumentType();
|
|---|
| 6768 | }
|
|---|
| 6769 |
|
|---|
| 6770 | /*!
|
|---|
| 6771 | Converts a QDomNode into a QDomElement. If the node is not an
|
|---|
| 6772 | element the returned object will be \link QDomNode::isNull()
|
|---|
| 6773 | null\endlink.
|
|---|
| 6774 |
|
|---|
| 6775 | \sa isElement()
|
|---|
| 6776 | */
|
|---|
| 6777 | QDomElement QDomNode::toElement()
|
|---|
| 6778 | {
|
|---|
| 6779 | if ( impl && impl->isElement() )
|
|---|
| 6780 | return QDomElement( ((QDomElementPrivate*)impl) );
|
|---|
| 6781 | return QDomElement();
|
|---|
| 6782 | }
|
|---|
| 6783 |
|
|---|
| 6784 | /*!
|
|---|
| 6785 | Converts a QDomNode into a QDomEntityReference. If the node is not
|
|---|
| 6786 | an entity reference, the returned object will be \link
|
|---|
| 6787 | QDomNode::isNull() null\endlink.
|
|---|
| 6788 |
|
|---|
| 6789 | \sa isEntityReference()
|
|---|
| 6790 | */
|
|---|
| 6791 | QDomEntityReference QDomNode::toEntityReference()
|
|---|
| 6792 | {
|
|---|
| 6793 | if ( impl && impl->isEntityReference() )
|
|---|
| 6794 | return QDomEntityReference( ((QDomEntityReferencePrivate*)impl) );
|
|---|
| 6795 | return QDomEntityReference();
|
|---|
| 6796 | }
|
|---|
| 6797 |
|
|---|
| 6798 | /*!
|
|---|
| 6799 | Converts a QDomNode into a QDomText. If the node is not a text,
|
|---|
| 6800 | the returned object will be \link QDomNode::isNull() null\endlink.
|
|---|
| 6801 |
|
|---|
| 6802 | \sa isText()
|
|---|
| 6803 | */
|
|---|
| 6804 | QDomText QDomNode::toText()
|
|---|
| 6805 | {
|
|---|
| 6806 | if ( impl && impl->isText() )
|
|---|
| 6807 | return QDomText( ((QDomTextPrivate*)impl) );
|
|---|
| 6808 | return QDomText();
|
|---|
| 6809 | }
|
|---|
| 6810 |
|
|---|
| 6811 | /*!
|
|---|
| 6812 | Converts a QDomNode into a QDomEntity. If the node is not an
|
|---|
| 6813 | entity the returned object will be \link QDomNode::isNull()
|
|---|
| 6814 | null\endlink.
|
|---|
| 6815 |
|
|---|
| 6816 | \sa isEntity()
|
|---|
| 6817 | */
|
|---|
| 6818 | QDomEntity QDomNode::toEntity()
|
|---|
| 6819 | {
|
|---|
| 6820 | if ( impl && impl->isEntity() )
|
|---|
| 6821 | return QDomEntity( ((QDomEntityPrivate*)impl) );
|
|---|
| 6822 | return QDomEntity();
|
|---|
| 6823 | }
|
|---|
| 6824 |
|
|---|
| 6825 | /*!
|
|---|
| 6826 | Converts a QDomNode into a QDomNotation. If the node is not a
|
|---|
| 6827 | notation the returned object will be \link QDomNode::isNull()
|
|---|
| 6828 | null\endlink.
|
|---|
| 6829 |
|
|---|
| 6830 | \sa isNotation()
|
|---|
| 6831 | */
|
|---|
| 6832 | QDomNotation QDomNode::toNotation()
|
|---|
| 6833 | {
|
|---|
| 6834 | if ( impl && impl->isNotation() )
|
|---|
| 6835 | return QDomNotation( ((QDomNotationPrivate*)impl) );
|
|---|
| 6836 | return QDomNotation();
|
|---|
| 6837 | }
|
|---|
| 6838 |
|
|---|
| 6839 | /*!
|
|---|
| 6840 | Converts a QDomNode into a QDomProcessingInstruction. If the node
|
|---|
| 6841 | is not a processing instruction the returned object will be \link
|
|---|
| 6842 | QDomNode::isNull() null\endlink.
|
|---|
| 6843 |
|
|---|
| 6844 | \sa isProcessingInstruction()
|
|---|
| 6845 | */
|
|---|
| 6846 | QDomProcessingInstruction QDomNode::toProcessingInstruction()
|
|---|
| 6847 | {
|
|---|
| 6848 | if ( impl && impl->isProcessingInstruction() )
|
|---|
| 6849 | return QDomProcessingInstruction( ((QDomProcessingInstructionPrivate*)impl) );
|
|---|
| 6850 | return QDomProcessingInstruction();
|
|---|
| 6851 | }
|
|---|
| 6852 |
|
|---|
| 6853 | /*!
|
|---|
| 6854 | Converts a QDomNode into a QDomCharacterData. If the node is not a
|
|---|
| 6855 | character data node the returned object will be \link
|
|---|
| 6856 | QDomNode::isNull() null\endlink.
|
|---|
| 6857 |
|
|---|
| 6858 | \sa isCharacterData()
|
|---|
| 6859 | */
|
|---|
| 6860 | QDomCharacterData QDomNode::toCharacterData()
|
|---|
| 6861 | {
|
|---|
| 6862 | if ( impl && impl->isCharacterData() )
|
|---|
| 6863 | return QDomCharacterData( ((QDomCharacterDataPrivate*)impl) );
|
|---|
| 6864 | return QDomCharacterData();
|
|---|
| 6865 | }
|
|---|
| 6866 |
|
|---|
| 6867 | /*!
|
|---|
| 6868 | Converts a QDomNode into a QDomComment. If the node is not a
|
|---|
| 6869 | comment the returned object will be \link QDomNode::isNull()
|
|---|
| 6870 | null\endlink.
|
|---|
| 6871 |
|
|---|
| 6872 | \sa isComment()
|
|---|
| 6873 | */
|
|---|
| 6874 | QDomComment QDomNode::toComment()
|
|---|
| 6875 | {
|
|---|
| 6876 | if ( impl && impl->isComment() )
|
|---|
| 6877 | return QDomComment( ((QDomCommentPrivate*)impl) );
|
|---|
| 6878 | return QDomComment();
|
|---|
| 6879 | }
|
|---|
| 6880 |
|
|---|
| 6881 | /**************************************************************
|
|---|
| 6882 | *
|
|---|
| 6883 | * QDomHandler
|
|---|
| 6884 | *
|
|---|
| 6885 | **************************************************************/
|
|---|
| 6886 |
|
|---|
| 6887 | QDomHandler::QDomHandler( QDomDocumentPrivate* adoc, bool namespaceProcessing )
|
|---|
| 6888 | {
|
|---|
| 6889 | doc = adoc;
|
|---|
| 6890 | node = doc;
|
|---|
| 6891 | cdata = FALSE;
|
|---|
| 6892 | nsProcessing = namespaceProcessing;
|
|---|
| 6893 | }
|
|---|
| 6894 |
|
|---|
| 6895 | QDomHandler::~QDomHandler()
|
|---|
| 6896 | {
|
|---|
| 6897 | }
|
|---|
| 6898 |
|
|---|
| 6899 | bool QDomHandler::endDocument()
|
|---|
| 6900 | {
|
|---|
| 6901 | // ### is this really necessary? (rms)
|
|---|
| 6902 | if ( node != doc )
|
|---|
| 6903 | return FALSE;
|
|---|
| 6904 | return TRUE;
|
|---|
| 6905 | }
|
|---|
| 6906 |
|
|---|
| 6907 | bool QDomHandler::startDTD( const QString& name, const QString& publicId, const QString& systemId )
|
|---|
| 6908 | {
|
|---|
| 6909 | doc->doctype()->name = name;
|
|---|
| 6910 | doc->doctype()->publicId = publicId;
|
|---|
| 6911 | doc->doctype()->systemId = systemId;
|
|---|
| 6912 | return TRUE;
|
|---|
| 6913 | }
|
|---|
| 6914 |
|
|---|
| 6915 | bool QDomHandler::startElement( const QString& nsURI, const QString&, const QString& qName, const QXmlAttributes& atts )
|
|---|
| 6916 | {
|
|---|
| 6917 | // tag name
|
|---|
| 6918 | QDomNodePrivate* n;
|
|---|
| 6919 | if ( nsProcessing ) {
|
|---|
| 6920 | n = doc->createElementNS( nsURI, qName );
|
|---|
| 6921 | } else {
|
|---|
| 6922 | n = doc->createElement( qName );
|
|---|
| 6923 | }
|
|---|
| 6924 | node->appendChild( n );
|
|---|
| 6925 | node = n;
|
|---|
| 6926 |
|
|---|
| 6927 | // attributes
|
|---|
| 6928 | for ( int i=0; i<atts.length(); i++ )
|
|---|
| 6929 | {
|
|---|
| 6930 | if ( nsProcessing ) {
|
|---|
| 6931 | ((QDomElementPrivate*)node)->setAttributeNS( atts.uri(i), atts.qName(i), atts.value(i) );
|
|---|
| 6932 | } else {
|
|---|
| 6933 | ((QDomElementPrivate*)node)->setAttribute( atts.qName(i), atts.value(i) );
|
|---|
| 6934 | }
|
|---|
| 6935 | }
|
|---|
| 6936 |
|
|---|
| 6937 | return TRUE;
|
|---|
| 6938 | }
|
|---|
| 6939 |
|
|---|
| 6940 | bool QDomHandler::endElement( const QString&, const QString&, const QString& )
|
|---|
| 6941 | {
|
|---|
| 6942 | if ( node == doc )
|
|---|
| 6943 | return FALSE;
|
|---|
| 6944 | node = node->parent();
|
|---|
| 6945 |
|
|---|
| 6946 | return TRUE;
|
|---|
| 6947 | }
|
|---|
| 6948 |
|
|---|
| 6949 | bool QDomHandler::characters( const QString& ch )
|
|---|
| 6950 | {
|
|---|
| 6951 | // No text as child of some document
|
|---|
| 6952 | if ( node == doc )
|
|---|
| 6953 | return FALSE;
|
|---|
| 6954 |
|
|---|
| 6955 | if ( cdata ) {
|
|---|
| 6956 | node->appendChild( doc->createCDATASection( ch ) );
|
|---|
| 6957 | } else if ( !entityName.isEmpty() ) {
|
|---|
| 6958 | QDomEntityPrivate* e = new QDomEntityPrivate( doc, 0, entityName,
|
|---|
| 6959 | QString::null, QString::null, QString::null );
|
|---|
| 6960 | e->value = ch;
|
|---|
| 6961 | doc->doctype()->appendChild( e );
|
|---|
| 6962 | node->appendChild( doc->createEntityReference( entityName ) );
|
|---|
| 6963 | } else {
|
|---|
| 6964 | node->appendChild( doc->createTextNode( ch ) );
|
|---|
| 6965 | }
|
|---|
| 6966 |
|
|---|
| 6967 | return TRUE;
|
|---|
| 6968 | }
|
|---|
| 6969 |
|
|---|
| 6970 | bool QDomHandler::processingInstruction( const QString& target, const QString& data )
|
|---|
| 6971 | {
|
|---|
| 6972 | node->appendChild( doc->createProcessingInstruction( target, data ) );
|
|---|
| 6973 | return TRUE;
|
|---|
| 6974 | }
|
|---|
| 6975 |
|
|---|
| 6976 | bool QDomHandler::skippedEntity( const QString& name )
|
|---|
| 6977 | {
|
|---|
| 6978 | node->appendChild( doc->createEntityReference( name ) );
|
|---|
| 6979 | return TRUE;
|
|---|
| 6980 | }
|
|---|
| 6981 |
|
|---|
| 6982 | bool QDomHandler::fatalError( const QXmlParseException& exception )
|
|---|
| 6983 | {
|
|---|
| 6984 | errorMsg = exception.message();
|
|---|
| 6985 | errorLine = exception.lineNumber();
|
|---|
| 6986 | errorColumn = exception.columnNumber();
|
|---|
| 6987 | return QXmlDefaultHandler::fatalError( exception );
|
|---|
| 6988 | }
|
|---|
| 6989 |
|
|---|
| 6990 | bool QDomHandler::startCDATA()
|
|---|
| 6991 | {
|
|---|
| 6992 | cdata = TRUE;
|
|---|
| 6993 | return TRUE;
|
|---|
| 6994 | }
|
|---|
| 6995 |
|
|---|
| 6996 | bool QDomHandler::endCDATA()
|
|---|
| 6997 | {
|
|---|
| 6998 | cdata = FALSE;
|
|---|
| 6999 | return TRUE;
|
|---|
| 7000 | }
|
|---|
| 7001 |
|
|---|
| 7002 | bool QDomHandler::startEntity( const QString &name )
|
|---|
| 7003 | {
|
|---|
| 7004 | entityName = name;
|
|---|
| 7005 | return TRUE;
|
|---|
| 7006 | }
|
|---|
| 7007 |
|
|---|
| 7008 | bool QDomHandler::endEntity( const QString & )
|
|---|
| 7009 | {
|
|---|
| 7010 | entityName = QString::null;
|
|---|
| 7011 | return TRUE;
|
|---|
| 7012 | }
|
|---|
| 7013 |
|
|---|
| 7014 | bool QDomHandler::comment( const QString& ch )
|
|---|
| 7015 | {
|
|---|
| 7016 | node->appendChild( doc->createComment( ch ) );
|
|---|
| 7017 | return TRUE;
|
|---|
| 7018 | }
|
|---|
| 7019 |
|
|---|
| 7020 | bool QDomHandler::unparsedEntityDecl( const QString &name, const QString &publicId, const QString &systemId, const QString ¬ationName )
|
|---|
| 7021 | {
|
|---|
| 7022 | QDomEntityPrivate* e = new QDomEntityPrivate( doc, 0, name,
|
|---|
| 7023 | publicId, systemId, notationName );
|
|---|
| 7024 | doc->doctype()->appendChild( e );
|
|---|
| 7025 | return TRUE;
|
|---|
| 7026 | }
|
|---|
| 7027 |
|
|---|
| 7028 | bool QDomHandler::externalEntityDecl( const QString &name, const QString &publicId, const QString &systemId )
|
|---|
| 7029 | {
|
|---|
| 7030 | return unparsedEntityDecl( name, publicId, systemId, QString::null );
|
|---|
| 7031 | }
|
|---|
| 7032 |
|
|---|
| 7033 | bool QDomHandler::notationDecl( const QString & name, const QString & publicId, const QString & systemId )
|
|---|
| 7034 | {
|
|---|
| 7035 | QDomNotationPrivate* n = new QDomNotationPrivate( doc, 0, name, publicId, systemId );
|
|---|
| 7036 | doc->doctype()->appendChild( n );
|
|---|
| 7037 | return TRUE;
|
|---|
| 7038 | }
|
|---|
| 7039 |
|
|---|
| 7040 | #endif //QT_NO_DOM
|
|---|