forked from andreww/fox
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathm_dom_document.m4
1421 lines (1196 loc) · 46.2 KB
/
m_dom_document.m4
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
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
TOHW_m_dom_publics(`
!FIXME lots of these should have a check if(namespaces) checkNCName
public :: getDocType
public :: getImplementation
public :: getDocumentElement
public :: setDocumentElement
public :: createElement
public :: createDocumentFragment
public :: createTextNode
public :: createComment
public :: createCdataSection
public :: createProcessingInstruction
public :: createAttribute
public :: createEntityReference
public :: createEmptyEntityReference
public :: getElementsByTagName
public :: importNode
public :: createElementNS
public :: createAttributeNS
public :: getElementsByTagNameNS
public :: getElementById
public :: getXmlStandalone
public :: setXmlStandalone
public :: getXmlVersion
public :: setXmlVersion
public :: getXmlEncoding
public :: getInputEncoding
public :: getDocumentURI
public :: setDocumentURI
public :: getStrictErrorChecking
public :: setStrictErrorChecking
public :: getDomConfig
public :: renameNode
public :: adoptNode
public :: setDocType
public :: setDomConfig
public :: setXds
public :: createNamespaceNode
public :: createEntity
public :: createNotation
public :: setGCstate
public :: getXds
public :: getLiveNodeLists
public :: setLiveNodeLists
')`'dnl
dnl
TOHW_m_dom_contents(`
TOHW_m_dom_get(Node, docType, np%docExtras%docType, (DOCUMENT_NODE))
TOHW_subroutine(setDocType, (arg, np))
type(Node), pointer :: arg
type(Node), pointer :: np
if (.not.associated(arg)) then
TOHW_m_dom_throw_error(FoX_NODE_IS_NULL)
endif
if (arg%nodeType/=DOCUMENT_NODE) then
TOHW_m_dom_throw_error(FoX_INVALID_NODE)
endif
arg%docExtras%docType => np
!NB special case in order to set ownerDocument
np%ownerDocument => arg
end subroutine setDocType
TOHW_m_dom_get(Node, documentElement, np%docExtras%documentElement, (DOCUMENT_NODE))
TOHW_subroutine(setXds, (arg, xds))
type(Node), pointer :: arg
type(xml_doc_state), pointer :: xds
if (.not.associated(arg)) then
TOHW_m_dom_throw_error(FoX_NODE_IS_NULL)
endif
if (arg%nodeType/=DOCUMENT_NODE) then
TOHW_m_dom_throw_error(FoX_INVALID_NODE)
endif
!NB special case in order to destroy_xml_doc_state etc
call destroy_xml_doc_state(arg%docExtras%xds)
deallocate(arg%docExtras%xds)
arg%docExtras%xds => xds
end subroutine setXds
TOHW_function(getImplementation, (arg), imp)
type(Node), pointer, optional :: arg
type(DOMImplementation), pointer :: imp
! According to the testsuite, you get to call
! getImplementation with no args. Dont know
! where they get that from ...
if (present(arg)) then
if (.not.associated(arg)) then
TOHW_m_dom_throw_error(FoX_NODE_IS_NULL)
endif
if (arg%nodeType/=DOCUMENT_NODE) then
TOHW_m_dom_throw_error(FoX_INVALID_NODE)
endif
imp => arg%docExtras%implementation
else
imp => FoX_DOM
endif
end function getImplementation
TOHW_subroutine(setDocumentElement, (arg, np))
! Only for use by FoX, not exported through FoX_DOM interface
type(Node), pointer :: arg
type(Node), pointer :: np
if (.not.associated(arg)) then
TOHW_m_dom_throw_error(FoX_NODE_IS_NULL)
endif
!NB special case due to additional error conditions:
if (arg%nodeType/=DOCUMENT_NODE) then
TOHW_m_dom_throw_error(FoX_INVALID_NODE)
elseif (np%nodeType/=ELEMENT_NODE) then
TOHW_m_dom_throw_error(FoX_INVALID_NODE)
elseif (.not.associated(np%ownerDocument, arg)) then
TOHW_m_dom_throw_error(WRONG_DOCUMENT_ERR)
endif
arg%docExtras%documentElement => np
end subroutine setDocumentElement
! Methods
TOHW_function(createElement, (arg, tagName), np)
type(Node), pointer :: arg
character(len=*), intent(in) :: tagName
type(Node), pointer :: np
type(xml_doc_state), pointer :: xds
type(element_t), pointer :: elem
type(attribute_t), pointer :: att
logical :: defaults_
integer :: i
if (.not.associated(arg)) then
TOHW_m_dom_throw_error(FoX_NODE_IS_NULL)
endif
if (arg%nodeType/=DOCUMENT_NODE) then
TOHW_m_dom_throw_error(FoX_INVALID_NODE)
elseif (.not.checkName(tagName, getXmlVersionEnum(arg))) then
TOHW_m_dom_throw_error(INVALID_CHARACTER_ERR)
endif
np => createNode(arg, ELEMENT_NODE, tagName, "")
allocate(np%elExtras)
np%elExtras%dom1 = .true.
np%elExtras%attributes%ownerElement => np
allocate(np%elExtras%namespaceURI(0))
allocate(np%elExtras%prefix(0))
allocate(np%elExtras%localname(0))
allocate(np%elExtras%namespaceNodes%nodes(0))
np%elExtras%attributes%ownerElement => np
if (getGCstate(arg)) then
np%inDocument = .false.
call append(arg%docExtras%hangingnodes, np)
! We only add default attributes if we are *not* building the doc
xds => getXds(arg)
elem => get_element(xds%element_list, tagName)
if (associated(elem)) then
do i = 1, get_attlist_size(elem)
att => get_attribute_declaration(elem, i)
if (attribute_has_default(att)) then
! Since this is a non-namespaced function, we create
! a non-namespaced attribute ...
call setAttribute(np, str_vs(att%name), str_vs(att%default))
endif
enddo
endif
else
np%inDocument = .true.
endif
end function createElement
TOHW_function(createEmptyElement, (arg, tagName), np)
type(Node), pointer :: arg
character(len=*), intent(in) :: tagName
type(Node), pointer :: np
! NO CHECKS !
np => createNode(arg, ELEMENT_NODE, tagName, "")
allocate(np%elExtras)
np%elExtras%dom1 = .true.
np%elExtras%attributes%ownerElement => np
allocate(np%elExtras%namespaceURI(0))
allocate(np%elExtras%prefix(0))
allocate(np%elExtras%localname(0))
allocate(np%elExtras%namespaceNodes%nodes(0))
np%elExtras%attributes%ownerElement => np
if (getGCstate(arg)) then
call append(arg%docExtras%hangingnodes, np)
np%inDocument = .false.
else
np%inDocument = .true.
endif
end function createEmptyElement
TOHW_function(createDocumentFragment, (arg), np)
type(Node), pointer :: arg
type(Node), pointer :: np
if (.not.associated(arg)) then
TOHW_m_dom_throw_error(FoX_NODE_IS_NULL)
endif
if (arg%nodeType/=DOCUMENT_NODE) then
TOHW_m_dom_throw_error(FoX_INVALID_NODE)
endif
np => createNode(arg, DOCUMENT_FRAGMENT_NODE, "#document-fragment", "")
if (getGCstate(arg)) then
np%inDocument = .false.
call append(arg%docExtras%hangingnodes, np)
else
np%inDocument = .true.
endif
end function createDocumentFragment
TOHW_function(createTextNode, (arg, data), np)
type(Node), pointer :: arg
character(len=*), intent(in) :: data
type(Node), pointer :: np
if (.not.associated(arg)) then
TOHW_m_dom_throw_error(FoX_NODE_IS_NULL)
endif
if (arg%nodeType/=DOCUMENT_NODE) then
TOHW_m_dom_throw_error(FoX_INVALID_NODE)
elseif (.not.checkChars(data, getXmlVersionEnum(arg))) then
TOHW_m_dom_throw_error(FoX_INVALID_CHARACTER)
endif
np => createNode(arg, TEXT_NODE, "#text", data)
np%textContentLength = len(data)
if (getGCstate(arg)) then
np%inDocument = .false.
call append(arg%docExtras%hangingnodes, np)
else
np%inDocument = .true.
endif
end function createTextNode
TOHW_function(createComment, (arg, data), np)
type(Node), pointer :: arg
character(len=*), intent(in) :: data
type(Node), pointer :: np
if (.not.associated(arg)) then
TOHW_m_dom_throw_error(FoX_NODE_IS_NULL)
endif
if (arg%nodeType/=DOCUMENT_NODE) then
TOHW_m_dom_throw_error(FoX_INVALID_NODE)
elseif (.not.checkChars(data, getXmlVersionEnum(arg))) then
TOHW_m_dom_throw_error(FoX_INVALID_CHARACTER)
elseif (index(data,"--")>0) then
TOHW_m_dom_throw_error(FoX_INVALID_COMMENT)
endif
np => createNode(arg, COMMENT_NODE, "#comment", data)
np%textContentLength = len(data)
if (getGCstate(arg)) then
np%inDocument = .false.
call append(arg%docExtras%hangingnodes, np)
else
np%inDocument = .true.
endif
end function createComment
TOHW_function(createCdataSection, (arg, data), np)
type(Node), pointer :: arg
character(len=*), intent(in) :: data
type(Node), pointer :: np
if (.not.associated(arg)) then
TOHW_m_dom_throw_error(FoX_NODE_IS_NULL)
endif
if (arg%nodeType/=DOCUMENT_NODE) then
TOHW_m_dom_throw_error(FoX_INVALID_NODE)
elseif (.not.checkChars(data, getXmlVersionEnum(arg))) then
TOHW_m_dom_throw_error(FoX_INVALID_CHARACTER)
elseif (index(data,"]]>")>0) then
TOHW_m_dom_throw_error(FoX_INVALID_CDATA_SECTION)
endif
np => createNode(arg, CDATA_SECTION_NODE, "#cdata-section", data)
np%textContentLength = len(data)
if (getGCstate(arg)) then
np%inDocument = .false.
call append(arg%docExtras%hangingnodes, np)
else
np%inDocument = .true.
endif
end function createCdataSection
TOHW_function(createProcessingInstruction, (arg, target, data), np)
type(Node), pointer :: arg
character(len=*), intent(in) :: target
character(len=*), intent(in) :: data
type(Node), pointer :: np
if (.not.associated(arg)) then
TOHW_m_dom_throw_error(FoX_NODE_IS_NULL)
endif
if (arg%nodeType/=DOCUMENT_NODE) then
TOHW_m_dom_throw_error(FoX_INVALID_NODE)
elseif (.not.checkName(target, getXmlVersionEnum(arg))) then
TOHW_m_dom_throw_error(INVALID_CHARACTER_ERR)
elseif (.not.checkChars(data, getXmlVersionEnum(arg))) then
TOHW_m_dom_throw_error(FoX_INVALID_CHARACTER)
elseif (index(data,"?>")>0) then
TOHW_m_dom_throw_error(FoX_INVALID_PI_DATA)
endif
np => createNode(arg, PROCESSING_INSTRUCTION_NODE, target, data)
np%textContentLength = len(data)
if (getGCstate(arg)) then
np%inDocument = .false.
call append(arg%docExtras%hangingnodes, np)
else
np%inDocument = .true.
endif
end function createProcessingInstruction
TOHW_function(createAttribute, (arg, name), np)
type(Node), pointer :: arg
character(len=*), intent(in) :: name
type(Node), pointer :: np
if (.not.associated(arg)) then
TOHW_m_dom_throw_error(FoX_NODE_IS_NULL)
endif
if (arg%nodeType/=DOCUMENT_NODE) then
TOHW_m_dom_throw_error(FoX_INVALID_NODE)
elseif (.not.checkName(name, getXmlVersionEnum(arg))) then
TOHW_m_dom_throw_error(INVALID_CHARACTER_ERR)
endif
np => createNode(arg, ATTRIBUTE_NODE, name, "")
allocate(np%elExtras)
np%elExtras%dom1 = .true.
allocate(np%elExtras%namespaceURI(0))
allocate(np%elExtras%prefix(0))
allocate(np%elExtras%localname(0))
if (getGCstate(arg)) then
np%inDocument = .false.
call append(arg%docExtras%hangingnodes, np)
else
np%inDocument = .true.
endif
end function createAttribute
recursive TOHW_function(createEntityReference, (arg, name), np)
! Needs to be recursive in case of entity-references within each other.
type(Node), pointer :: arg
character(len=*), intent(in) :: name
type(Node), pointer :: np
type(Node), pointer :: ent, newNode
integer :: i
logical :: brokenNS
if (.not.associated(arg)) then
TOHW_m_dom_throw_error(FoX_NODE_IS_NULL)
endif
if (arg%nodeType/=DOCUMENT_NODE) then
TOHW_m_dom_throw_error(FoX_INVALID_NODE)
elseif (.not.checkName(name, getXmlVersionEnum(arg))) then
TOHW_m_dom_throw_error(INVALID_CHARACTER_ERR)
endif
if (getXmlStandalone(arg).and..not.associated(getDocType(arg))) then
TOHW_m_dom_throw_error(FoX_NO_SUCH_ENTITY)
endif
np => createNode(arg, ENTITY_REFERENCE_NODE, name, "")
if (getGCstate(arg)) then ! otherwise the parser will fill these nodes in itself
if (associated(getDocType(arg))) then
ent => getNamedItem(getEntities(getDocType(arg)), name)
if (associated(ent)) then
if (getIllFormed(ent)) then
TOHW_m_dom_throw_error(FoX_INVALID_ENTITY)
endif
brokenNS = arg%docExtras%brokenNS
arg%docExtras%brokenNS = .true. ! We need to not worry about NS errors for a bit
do i = 0, getLength(getChildNodes(ent)) - 1
newNode => appendChild(np, cloneNode(item(getChildNodes(ent), i), .true., ex))
! No namespace calcs here - wait for a namespace normalization
call setReadOnlyNode(newNode, .true., .true.)
enddo
arg%docExtras%brokenNS = brokenNS ! FIXME also for all new default attributes
elseif (getXmlStandalone(arg)) then
TOHW_m_dom_throw_error(FoX_NO_SUCH_ENTITY, (np))
endif
endif
endif
call setReadOnlyNode(np, .true., .false.)
if (getGCstate(arg)) then
np%inDocument = .false.
call append_nl(arg%docExtras%hangingNodes, np)
! All child nodes were created outside the document by cloneNode above
else
np%inDocument = .true.
endif
end function createEntityReference
TOHW_function(createEmptyEntityReference, (arg, name), np)
type(Node), pointer :: arg
character(len=*), intent(in) :: name
type(Node), pointer :: np
if (.not.associated(arg)) then
TOHW_m_dom_throw_error(FoX_NODE_IS_NULL)
endif
if (arg%nodeType/=DOCUMENT_NODE) then
TOHW_m_dom_throw_error(FoX_INVALID_NODE)
elseif (.not.checkName(name, getXmlVersionEnum(arg))) then
TOHW_m_dom_throw_error(INVALID_CHARACTER_ERR)
endif
np => createNode(arg, ENTITY_REFERENCE_NODE, name, "")
if (getGCstate(arg)) then
np%inDocument = .false.
call append(arg%docExtras%hangingnodes, np)
else
np%inDocument = .true.
endif
end function createEmptyEntityReference
TOHW_function(getElementsByTagName, (doc, tagName, name), list)
type(Node), pointer :: doc
character(len=*), intent(in), optional :: tagName, name
type(NodeList), pointer :: list
type(NodeListPtr), pointer :: nll(:), temp_nll(:)
type(Node), pointer :: arg, this, treeroot
logical :: doneChildren, doneAttributes, allElements
integer :: i, i_tree
if (.not.associated(doc)) then
TOHW_m_dom_throw_error(FoX_NODE_IS_NULL)
endif
if (doc%nodeType==DOCUMENT_NODE) then
if (present(name).or..not.present(tagName)) then
TOHW_m_dom_throw_error(FoX_INVALID_NODE)
endif
elseif (doc%nodeType==ELEMENT_NODE) then
if (present(name).or..not.present(tagName)) then
TOHW_m_dom_throw_error(FoX_INVALID_NODE)
endif
else
TOHW_m_dom_throw_error(FoX_INVALID_NODE)
endif
if (doc%nodeType==DOCUMENT_NODE) then
arg => getDocumentElement(doc)
else
arg => doc
endif
allocate(list)
allocate(list%nodes(0))
list%element => doc
if (present(name)) list%nodeName => vs_str_alloc(name)
if (present(tagName)) list%nodeName => vs_str_alloc(tagName)
allElements = (str_vs(list%nodeName)=="*")
if (doc%nodeType==DOCUMENT_NODE) then
nll => doc%docExtras%nodelists
elseif (doc%nodeType==ELEMENT_NODE) then
nll => doc%ownerDocument%docExtras%nodelists
endif
allocate(temp_nll(size(nll)+1))
do i = 1, size(nll)
temp_nll(i)%this => nll(i)%this
enddo
temp_nll(i)%this => list
deallocate(nll)
if (doc%nodeType==DOCUMENT_NODE) then
doc%docExtras%nodelists => temp_nll
elseif (doc%nodeType==ELEMENT_NODE) then
doc%ownerDocument%docExtras%nodelists => temp_nll
endif
treeroot => arg
TOHW_m_dom_treewalk(`dnl
if (this%nodeType==ELEMENT_NODE) then
if ((allElements .or. str_vs(this%nodeName)==tagName) &
.and..not.(getNodeType(doc)==ELEMENT_NODE.and.associated(this, arg))) &
call append(list, this)
doneAttributes = .true.
endif
',`')
end function getElementsByTagName
TOHW_function(importNode, (doc, arg, deep) , np)
type(Node), pointer :: doc
type(Node), pointer :: arg
logical, intent(in) :: deep
type(Node), pointer :: np
type(Node), pointer :: this, thatParent, new, treeroot
type(xml_doc_state), pointer :: xds
type(element_t), pointer :: elem
type(attribute_t), pointer :: att
logical :: doneAttributes, doneChildren, brokenNS
integer :: i_tree
if (.not.associated(doc).or..not.associated(arg)) then
TOHW_m_dom_throw_error(FoX_NODE_IS_NULL)
endif
if (getNodeType(doc)/=DOCUMENT_NODE) then
TOHW_m_dom_throw_error(FoX_INVALID_NODE)
elseif (getNodeType(arg)==DOCUMENT_NODE .or. &
getNodeType(arg)==DOCUMENT_TYPE_NODE) then
TOHW_m_dom_throw_error(NOT_SUPPORTED_ERR)
endif
brokenNS = doc%docExtras%brokenNS
doc%docExtras%brokenNS = .true. ! We need to do stupid NS things
xds => getXds(doc)
thatParent => null()
treeroot => arg
TOHW_m_dom_treewalk(`
new => null()
select case (getNodeType(this, ex))
case (ELEMENT_NODE)
if (.not.doneAttributes) then
! We dont create an empty node - we insist on having all default
! properties created.
if (getParameter(getDomConfig(doc, ex), "namespaces", ex)) then
new => createElementNS(doc, getNamespaceURI(this, ex), getTagName(this, ex), ex)
else
new => createElement(doc, getTagName(this, ex), ex)
endif
endif
case (ATTRIBUTE_NODE)
if (associated(this, arg).or.getSpecified(this, ex)) then
! We are importing just this attribute node
! or this was an explicitly specified attribute; either
! way, we import it as is, and it remains specified.
if (getParameter(getDomConfig(doc), "namespaces")) then
new => createAttributeNS(doc, getNamespaceURI(this, ex), getName(this, ex), ex)
else
new => createAttribute(doc, getName(this), ex)
endif
call setSpecified(new, .true.)
else
! This is an attribute being imported as part of a hierarchy,
! but its only here by default. Is there a default attribute
! of this name in the new document?
elem => get_element(xds%element_list, &
getTagName(getOwnerElement(this)))
att => get_attribute_declaration(elem, getName(this))
if (attribute_has_default(att)) then
! Create the new default:
if (getParameter(getDomConfig(doc, ex), "namespaces", ex)) then
! We create a namespaced attribute. Of course, its
! namespaceURI remains empty for the moment unless we know it ...
if (prefixOfQName(getName(this, ex))=="xml") then
new => createAttributeNS(doc, &
"http://www.w3.org/XML/1998/namespace", &
getName(this, ex), ex)
elseif (getName(this, ex)=="xmlns" &
.or. prefixOfQName(getName(this, ex))=="xmlns") then
new => createAttributeNS(doc, &
"http://www.w3.org/2000/xmlns/", &
getName(this, ex), ex)
else
! Wait for namespace fixup ...
new => createAttributeNS(doc, "", &
getName(this, ex), ex)
endif
else
new => createAttribute(doc, getName(this, ex), ex)
endif
call setValue(new, str_vs(att%default), ex)
call setSpecified(new, .false.)
endif
! In any case, we dont want to copy the children of this node.
doneChildren=.true.
endif
case (TEXT_NODE)
new => createTextNode(doc, getData(this, ex), ex)
case (CDATA_SECTION_NODE)
new => createCDataSection(doc, getData(this, ex), ex)
case (ENTITY_REFERENCE_NODE)
new => createEntityReference(doc, getNodeName(this, ex), ex)
! This will automatically populate the entity reference if doc defines it, so no children needed
doneChildren = .true.
case (ENTITY_NODE)
new => createEntity(doc, getNodeName(this, ex), &
getPublicId(this, ex), getSystemId(this, ex), &
getNotationName(this, ex), ex)
case (PROCESSING_INSTRUCTION_NODE)
new => createProcessingInstruction(doc, &
getTarget(this, ex), getData(this, ex), ex)
case (COMMENT_NODE)
new => createComment(doc, getData(this, ex), ex)
case (DOCUMENT_NODE)
TOHW_m_dom_throw_error(NOT_SUPPORTED_ERR)
case (DOCUMENT_TYPE_NODE)
TOHW_m_dom_throw_error(NOT_SUPPORTED_ERR)
case (DOCUMENT_FRAGMENT_NODE)
new => createDocumentFragment(doc, ex)
case (NOTATION_NODE)
new => createNotation(doc, getNodeName(this, ex), &
getPublicId(this, ex), getSystemId(this, ex), ex)
end select
if (.not.associated(thatParent)) then
thatParent => new
elseif (associated(new)) then
if (getNodeType(this, ex)==ATTRIBUTE_NODE) then
new => setAttributeNode(thatParent, new, ex)
else
new => appendChild(thatParent, new, ex)
endif
endif
if (.not.deep) then
if (getNodeType(arg, ex)==ATTRIBUTE_NODE &
.or.getNodeType(arg, ex)==ELEMENT_NODE) then
continue
else
exit
endif
endif
', `', `parentNode', `')
np => thatParent
doc%docExtras%brokenNS = brokenNS
! call namespaceFixup(np)
end function importNode
TOHW_function(createElementNS, (arg, namespaceURI, qualifiedName), np)
type(Node), pointer :: arg
character(len=*), intent(in) :: namespaceURI, qualifiedName
type(Node), pointer :: np
type(xml_doc_state), pointer :: xds
type(element_t), pointer :: elem
type(attribute_t), pointer :: att
integer :: i
logical :: brokenNS
type(URI), pointer :: URIref
if (.not.associated(arg)) then
TOHW_m_dom_throw_error(FoX_NODE_IS_NULL)
endif
if (arg%nodeType/=DOCUMENT_NODE) then
TOHW_m_dom_throw_error(FoX_INVALID_NODE)
elseif (.not.checkName(qualifiedName, getXmlVersionEnum(arg))) then
TOHW_m_dom_throw_error(INVALID_CHARACTER_ERR)
elseif (.not.checkQName(qualifiedName, getXmlVersionEnum(arg))) then
TOHW_m_dom_throw_error(NAMESPACE_ERR)
elseif (prefixOfQName(qualifiedName)/="" &
.and. namespaceURI=="".and..not.arg%docExtras%brokenNS) then
TOHW_m_dom_throw_error(NAMESPACE_ERR)
elseif (namespaceURI=="http://www.w3.org/XML/1998/namespace" .neqv. &
prefixOfQName(qualifiedName)=="xml") then
TOHW_m_dom_throw_error(NAMESPACE_ERR)
elseif (namespaceURI=="http://www.w3.org/2000/xmlns/") then
TOHW_m_dom_throw_error(NAMESPACE_ERR)
endif
URIref => parseURI(namespaceURI)
if (.not.associated(URIref)) then
TOHW_m_dom_throw_error(FoX_INVALID_URI)
endif
call destroyURI(URIref)
np => createNode(arg, ELEMENT_NODE, qualifiedName, "")
allocate(np%elExtras)
np%elExtras%namespaceURI => vs_str_alloc(namespaceURI)
np%elExtras%prefix => vs_str_alloc(prefixOfQName(qualifiedname))
np%elExtras%localName => vs_str_alloc(localpartOfQName(qualifiedname))
allocate(np%elExtras%namespaceNodes%nodes(0))
np%elExtras%attributes%ownerElement => np
if (getGCstate(arg)) then
np%inDocument = .false.
call append(arg%docExtras%hangingnodes, np)
! We only add default attributes if we are *not* building the doc
xds => getXds(arg)
elem => get_element(xds%element_list, qualifiedName)
if (associated(elem)) then
do i = 1, get_attlist_size(elem)
att => get_attribute_declaration(elem, i)
if (attribute_has_default(att)) then
! Since this is a namespaced function, we create a namespaced
! attribute. Of course, its namespaceURI remains empty
! for the moment unless we know it ...
if (prefixOfQName(str_vs(att%name))=="xml") then
call setAttributeNS(np, &
"http://www.w3.org/XML/1998/namespace", &
str_vs(att%name), str_vs(att%default), ex)
elseif (str_vs(att%name)=="xmlns" &
.or. prefixOfQName(str_vs(att%name))=="xmlns") then
call setAttributeNS(np, &
"http://www.w3.org/2000/xmlns/", &
str_vs(att%name), str_vs(att%default), ex)
else
! Wait for namespace fixup ...
brokenNS = arg%docExtras%brokenNS
arg%docExtras%brokenNS = .true.
call setAttributeNS(np, "", str_vs(att%name), &
str_vs(att%default), ex)
arg%docExtras%brokenNS = brokenNS
endif
endif
enddo
endif
else
np%inDocument = .true.
endif
end function createElementNS
TOHW_function(createEmptyElementNS, (arg, namespaceURI, qualifiedName), np)
type(Node), pointer :: arg
character(len=*), intent(in) :: namespaceURI, qualifiedName
type(Node), pointer :: np
! NO CHECKS !
np => createNode(arg, ELEMENT_NODE, qualifiedName, "")
allocate(np%elExtras)
np%elExtras%namespaceURI => vs_str_alloc(namespaceURI)
np%elExtras%prefix => vs_str_alloc(prefixOfQName(qualifiedname))
np%elExtras%localName => vs_str_alloc(localpartOfQName(qualifiedname))
allocate(np%elExtras%namespaceNodes%nodes(0))
np%elExtras%attributes%ownerElement => np
if (getGCstate(arg)) then
call append(arg%docExtras%hangingnodes, np)
np%inDocument = .false.
else
np%inDocument = .true.
endif
end function createEmptyElementNS
TOHW_function(createAttributeNS, (arg, namespaceURI, qualifiedname), np)
type(Node), pointer :: arg
character(len=*), intent(in) :: namespaceURI, qualifiedName
type(Node), pointer :: np
type(URI), pointer :: URIref
if (.not.associated(arg)) then
TOHW_m_dom_throw_error(FoX_NODE_IS_NULL)
endif
if (arg%nodeType/=DOCUMENT_NODE) then
TOHW_m_dom_throw_error(FoX_INVALID_NODE)
elseif (.not.checkName(qualifiedName, getXmlVersionEnum(arg))) then
TOHW_m_dom_throw_error(INVALID_CHARACTER_ERR)
elseif (.not.checkQName(qualifiedName, getXmlVersionEnum(arg))) then
TOHW_m_dom_throw_error(NAMESPACE_ERR)
elseif (prefixOfQName(qualifiedName)/="" &
.and. namespaceURI=="".and..not.arg%docExtras%brokenNS) then
TOHW_m_dom_throw_error(NAMESPACE_ERR)
elseif (namespaceURI=="http://www.w3.org/XML/1998/namespace" .neqv. &
prefixOfQName(qualifiedName)=="xml") then
TOHW_m_dom_throw_error(NAMESPACE_ERR)
elseif (namespaceURI=="http://www.w3.org/2000/xmlns/" .neqv. &
(qualifiedName=="xmlns" .or. prefixOfQName(qualifiedName)=="xmlns")) then
TOHW_m_dom_throw_error(NAMESPACE_ERR)
endif
URIref => parseURI(namespaceURI)
if (.not.associated(URIref)) then
TOHW_m_dom_throw_error(FoX_INVALID_URI)
endif
call destroyURI(URIref)
np => createNode(arg, ATTRIBUTE_NODE, qualifiedName, "")
allocate(np%elExtras)
np%elExtras%namespaceURI => vs_str_alloc(namespaceURI)
np%elExtras%localname => vs_str_alloc(localPartofQName(qualifiedname))
np%elExtras%prefix => vs_str_alloc(PrefixofQName(qualifiedname))
if (getGCstate(arg)) then
np%inDocument = .false.
call append(arg%docExtras%hangingnodes, np)
else
np%inDocument = .true.
endif
end function createAttributeNS
TOHW_function(getElementsByTagNameNS, (doc, namespaceURI, localName), list)
type(Node), pointer :: doc
character(len=*), intent(in) :: namespaceURI, localName
type(NodeList), pointer :: list
type(NodeListPtr), pointer :: nll(:), temp_nll(:)
type(Node), pointer :: this, arg, treeroot
logical :: doneChildren, doneAttributes, allLocalNames, allNameSpaces
integer :: i, i_tree
if (.not.associated(doc)) then
TOHW_m_dom_throw_error(FoX_NODE_IS_NULL)
endif
if (doc%nodeType/=DOCUMENT_NODE.and.doc%nodeType/=ELEMENT_NODE) then
TOHW_m_dom_throw_error(FoX_INVALID_NODE)
endif
allNamespaces = (namespaceURI=="*")
allLocalNames = (localName=="*")
if (doc%nodeType==DOCUMENT_NODE) then
arg => getDocumentElement(doc)
else
arg => doc
endif
allocate(list)
allocate(list%nodes(0))
list%element => doc
list%localName => vs_str_alloc(localName)
list%namespaceURI => vs_str_alloc(namespaceURI)
if (doc%nodeType==DOCUMENT_NODE) then
nll => doc%docExtras%nodelists
elseif (doc%nodeType==ELEMENT_NODE) then
nll => doc%ownerDocument%docExtras%nodelists
endif
allocate(temp_nll(size(nll)+1))
do i = 1, size(nll)
temp_nll(i)%this => nll(i)%this
enddo
temp_nll(i)%this => list
deallocate(nll)
if (doc%nodeType==DOCUMENT_NODE) then
doc%docExtras%nodelists => temp_nll
elseif (doc%nodeType==ELEMENT_NODE) then
doc%ownerDocument%docExtras%nodelists => temp_nll
endif
treeroot => arg
TOHW_m_dom_treewalk(`dnl
if (getNodeType(this)==ELEMENT_NODE) then
if (getNamespaceURI(this)/="") then
if ((allNameSpaces .or. getNameSpaceURI(this)==namespaceURI) &
.and. (allLocalNames .or. getLocalName(this)==localName) &
.and..not.(getNodeType(doc)==ELEMENT_NODE.and.associated(this, arg))) &
call append(list, this)
else
if ((allNameSpaces .or. namespaceURI=="") &
.and. (allLocalNames .or. getNodeName(this)==localName) &
.and..not.(getNodeType(doc)==ELEMENT_NODE.and.associated(this, arg))) &
call append(list, this)
endif
doneAttributes = .true. ! Never search attributes
endif
',`')
end function getElementsByTagNameNS
TOHW_function(getElementById, (arg, elementId), np)
type(Node), pointer :: arg
character(len=*), intent(in) :: elementId
type(Node), pointer :: np
type(Node), pointer :: this, treeroot
integer :: i_tree
logical :: doneChildren, doneAttributes
if (.not.associated(arg)) then
TOHW_m_dom_throw_error(FoX_NODE_IS_NULL)
endif
if (arg%nodeType/=DOCUMENT_NODE) then
TOHW_m_dom_throw_error(FoX_INVALID_NODE)
endif
np => null()
treeroot => getDocumentElement(arg)
TOHW_m_dom_treewalk(`dnl
if (this%nodeType==ATTRIBUTE_NODE) then
if (getIsId(this).and.getValue(this)==elementId) then
np => getOwnerElement(this)
return
endif
endif
',`')
end function getElementById
TOHW_m_dom_get(logical, xmlStandalone, np%docExtras%xds%standalone, (DOCUMENT_NODE))
TOHW_m_dom_set(logical, xmlStandalone, np%docExtras%xds%standalone, (DOCUMENT_NODE))
! FIXME additional check on setting - do we have any undefined entrefs present?
TOHW_function(getXmlVersion, (arg), s)
type(Node), pointer :: arg
character(len=3) :: s
if (.not.associated(arg)) then
TOHW_m_dom_throw_error(FoX_NODE_IS_NULL)
endif
if (arg%nodeType/=DOCUMENT_NODE &
.and.arg%nodeType/=ENTITY_NODE) then
TOHW_m_dom_throw_error(FoX_INVALID_NODE)
endif
if (getXmlVersionEnum(arg)==XML1_0) then
s = "1.0"
elseif (getXmlVersionEnum(arg)==XML1_1) then
s = "1.1"
else
s = "XXX"
endif
end function getXmlVersion
TOHW_subroutine(setXmlVersion, (arg, s))
type(Node), pointer :: arg
character(len=*) :: s
if (.not.associated(arg)) then
TOHW_m_dom_throw_error(FoX_NODE_IS_NULL)
endif
if (arg%nodeType/=DOCUMENT_NODE) then
TOHW_m_dom_throw_error(FoX_INVALID_NODE)
endif
if (s=="1.0") then
arg%docExtras%xds%xml_version = XML1_0
elseif (s=="1.1") then
arg%docExtras%xds%xml_version = XML1_1
else
TOHW_m_dom_throw_error(NOT_SUPPORTED_ERR)
endif
end subroutine setXmlVersion
pure function getXmlEncoding_len(arg, p) result(n)
type(Node), pointer :: arg
logical, intent(in) :: p
integer :: n
n = 0