blob: c0aeff59bb80b54eba2d119aaed96e93c9fb2221 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001///////////////////////////////////////////////////////////////////////////
2//
3// Copyright (c) 2000-2003 Intel Corporation
4// All rights reserved.
5//
6// Redistribution and use in source and binary forms, with or without
7// modification, are permitted provided that the following conditions are met:
8//
9// * Redistributions of source code must retain the above copyright notice,
10// this list of conditions and the following disclaimer.
11// * Redistributions in binary form must reproduce the above copyright notice,
12// this list of conditions and the following disclaimer in the documentation
13// and/or other materials provided with the distribution.
14// * Neither name of Intel Corporation nor the names of its contributors
15// may be used to endorse or promote products derived from this software
16// without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
22// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29//
30///////////////////////////////////////////////////////////////////////////
31
32#include <stdio.h>
33#include <stdlib.h>
34
35#include "xmlparser.h"
36
37/*================================================================
38* XmlDocumentInit
39* It initialize the document structure.
40* External function.
41*
42*=================================================================*/
43void
44XmlDocumentInit( XmlDocument * doc )
45{
46 memset( doc, 0, sizeof( XmlDocument ) );
47}
48
49/*================================================================
50* XmlDocumentFree
51* It XFREEs the whole document tree.
52* External function.
53*
54*=================================================================*/
55void
56XmlDocumentFree(
57 Pool * pool,
58 XmlDocument * doc )
59{
60 if ( doc != NULL )
61 {
62 XmlNodeFree(
63#ifdef USE_CWMP_MEMORY_POOL
64 pool ,
65#endif
66 ( XmlNode * ) doc );
67 }
68
69}
70
71/*================================================================
72* XmlDocSetOwnerDocument
73*
74* When this function is called first time, nodeptr is the root
75* of the subtree, so it is not necessay to do two steps
76* recursion.
77*
78* Internal function called by XmlDocImportNode
79*
80*=================================================================*/
81void
82XmlDocSetOwnerDocument( XmlDocument * doc,
83 XmlNode * nodeptr )
84{
85 if ( nodeptr != NULL )
86 {
87 nodeptr->ownerDocument = doc;
88 XmlDocSetOwnerDocument( doc,
89 XmlNodeGetFirstChild( nodeptr ) );
90 XmlDocSetOwnerDocument( doc,
91 XmlNodeGetNextSibling
92 ( nodeptr ) );
93 }
94}
95
96/*================================================================
97* XmlDocImportNode
98* Imports a node from another document to this document. The
99* returned node has no parent; (parentNode is null). The source
100* node is not altered or removed from the original document;
101* this method creates a new copy of the source node.
102
103* For all nodes, importing a node creates a node object owned
104* by the importing document, with attribute values identical to
105* the source node's nodeName and nodeType, plus the attributes
106* related to namespaces (prefix, localName, and namespaceURI).
107* As in the cloneNode operation on a node, the source node is
108* not altered.
109*
110* External function.
111*
112*=================================================================*/
113int
114XmlDocImportNode(
115 Pool * pool,
116
117 XmlDocument * doc,
118 XmlNode * importNode,
119 IN BOOL deep,
120 OUT XmlNode ** rtNode )
121{
122 unsigned short nodeType;
123 XmlNode * newNode;
124
125 *rtNode = NULL;
126
127 if ( ( doc == NULL ) || ( importNode == NULL ) )
128 {
129 return XML_INVALID_PARAMETER;
130 }
131
132 nodeType = XmlNodeGetNodeType( importNode );
133 if ( nodeType == XML_DOCUMENT_NODE )
134 {
135 return XML_NOT_SUPPORTED_ERR;
136 }
137
138 newNode = XmlNodeCloneNode(
139#ifdef USE_CWMP_MEMORY_POOL
140 pool ,
141#endif
142
143 importNode, deep );
144 if ( newNode == NULL )
145 {
146 return XML_FAILED;
147 }
148
149 XmlDocSetOwnerDocument( doc, newNode );
150 *rtNode = newNode;
151
152 return XML_OK;
153}
154
155/*================================================================
156* XmlDocCreateElementEx
157* Creates an element of the type specified.
158* External function.
159* Parameters:
160* doc: pointer to document
161* tagName: The name of the element, it is case-sensitive.
162* Return Value:
163* XML_OK
164* XML_INVALID_PARAMETER: if either doc or tagName is NULL
165* XML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations.
166*
167*=================================================================*/
168int
169#ifdef USE_CWMP_MEMORY_POOL
170XmlDocCreateElementEx(Pool * pool, XmlDocument * doc,
171#else
172XmlDocCreateElementEx( XmlDocument * doc,
173#endif
174
175 IN char * tagName,
176 OUT XmlElement ** rtElement )
177{
178
179 int errCode = XML_OK;
180 XmlElement *newElement = NULL;
181
182 if ( ( doc == NULL ) || ( tagName == NULL ) )
183 {
184 errCode = XML_INVALID_PARAMETER;
185 goto ErrorHandler;
186 }
187
188 newElement = ( XmlElement * ) PMALLOC( sizeof( XmlElement ) );
189 if ( newElement == NULL )
190 {
191 errCode = XML_INSUFFICIENT_MEMORY;
192 goto ErrorHandler;
193 }
194
195 XmlElementInit( newElement );
196 newElement->tagName = PSTRDUP( tagName );
197 if ( newElement->tagName == NULL )
198 {
199 XmlElementFree(
200#ifdef USE_CWMP_MEMORY_POOL
201
202 pool ,
203#endif
204 newElement );
205 newElement = NULL;
206 errCode = XML_INSUFFICIENT_MEMORY;
207 goto ErrorHandler;
208 }
209 // set the node fields
210 newElement->node.nodeType = XML_ELEMENT_NODE;
211 newElement->node.nodeName = PSTRDUP( tagName );
212 if ( newElement->node.nodeName == NULL )
213 {
214 XmlElementFree(
215#ifdef USE_CWMP_MEMORY_POOL
216 pool ,
217#endif
218 newElement );
219 newElement = NULL;
220 errCode = XML_INSUFFICIENT_MEMORY;
221 goto ErrorHandler;
222 }
223
224 newElement->node.ownerDocument = doc;
225
226ErrorHandler:
227 *rtElement = newElement;
228 return errCode;
229
230}
231
232/*================================================================
233* XmlDocCreateElement
234* Creates an element of the type specified.
235* External function.
236* Parameters:
237* doc: pointer to document
238* tagName: The name of the element, it is case-sensitive.
239* Return Value:
240* A new element object with the nodeName set to tagName, and
241* localName, prefix and namespaceURI set to null.
242*
243*=================================================================*/
244XmlElement *
245
246XmlDocCreateElement(
247 Pool * pool,
248 XmlDocument * doc,
249 IN char * tagName )
250{
251 XmlElement *newElement = NULL;
252
253 XmlDocCreateElementEx(
254#ifdef USE_CWMP_MEMORY_POOL
255 pool ,
256#endif
257 doc, tagName, &newElement );
258 return newElement;
259
260}
261
262/*================================================================
263* XmlDocCreateDocumentEx
264* Creates an document object
265* Internal function.
266* Parameters:
267* rtDoc: the document created or NULL on failure
268* Return Value:
269* XML_OK
270* XML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations.
271*
272*=================================================================*/
273int
274XmlDocCreateDocumentEx(
275 Pool * pool,
276 OUT XmlDocument ** rtDoc )
277{
278 XmlDocument *doc;
279 int errCode = XML_OK;
280
281 doc = NULL;
282 doc = ( XmlDocument * ) PMALLOC( sizeof( XmlDocument ) );
283 if ( doc == NULL )
284 {
285 errCode = XML_INSUFFICIENT_MEMORY;
286 goto ErrorHandler;
287 }
288
289 XmlDocumentInit( doc );
290
291 doc->node.nodeName = PSTRDUP( DOCUMENTNODENAME );
292 if ( doc->node.nodeName == NULL )
293 {
294 XmlDocumentFree(
295#ifdef USE_CWMP_MEMORY_POOL
296 pool ,
297#endif
298 doc );
299 doc = NULL;
300 errCode = XML_INSUFFICIENT_MEMORY;
301 goto ErrorHandler;
302 }
303
304 doc->node.nodeType = XML_DOCUMENT_NODE;
305 doc->node.ownerDocument = doc;
306
307ErrorHandler:
308 *rtDoc = doc;
309 return errCode;
310}
311
312/*================================================================
313* XmlDocCreateDocument
314* Creates an document object
315* Internal function.
316* Parameters:
317* none
318* Return Value:
319* A new document object with the nodeName set to "#document".
320*
321*=================================================================*/
322XmlDocument *
323XmlDocCreateDocument(
324#ifdef USE_CWMP_MEMORY_POOL
325 Pool * pool
326#endif
327)
328{
329 XmlDocument *doc = NULL;
330
331 XmlDocCreateDocumentEx(
332#ifdef USE_CWMP_MEMORY_POOL
333 pool ,
334#endif
335 &doc );
336
337 return doc;
338
339}
340
341/*================================================================
342* XmlDocCreateTextNodeEx
343* Creates an text node.
344* External function.
345* Parameters:
346* data: text data for the text node. It is stored in nodeValue field.
347* Return Value:
348* XML_OK
349* XML_INVALID_PARAMETER: if either doc or data is NULL
350* XML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations.
351*
352*=================================================================*/
353int
354#ifdef USE_CWMP_MEMORY_POOL
355XmlDocCreateTextNodeEx(Pool * pool, XmlDocument * doc,
356#else
357XmlDocCreateTextNodeEx( XmlDocument * doc,
358#endif
359 IN char *data,
360 OUT XmlNode ** textNode )
361{
362 XmlNode * returnNode;
363 int rc = XML_OK;
364
365 returnNode = NULL;
366 if ( ( doc == NULL ) || ( data == NULL ) )
367 {
368 rc = XML_INVALID_PARAMETER;
369 goto ErrorHandler;
370 }
371
372 returnNode = ( XmlNode * ) PMALLOC( sizeof( XmlNode ) );
373 if ( returnNode == NULL )
374 {
375 rc = XML_INSUFFICIENT_MEMORY;
376 goto ErrorHandler;
377 }
378 // initialize the node
379 XmlNodeInit( returnNode );
380
381 returnNode->nodeName = PSTRDUP( TEXTNODENAME );
382 if ( returnNode->nodeName == NULL )
383 {
384 XmlNodeFree(
385#ifdef USE_CWMP_MEMORY_POOL
386 pool ,
387#endif
388 returnNode );
389 returnNode = NULL;
390 rc = XML_INSUFFICIENT_MEMORY;
391 goto ErrorHandler;
392 }
393 // add in node value
394// if ( data != NULL ) // kw 3
395 {
396 returnNode->nodeValue = XmlStrduptrim(
397#ifdef USE_CWMP_MEMORY_POOL
398 pool ,
399#endif
400 data );
401 if ( returnNode->nodeValue == NULL )
402 {
403 XmlNodeFree(
404#ifdef USE_CWMP_MEMORY_POOL
405 pool ,
406#endif
407 returnNode );
408 returnNode = NULL;
409 rc = XML_INSUFFICIENT_MEMORY;
410 goto ErrorHandler;
411 }
412 }
413
414 returnNode->nodeType = XML_TEXT_NODE;
415 returnNode->ownerDocument = doc;
416
417ErrorHandler:
418 *textNode = returnNode;
419 return rc;
420
421}
422
423/*================================================================
424* XmlDocCreateTextNode
425* Creates an text node.
426* External function.
427* Parameters:
428* data: text data for the text node. It is stored in nodeValue field.
429* Return Value:
430* The new text node.
431*
432*=================================================================*/
433XmlNode *
434XmlDocCreateTextNode(
435 Pool * pool,
436
437 XmlDocument * doc,
438 IN char *data )
439{
440 XmlNode * returnNode = NULL;
441
442 XmlDocCreateTextNodeEx(
443#ifdef USE_CWMP_MEMORY_POOL
444 pool ,
445#endif
446 doc, data, &returnNode );
447
448 return returnNode;
449}
450
451/*================================================================
452* XmlDocCreateAttributeEx
453* Creates an attribute of the given name.
454* External function.
455* Parameters:
456* name: The name of the Attribute node.
457* Return Value:
458* XML_OK
459* XML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations.
460*
461================================================================*/
462int
463#ifdef USE_CWMP_MEMORY_POOL
464XmlDocCreateAttributeEx(Pool * pool, XmlDocument * doc,
465#else
466XmlDocCreateAttributeEx( XmlDocument * doc,
467#endif
468
469 const char *name,
470 XmlAttribute ** rtAttr )
471{
472 XmlAttribute *attrNode = NULL;
473 int errCode = XML_OK;
474
475 attrNode = ( XmlAttribute * ) PMALLOC( sizeof( XmlAttribute ) );
476 if ( attrNode == NULL )
477 {
478 errCode = XML_INSUFFICIENT_MEMORY;
479 goto ErrorHandler;
480 }
481
482 if ( ( doc == NULL ) || ( name == NULL ) )
483 {
484 XmlAttrFree(
485#ifdef USE_CWMP_MEMORY_POOL
486 pool ,
487#endif
488 attrNode );
489 attrNode = NULL;
490 errCode = XML_INVALID_PARAMETER;
491 goto ErrorHandler;
492 }
493
494 XmlAttrInit( attrNode );
495
496 attrNode->node.nodeType = XML_ATTRIBUTE_NODE;
497
498 // set the node fields
499 attrNode->node.nodeName = PSTRDUP( name );
500 if ( attrNode->node.nodeName == NULL )
501 {
502 XmlAttrFree(
503#ifdef USE_CWMP_MEMORY_POOL
504 pool ,
505#endif
506 attrNode );
507 attrNode = NULL;
508 errCode = XML_INSUFFICIENT_MEMORY;
509 goto ErrorHandler;
510 }
511
512 attrNode->node.ownerDocument = doc;
513
514ErrorHandler:
515 *rtAttr = attrNode;
516 return errCode;
517
518}
519
520/*================================================================
521* XmlDocCreateAttribute
522* Creates an attribute of the given name.
523* External function.
524* Parameters:
525* name: The name of the Attribute node.
526* Return Value:
527* A new attr object with the nodeName attribute set to the
528* given name, and the localName, prefix and namespaceURI set to NULL.
529* The value of the attribute is the empty string.
530*
531================================================================*/
532XmlAttribute *
533XmlDocCreateAttribute(
534 Pool * pool,
535 XmlDocument * doc,
536 IN char *name )
537{
538 XmlAttribute *attrNode = NULL;
539
540 XmlDocCreateAttributeEx(
541#ifdef USE_CWMP_MEMORY_POOL
542 pool ,
543#endif
544
545 doc, name, &attrNode );
546 return attrNode;
547
548}
549
550/*================================================================
551* XmlDocCreateAttributeNSEx
552* Creates an attrbute of the given name and namespace URI
553* External function.
554* Parameters:
555* namespaceURI: the namespace fo the attribute to create
556* qualifiedName: qualifiedName of the attribute to instantiate
557* Return Value:
558* XML_OK
559* XML_INVALID_PARAMETER: if either doc,namespaceURI or qualifiedName is NULL
560* XML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations.
561*
562*=================================================================*/
563int
564XmlDocCreateAttributeNSEx(
565 Pool * pool,
566
567 XmlDocument * doc,
568 const char * namespaceURI,
569 const char * qualifiedName,
570 OUT XmlAttribute ** rtAttr )
571{
572 XmlAttribute *attrNode = NULL;
573 int errCode = XML_OK;
574
575 if ( ( doc == NULL ) || ( namespaceURI == NULL )
576 || ( qualifiedName == NULL ) )
577 {
578 errCode = XML_INVALID_PARAMETER;
579 goto ErrorHandler;
580 }
581
582 errCode =
583 XmlDocCreateAttributeEx(
584#ifdef USE_CWMP_MEMORY_POOL
585 pool ,
586#endif
587
588 doc, qualifiedName, &attrNode );
589 if ( errCode != XML_OK )
590 {
591 goto ErrorHandler;
592 }
593 // set the namespaceURI field
594 attrNode->node.namespaceURI = PSTRDUP( namespaceURI );
595 if ( attrNode->node.namespaceURI == NULL )
596 {
597 XmlAttrFree(
598#ifdef USE_CWMP_MEMORY_POOL
599 pool ,
600#endif
601 attrNode );
602 attrNode = NULL;
603 errCode = XML_INSUFFICIENT_MEMORY;
604 goto ErrorHandler;
605 }
606 // set the localName and prefix
607 errCode =
608 XmlNodeSetNodeName(
609#ifdef USE_CWMP_MEMORY_POOL
610 pool ,
611#endif
612
613 ( XmlNode * ) attrNode, qualifiedName );
614 if ( errCode != XML_OK )
615 {
616 XmlAttrFree(
617#ifdef USE_CWMP_MEMORY_POOL
618 pool ,
619#endif
620 attrNode );
621 attrNode = NULL;
622 goto ErrorHandler;
623 }
624
625ErrorHandler:
626 *rtAttr = attrNode;
627 return errCode;
628
629}
630
631/*================================================================
632* XmlDocCreateAttributeNS
633* Creates an attrbute of the given name and namespace URI
634* External function.
635* Parameters:
636* namespaceURI: the namespace fo the attribute to create
637* qualifiedName: qualifiedName of the attribute to instantiate
638* Return Value:
639* Creates an attribute node with the given namespaceURI and
640* qualifiedName. The prefix and localname are extracted from
641* the qualifiedName. The node value is empty.
642*
643*=================================================================*/
644XmlAttribute *
645XmlDocCreateAttributeNS(
646 Pool * pool,
647
648 XmlDocument * doc,
649 IN char * namespaceURI,
650 IN char * qualifiedName )
651{
652 XmlAttribute *attrNode = NULL;
653
654 XmlDocCreateAttributeNSEx(
655#ifdef USE_CWMP_MEMORY_POOL
656 pool ,
657#endif
658
659 doc, namespaceURI, qualifiedName,
660 &attrNode );
661 return attrNode;
662}
663
664/*================================================================
665* XmlDocCreateCDATASectionEx
666* Creates an CDATASection node whose value is the specified string
667* External function.
668* Parameters:
669* data: the data for the CDATASection contents.
670* Return Value:
671* XML_OK
672* XML_INVALID_PARAMETER: if either doc or data is NULL
673* XML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations.
674*
675*=================================================================*/
676int
677#ifdef USE_CWMP_MEMORY_POOL
678XmlDocCreateCDATASectionEx(Pool * pool, XmlDocument * doc,
679#else
680XmlDocCreateCDATASectionEx( XmlDocument * doc,
681#endif
682 IN char * data,
683 OUT XmlCDATASection ** rtCD )
684{
685 int errCode = XML_OK;
686 XmlCDATASection *cDSectionNode = NULL;
687
688 if ( ( doc == NULL ) || ( data == NULL ) )
689 {
690 errCode = XML_INVALID_PARAMETER;
691 goto ErrorHandler;
692 }
693
694 cDSectionNode =
695 ( XmlCDATASection * ) PMALLOC( sizeof( XmlCDATASection ) );
696 if ( cDSectionNode == NULL )
697 {
698 errCode = XML_INSUFFICIENT_MEMORY;
699 goto ErrorHandler;
700 }
701
702 XmlCDATASectionInit( cDSectionNode );
703
704 cDSectionNode->node.nodeType = XML_CDATA_SECTION_NODE;
705 cDSectionNode->node.nodeName = PSTRDUP( CDATANODENAME );
706 if ( cDSectionNode->node.nodeName == NULL )
707 {
708 XmlCDATASectionFree(
709#ifdef USE_CWMP_MEMORY_POOL
710 pool ,
711#endif
712 cDSectionNode );
713 cDSectionNode = NULL;
714 errCode = XML_INSUFFICIENT_MEMORY;
715 goto ErrorHandler;
716 }
717
718 cDSectionNode->node.nodeValue = XmlStrduptrim(
719#ifdef USE_CWMP_MEMORY_POOL
720 pool ,
721#endif
722 data );
723 if ( cDSectionNode->node.nodeValue == NULL )
724 {
725 XmlCDATASectionFree(
726#ifdef USE_CWMP_MEMORY_POOL
727 pool ,
728#endif
729 cDSectionNode );
730 cDSectionNode = NULL;
731 errCode = XML_INSUFFICIENT_MEMORY;
732 goto ErrorHandler;
733 }
734
735 cDSectionNode->node.ownerDocument = doc;
736
737ErrorHandler:
738 *rtCD = cDSectionNode;
739 return errCode;
740
741}
742
743/*================================================================
744* XmlDocCreateCDATASection
745* Creates an CDATASection node whose value is the specified string
746* External function.
747* Parameters:
748* data: the data for the CDATASection contents.
749* Return Value:
750* The new CDATASection object.
751*
752*=================================================================*/
753XmlCDATASection *
754XmlDocCreateCDATASection(
755 Pool * pool,
756
757 XmlDocument * doc,
758 IN char * data )
759{
760
761 XmlCDATASection *cDSectionNode = NULL;
762
763 XmlDocCreateCDATASectionEx(
764#ifdef USE_CWMP_MEMORY_POOL
765 pool ,
766#endif
767
768 doc, data, &cDSectionNode );
769 return cDSectionNode;
770}
771
772/*================================================================
773* XmlDocCreateElementNSEx
774* Creates an element of the given qualified name and namespace URI.
775* External function.
776* Parameters:
777* namespaceURI: the namespace URI of the element to create.
778* qualifiedName: the qualified name of the element to instantiate.
779* Return Value:
780* Return Value:
781* XML_OK
782* XML_INVALID_PARAMETER: if either doc,namespaceURI or qualifiedName is NULL
783* XML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations.
784*
785*=================================================================*/
786int
787XmlDocCreateElementNSEx(
788 Pool * pool,
789
790 XmlDocument * doc,
791 IN char * namespaceURI,
792 IN char * qualifiedName,
793 OUT XmlElement ** rtElement )
794{
795
796 XmlElement *newElement = NULL;
797 int errCode = XML_OK;
798
799 if ( ( doc == NULL ) || ( namespaceURI == NULL )
800 || ( qualifiedName == NULL ) )
801 {
802 errCode = XML_INVALID_PARAMETER;
803 goto ErrorHandler;
804 }
805
806 errCode =
807 XmlDocCreateElementEx(
808#ifdef USE_CWMP_MEMORY_POOL
809 pool ,
810#endif
811
812 doc, qualifiedName, &newElement );
813 if ( errCode != XML_OK )
814 {
815 goto ErrorHandler;
816 }
817 // set the namespaceURI field
818 newElement->node.namespaceURI = PSTRDUP( namespaceURI );
819 if ( newElement->node.namespaceURI == NULL )
820 {
821 XmlElementFree(
822#ifdef USE_CWMP_MEMORY_POOL
823 pool ,
824#endif
825 newElement );
826 newElement = NULL;
827 errCode = XML_INSUFFICIENT_MEMORY;
828 goto ErrorHandler;
829 }
830 // set the localName and prefix
831 errCode =
832 XmlNodeSetNodeName(
833#ifdef USE_CWMP_MEMORY_POOL
834 pool ,
835#endif
836
837 ( XmlNode * ) newElement, qualifiedName );
838 if ( errCode != XML_OK )
839 {
840 XmlElementFree(
841#ifdef USE_CWMP_MEMORY_POOL
842 pool ,
843#endif
844 newElement );
845 newElement = NULL;
846 errCode = XML_INSUFFICIENT_MEMORY;
847 goto ErrorHandler;
848 }
849
850 newElement->node.nodeValue = NULL;
851
852ErrorHandler:
853 *rtElement = newElement;
854 return errCode;
855
856}
857
858/*================================================================
859* XmlDocCreateElementNS
860* Creates an element of the given qualified name and namespace URI.
861* External function.
862* Parameters:
863* namespaceURI: the namespace URI of the element to create.
864* qualifiedName: the qualified name of the element to instantiate.
865* Return Value:
866* The new element object with tagName qualifiedName, prefix and
867* localName extraced from qualfiedName, nodeName of qualfiedName,
868* namespaceURI of namespaceURI.
869*
870*=================================================================*/
871XmlElement *
872XmlDocCreateElementNS(
873 Pool * pool,
874
875 XmlDocument * doc,
876 IN char * namespaceURI,
877 IN char * qualifiedName )
878{
879 XmlElement *newElement = NULL;
880
881 XmlDocCreateElementNSEx(
882#ifdef USE_CWMP_MEMORY_POOL
883 pool ,
884#endif
885
886 doc, namespaceURI, qualifiedName,
887 &newElement );
888 return newElement;
889}
890
891/*================================================================
892* XmlDocGetElementsByTagName
893* Returns a nodeList of all the Elements with a given tag name
894* in the order in which they are encountered in a preorder traversal
895* of the document tree.
896* External function.
897* Parameters:
898* tagName: the name of the tag to match on. The special value "*"
899* matches all tags.
900* Return Value:
901* A new nodeList object containing all the matched Elements.
902*
903*=================================================================*/
904XmlNodeList *
905XmlDocGetElementsByTagName(
906 Pool * pool,
907 XmlDocument * doc,
908 IN char *tagName )
909{
910 XmlNodeList *returnNodeList = NULL;
911
912 if ( ( doc == NULL ) || ( tagName == NULL ) )
913 {
914 return NULL;
915 }
916
917 XmlNodeGetElementsByTagName(
918#ifdef USE_CWMP_MEMORY_POOL
919 pool ,
920#endif
921 ( XmlNode * ) doc, tagName,
922 &returnNodeList );
923 return returnNodeList;
924}
925
926/*================================================================
927* XmlDocGetElementsByTagNameNS
928* Returns a nodeList of all the Elements with a given local name and
929* namespace URI in the order in which they are encountered in a
930* preorder traversal of the document tree.
931* External function.
932* Parameters:
933* namespaceURI: the namespace of the elements to match on. The special
934* value "*" matches all namespaces.
935* localName: the local name of the elements to match on. The special
936* value "*" matches all local names.
937* Return Value:
938* A new nodeList object containing all the matched Elements.
939*
940*=================================================================*/
941XmlNodeList *
942XmlDocGetElementsByTagNameNS(
943 Pool * pool,
944 XmlDocument * doc,
945 IN char * namespaceURI,
946 IN char * localName )
947{
948 XmlNodeList *returnNodeList = NULL;
949
950 if ( ( doc == NULL ) || ( namespaceURI == NULL )
951 || ( localName == NULL ) )
952 {
953 return NULL;
954 }
955
956 XmlNodeGetElementsByTagNameNS(
957#ifdef USE_CWMP_MEMORY_POOL
958 pool ,
959#endif
960 ( XmlNode * ) doc, namespaceURI,
961 localName, &returnNodeList );
962 return returnNodeList;
963}
964
965/*================================================================
966* XmlDocGetElementById
967* Returns the element whose ID is given by tagName. If no such
968* element exists, returns null.
969* External function.
970* Parameter:
971* tagName: the tag name for an element.
972* Return Values:
973* The matching element.
974*
975*=================================================================*/
976XmlElement *
977XmlDocGetElementById( XmlDocument * doc,
978 IN char * tagName )
979{
980 XmlElement *rtElement = NULL;
981 XmlNode * nodeptr = ( XmlNode * ) doc;
982 const char *name;
983
984 if ( ( nodeptr == NULL ) || ( tagName == NULL ) )
985 {
986 return rtElement;
987 }
988
989 if ( XmlNodeGetNodeType( nodeptr ) == XML_ELEMENT_NODE )
990 {
991 name = XmlNodeGetNodeName( nodeptr );
992 if ( name == NULL )
993 {
994 return rtElement;
995 }
996
997 if ( strcmp( tagName, name ) == 0 )
998 {
999 rtElement = ( XmlElement * ) nodeptr;
1000 return rtElement;
1001 }
1002 else
1003 {
1004 rtElement = XmlDocGetElementById( ( XmlDocument * )
1005 XmlNodeGetFirstChild
1006 ( nodeptr ),
1007 tagName );
1008 if ( rtElement == NULL )
1009 {
1010 rtElement = XmlDocGetElementById( ( XmlDocument
1011 * )
1012 XmlNodeGetNextSibling
1013 ( nodeptr ),
1014 tagName );
1015 }
1016 }
1017 }
1018 else
1019 {
1020 rtElement = XmlDocGetElementById( ( XmlDocument * )
1021 XmlNodeGetFirstChild
1022 ( nodeptr ), tagName );
1023 if ( rtElement == NULL )
1024 {
1025 rtElement = XmlDocGetElementById( ( XmlDocument * )
1026 XmlNodeGetNextSibling
1027 ( nodeptr ),
1028 tagName );
1029 }
1030 }
1031
1032 return rtElement;
1033}