File: wx.xml.XmlNode.txt

package info (click to toggle)
wxpython4.0 4.0.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 211,112 kB
  • sloc: cpp: 888,355; python: 223,130; makefile: 52,087; ansic: 45,780; sh: 3,012; xml: 1,534; perl: 264
file content (881 lines) | stat: -rw-r--r-- 22,780 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
.. wxPython Phoenix documentation

   This file was generated by Phoenix's sphinx generator and associated
   tools, do not edit by hand.

   Copyright: (c) 2011-2018 by Total Control Software
   License:   wxWindows License

.. include:: headings.inc



.. _wx.xml.XmlNode:

==========================================================================================================================================
|phoenix_title|  **wx.xml.XmlNode**
==========================================================================================================================================

Represents a node in an ``XML`` document.          

See :ref:`wx.xml.XmlDocument`. 

Node has a name and may have content and attributes. 

Most common node types are  ``XML_TEXT_NODE``   (name and attributes are irrelevant) and   ``XML_ELEMENT_NODE`` . 

Example: in  ``<title>hi</title>``   there is an element with the name   ``title``   and irrelevant content and one child of type   ``XML_TEXT_NODE``   with   ``hi``   as content. 

The  ``XML_PI_NODE``   type sets the name to the ``PI`` target and the contents to the instructions. Note that whilst the ``PI`` instructions are often in the form of pseudo-attributes these do not use the nodes attribute system. It is the users responsibility to code and decode the instruction text. 

If  ``USE_UNICODE``   is 0, all strings are encoded in the encoding given to  :meth:`wx.xml.XmlDocument.Load`   (default is ``UTF-8``). 







         



.. seealso:: :ref:`wx.xml.XmlDocument`, :ref:`wx.xml.XmlAttribute`    







|

|class_hierarchy| Class Hierarchy
=================================

.. raw:: html

   <div id="toggleBlock" onclick="return toggleVisibility(this)" class="closed" style="cursor:pointer;">
   <img id="toggleBlock-trigger" src="_static/images/closed.png"/>
   Inheritance diagram for class <strong>XmlNode</strong>:
   </div>
   <div id="toggleBlock-summary" style="display:block;"></div>
   <div id="toggleBlock-content" style="display:none;">
   <p class="graphviz">
   <center><img src="_static/images/inheritance/wx.xml.XmlNode_inheritance.png" alt="Inheritance diagram of XmlNode" usemap="#dummy" class="inheritance"/></center>
   </div>
   <script type="text/javascript">toggleVisibilityOnLoad(document.getElementById('toggleBlock'))</script>
   <map id="dummy" name="dummy"> <area shape="rect" id="node1" href="wx.xml.XmlNode.html" title="wx.xml.XmlNode" alt="" coords="5,5,131,35"/> </map> 
   </p>

|


|method_summary| Methods Summary
================================

================================================================================ ================================================================================
:meth:`~wx.xml.XmlNode.__init__`                                                 Creates this ``XML`` node and eventually insert it into an existing ``XML`` tree.
:meth:`~wx.xml.XmlNode.AddAttribute`                                             Appends a attribute with given `name`  and `value`  to the list of attributes for this node.
:meth:`~wx.xml.XmlNode.AddChild`                                                 Adds node `child`  as the last child of this node.
:meth:`~wx.xml.XmlNode.DeleteAttribute`                                          Removes the first attributes which has the given `name`  from the list of attributes for this node.
:meth:`~wx.xml.XmlNode.GetAttribute`                                             Returns the value of the attribute named `attrName`  if it does exist.
:meth:`~wx.xml.XmlNode.GetAttributes`                                            Return a pointer to the first attribute of this node.
:meth:`~wx.xml.XmlNode.GetChildren`                                              Returns the first child of this node.
:meth:`~wx.xml.XmlNode.GetContent`                                               Returns the content of this node.
:meth:`~wx.xml.XmlNode.GetDepth`                                                 Returns the number of nodes which separate this node from  ``grandparent`` .
:meth:`~wx.xml.XmlNode.GetLineNumber`                                            Returns line number of the node in the input ``XML`` file or  ``-1``   if it is unknown.
:meth:`~wx.xml.XmlNode.GetName`                                                  Returns the name of this node.
:meth:`~wx.xml.XmlNode.GetNext`                                                  Returns a pointer to the sibling of this node or ``None`` if there are no siblings.
:meth:`~wx.xml.XmlNode.GetNoConversion`                                          Returns a flag indicating whether encoding conversion is necessary when saving.
:meth:`~wx.xml.XmlNode.GetNodeContent`                                           Returns the content of the first child node of type  ``XML_TEXT_NODE``   or   ``XML_CDATA_SECTION_NODE`` .
:meth:`~wx.xml.XmlNode.GetParent`                                                Returns a pointer to the parent of this node or ``None`` if this node has no parent.
:meth:`~wx.xml.XmlNode.GetType`                                                  Returns the type of this node.
:meth:`~wx.xml.XmlNode.HasAttribute`                                             Returns ``True`` if this node has a attribute named `attrName`.
:meth:`~wx.xml.XmlNode.InsertChild`                                              Inserts the `child`  node immediately before `followingNode`  in the children list.
:meth:`~wx.xml.XmlNode.InsertChildAfter`                                         Inserts the `child`  node immediately after `precedingNode`  in the children list.
:meth:`~wx.xml.XmlNode.IsWhitespaceOnly`                                         Returns ``True`` if the content of this node is a string containing only whitespaces (spaces, tabs, new lines, etc).
:meth:`~wx.xml.XmlNode.RemoveChild`                                              Removes the given node from the children list.
:meth:`~wx.xml.XmlNode.SetContent`                                               Sets the content of this node.
:meth:`~wx.xml.XmlNode.SetName`                                                  Sets the name of this node.
:meth:`~wx.xml.XmlNode.SetNext`                                                  Sets as sibling the given node.
:meth:`~wx.xml.XmlNode.SetNoConversion`                                          Sets a flag to indicate whether encoding conversion is necessary when saving.
:meth:`~wx.xml.XmlNode.SetParent`                                                Sets as parent the given node.
:meth:`~wx.xml.XmlNode.SetType`                                                  Sets the type of this node.
================================================================================ ================================================================================


|


|property_summary| Properties Summary
=====================================

================================================================================ ================================================================================
:attr:`~wx.xml.XmlNode.Attributes`                                               See :meth:`~wx.xml.XmlNode.GetAttributes`
:attr:`~wx.xml.XmlNode.Children`                                                 See :meth:`~wx.xml.XmlNode.GetChildren`
:attr:`~wx.xml.XmlNode.Content`                                                  See :meth:`~wx.xml.XmlNode.GetContent` and :meth:`~wx.xml.XmlNode.SetContent`
:attr:`~wx.xml.XmlNode.Depth`                                                    See :meth:`~wx.xml.XmlNode.GetDepth`
:attr:`~wx.xml.XmlNode.LineNumber`                                               See :meth:`~wx.xml.XmlNode.GetLineNumber`
:attr:`~wx.xml.XmlNode.Name`                                                     See :meth:`~wx.xml.XmlNode.GetName` and :meth:`~wx.xml.XmlNode.SetName`
:attr:`~wx.xml.XmlNode.Next`                                                     See :meth:`~wx.xml.XmlNode.GetNext` and :meth:`~wx.xml.XmlNode.SetNext`
:attr:`~wx.xml.XmlNode.NoConversion`                                             See :meth:`~wx.xml.XmlNode.GetNoConversion` and :meth:`~wx.xml.XmlNode.SetNoConversion`
:attr:`~wx.xml.XmlNode.NodeContent`                                              See :meth:`~wx.xml.XmlNode.GetNodeContent`
:attr:`~wx.xml.XmlNode.Parent`                                                   See :meth:`~wx.xml.XmlNode.GetParent` and :meth:`~wx.xml.XmlNode.SetParent`
:attr:`~wx.xml.XmlNode.Type`                                                     See :meth:`~wx.xml.XmlNode.GetType` and :meth:`~wx.xml.XmlNode.SetType`
================================================================================ ================================================================================


|


|api| Class API
===============


.. class:: wx.xml.XmlNode(object)

   **Possible constructors**::

       XmlNode(parent, type, name, content="", attrs=None, next=None,
               lineNo=-1)
       
       XmlNode(type, name, content="", lineNo=-1)
       
       XmlNode(node)
       
   
   Represents a node in an ``XML`` document.



   .. method:: __init__(self, *args, **kw)



      |overload| Overloaded Implementations:

      **~~~**

      
      **__init__** `(self, parent, type, name, content=EmptyString, attrs=None, next=None, lineNo=-1)`
      
      Creates this ``XML`` node and eventually insert it into an existing ``XML`` tree.                  
      
      
      
      
      :param `parent`: The parent node to which append this node instance. If this argument is ``None`` this new node will be floating and it can be appended later to another one using the :meth:`AddChild`   or :meth:`InsertChild`   functions. Otherwise the child is already added to the ``XML`` tree by this constructor and it shouldn't be done again.   
      :type `parent`: wx.xml.XmlNode
      :param `type`: One of the :ref:`wx.xml.XmlNodeType`  enumeration value.   
      :type `type`: wx.xml.XmlNodeType
      :param `name`: The name of the node. This is the string which appears between angular brackets.   
      :type `name`: string
      :param `content`: The content of the node. Only meaningful when type is  ``XML_TEXT_NODE``   or   ``XML_CDATA_SECTION_NODE`` .    
      :type `content`: string
      :param `attrs`: If not ``None``, this :ref:`wx.xml.XmlAttribute`  object and its eventual siblings are attached to the node.   
      :type `attrs`: wx.xml.XmlAttribute
      :param `next`: If not ``None``, this node and its eventual siblings are attached to the node.   
      :type `next`: wx.xml.XmlNode
      :param `lineNo`: Number of line this node was present at in input file or -1.   
      :type `lineNo`: int
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
                        
      
      
      
      
      **~~~**

      
      **__init__** `(self, type, name, content=EmptyString, lineNo=-1)`
      
      A simplified version of the first constructor form, assuming a ``None`` parent.                  
      
      
      
      
      :param `type`: One of the :ref:`wx.xml.XmlNodeType`  enumeration value.   
      :type `type`: wx.xml.XmlNodeType
      :param `name`: The name of the node. This is the string which appears between angular brackets.   
      :type `name`: string
      :param `content`: The content of the node. Only meaningful when type is  ``XML_TEXT_NODE``   or   ``XML_CDATA_SECTION_NODE`` .    
      :type `content`: string
      :param `lineNo`: Number of line this node was present at in input file or -1.   
      :type `lineNo`: int
      
      
      
      
      
      
      
      
      
      
                        
      
      
      
      
      **~~~**

      
      **__init__** `(self, node)`
      
      Copy constructor.                  
      
      Note that this does NOT copy siblings and parent pointer, i.e. :meth:`GetParent`   and :meth:`GetNext`   will return ``None`` after using copy constructor and are never unmodified by :meth:`operator=` . On the other hand, it DOES copy children and attributes.                  
      
      
      :param `node`: 
      :type `node`: wx.xml.XmlNode
      
      
      
      
      
      
      **~~~**






   .. method:: AddAttribute(self, *args, **kw)



      |overload| Overloaded Implementations:

      **~~~**

      
      **AddAttribute** `(self, name, value)`
      
      Appends a attribute with given `name`  and `value`  to the list of attributes for this node.                  
      
      
      :param `name`: 
      :type `name`: string
      :param `value`: 
      :type `value`: string
      
      
      
      
      
      
      **~~~**

      
      **AddAttribute** `(self, attr)`
      
      Appends given attribute to the list of attributes for this node.                  
      
      
      :param `attr`: 
      :type `attr`: wx.xml.XmlAttribute
      
      
      
      
      
      
      **~~~**






   .. method:: AddChild(self, child)

      Adds node `child`  as the last child of this node.                  

                


      :param `child`: 
      :type `child`: wx.xml.XmlNode






      .. note:: 

         Note that this function works in O(n) time where `n`  is the number of existing children. Consequently, adding large number of child nodes using this method can be expensive, because it has O(n^2) time complexity in number of nodes to be added. Use :meth:`InsertChildAfter`   to populate ``XML`` tree in linear time.  







      .. seealso:: :meth:`InsertChild` , :meth:`InsertChildAfter`     








   .. method:: DeleteAttribute(self, name)

      Removes the first attributes which has the given `name`  from the list of attributes for this node.                  


      :param `name`: 
      :type `name`: string




      :rtype: `bool`








   .. method:: GetAttribute(self, attrName, defaultVal=EmptyString)

      Returns the value of the attribute named `attrName`  if it does exist.                  

      If it does not exist, the `defaultVal`  is returned.                  


      :param `attrName`: 
      :type `attrName`: string
      :param `defaultVal`: 
      :type `defaultVal`: string




      :rtype: `string`








   .. method:: GetAttributes(self)

      Return a pointer to the first attribute of this node.                  

      :rtype: :ref:`wx.xml.XmlAttribute`








   .. method:: GetChildren(self)

      Returns the first child of this node.                  

      To get a pointer to the second child of this node (if it does exist), use the :meth:`GetNext`   function on the returned value.                  

      :rtype: :ref:`wx.xml.XmlNode`








   .. method:: GetContent(self)

      Returns the content of this node.                  

      Can be an empty string. Be aware that for nodes of type  ``XML_ELEMENT_NODE``   (the most used node type) the content is an empty string. See  :meth:`GetNodeContent`   for more details.                  

      :rtype: `string`








   .. method:: GetDepth(self, grandparent=None)

      Returns the number of nodes which separate this node from  ``grandparent`` .                   

      This function searches only the parents of this node until it finds `grandparent`  or the ``None`` node (which is the parent of non-linked nodes or the parent of a :ref:`wx.xml.XmlDocument`'s root element node).                  


      :param `grandparent`: 
      :type `grandparent`: wx.xml.XmlNode




      :rtype: `int`








   .. method:: GetLineNumber(self)

      Returns line number of the node in the input ``XML`` file or  ``-1``   if it is unknown.                   

      :rtype: `int`








   .. method:: GetName(self)

      Returns the name of this node.                  

      Can be an empty string (e.g. for nodes of type  ``XML_TEXT_NODE``   or   ``XML_CDATA_SECTION_NODE`` ).                   

      :rtype: `string`








   .. method:: GetNext(self)

      Returns a pointer to the sibling of this node or ``None`` if there are no siblings.                  

      :rtype: :ref:`wx.xml.XmlNode`








   .. method:: GetNoConversion(self)

      Returns a flag indicating whether encoding conversion is necessary when saving.                  

      The default is ``False``. 

      You can improve saving efficiency considerably by setting this value.                  

      :rtype: `bool`








   .. method:: GetNodeContent(self)

      Returns the content of the first child node of type  ``XML_TEXT_NODE``   or   ``XML_CDATA_SECTION_NODE`` .                   

      This function is very useful since the ``XML`` snippet  ``"tagnametagcontent/tagname"``   is represented by expat with the following tag tree: 



      .. code-block:: text

              XML_ELEMENT_NODE name="tagname", content=""
              |-- XML_TEXT_NODE name="", content="tagcontent"



      or eventually: 



      .. code-block:: text

              XML_ELEMENT_NODE name="tagname", content=""
              |-- XML_CDATA_SECTION_NODE name="", content="tagcontent"



      An empty string is returned if the node has no children of type  ``XML_TEXT_NODE``   or   ``XML_CDATA_SECTION_NODE`` , or if the content of the first child of such types is empty.                   

      :rtype: `string`








   .. method:: GetParent(self)

      Returns a pointer to the parent of this node or ``None`` if this node has no parent.                  

      :rtype: :ref:`wx.xml.XmlNode`








   .. method:: GetType(self)

      Returns the type of this node.                  

      :rtype: :ref:`wx.xml.XmlNodeType`








   .. method:: HasAttribute(self, attrName)

      Returns ``True`` if this node has a attribute named `attrName`.                  


      :param `attrName`: 
      :type `attrName`: string




      :rtype: `bool`








   .. method:: InsertChild(self, child, followingNode)

      Inserts the `child`  node immediately before `followingNode`  in the children list.                  

                


      :param `child`: 
      :type `child`: wx.xml.XmlNode
      :param `followingNode`: 
      :type `followingNode`: wx.xml.XmlNode




      :rtype: `bool`







      :returns: 

         ``True`` if `followingNode`  has been found and the `child`  node has been inserted.  







      .. note:: 

         For historical reasons, `followingNode`  may be ``None``. In that case, then `child`  is prepended to the list of children and becomes the first child of this node, i.e. it behaves identically to using the first children (as returned by :meth:`GetChildren` ) for `followingNode`).  







      .. seealso:: :meth:`AddChild` , :meth:`InsertChildAfter`     








   .. method:: InsertChildAfter(self, child, precedingNode)

      Inserts the `child`  node immediately after `precedingNode`  in the children list.                  




      :param `child`: The child to insert.   
      :type `child`: wx.xml.XmlNode
      :param `precedingNode`: The node to insert  `child`  after. As a special case, this can be ``None`` if this node has no children yet  `child`  will become this node's only child node.  
      :type `precedingNode`: wx.xml.XmlNode








      :rtype: `bool`



                  



      :returns: 

         ``True`` if `precedingNode`  has been found and the `child`  node has been inserted.  







      .. versionadded:: 2.8.8 
    







      .. seealso:: :meth:`InsertChild` , :meth:`AddChild`     








   .. method:: IsWhitespaceOnly(self)

      Returns ``True`` if the content of this node is a string containing only whitespaces (spaces, tabs, new lines, etc).                  

      Note that this function is locale-independent since the parsing of ``XML`` documents must always produce the exact same tree regardless of the locale it runs under.                  

      :rtype: `bool`








   .. method:: RemoveChild(self, child)

      Removes the given node from the children list.                  

      Returns ``True`` if the node was found and removed or ``False`` if the node could not be found. Note that the caller is responsible for deleting the removed node in order to avoid memory leaks.                  


      :param `child`: 
      :type `child`: wx.xml.XmlNode




      :rtype: `bool`








   .. method:: SetContent(self, con)

      Sets the content of this node.                  


      :param `con`: 
      :type `con`: string







   .. method:: SetName(self, name)

      Sets the name of this node.                  


      :param `name`: 
      :type `name`: string







   .. method:: SetNext(self, next)

      Sets as sibling the given node.                  

      The caller is responsible for deleting any previously present sibling node.                  


      :param `next`: 
      :type `next`: wx.xml.XmlNode







   .. method:: SetNoConversion(self, noconversion)

      Sets a flag to indicate whether encoding conversion is necessary when saving.                  

      The default is ``False``. 

      You can improve saving efficiency considerably by setting this value.                  


      :param `noconversion`: 
      :type `noconversion`: bool







   .. method:: SetParent(self, parent)

      Sets as parent the given node.                  

      The caller is responsible for deleting any previously present parent node.                  


      :param `parent`: 
      :type `parent`: wx.xml.XmlNode







   .. method:: SetType(self, type)

      Sets the type of this node.                  


      :param `type`: 
      :type `type`: wx.xml.XmlNodeType







   .. attribute:: Attributes

      See :meth:`~wx.xml.XmlNode.GetAttributes`


   .. attribute:: Children

      See :meth:`~wx.xml.XmlNode.GetChildren`


   .. attribute:: Content

      See :meth:`~wx.xml.XmlNode.GetContent` and :meth:`~wx.xml.XmlNode.SetContent`


   .. attribute:: Depth

      See :meth:`~wx.xml.XmlNode.GetDepth`


   .. attribute:: LineNumber

      See :meth:`~wx.xml.XmlNode.GetLineNumber`


   .. attribute:: Name

      See :meth:`~wx.xml.XmlNode.GetName` and :meth:`~wx.xml.XmlNode.SetName`


   .. attribute:: Next

      See :meth:`~wx.xml.XmlNode.GetNext` and :meth:`~wx.xml.XmlNode.SetNext`


   .. attribute:: NoConversion

      See :meth:`~wx.xml.XmlNode.GetNoConversion` and :meth:`~wx.xml.XmlNode.SetNoConversion`


   .. attribute:: NodeContent

      See :meth:`~wx.xml.XmlNode.GetNodeContent`


   .. attribute:: Parent

      See :meth:`~wx.xml.XmlNode.GetParent` and :meth:`~wx.xml.XmlNode.SetParent`


   .. attribute:: Type

      See :meth:`~wx.xml.XmlNode.GetType` and :meth:`~wx.xml.XmlNode.SetType`