xmlwrite.cpp
Upload User: zhongxx05
Upload Date: 2007-06-06
Package Size: 33641k
Code Size: 18k
Category:

Symbian

Development Platform:

C/C++

  1. /* ***** BEGIN LICENSE BLOCK ***** 
  2.  * Version: RCSL 1.0 
  3.  *  
  4.  * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 
  5.  *  
  6.  * The contents of this file, and the files included with this file, are 
  7.  * subject to the current version of RealNetworks Community Source License 
  8.  * Version 1.0 (the "License"). You may not use this file except in 
  9.  * compliance with the License executed by both you and RealNetworks.  You 
  10.  * may obtain a copy of the License at  
  11.  * http://www.helixcommunity.org/content/rcsl.  You may also obtain a 
  12.  * copy of the License by contacting RealNetworks directly.  Please see the 
  13.  * License for the rights, obligations and limitations governing use of the 
  14.  * contents of the file. 
  15.  *  
  16.  * This file is part of the Helix DNA Technology. RealNetworks is the 
  17.  * developer of the Original Code and owns the copyrights in the portions 
  18.  * it created. 
  19.  *  
  20.  * This file, and the files included with this file, is distributed and made 
  21.  * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  22.  * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  23.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 
  24.  * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.  
  25.  * 
  26.  * Technology Compatibility Kit Test Suite(s) Location: 
  27.  *    http://www.helixcommunity.org/content/tck 
  28.  * 
  29.  * Contributor(s): 
  30.  *  
  31.  * ***** END LICENSE BLOCK ***** */ 
  32. /* 
  33.  * $Id: xmlwrite.cpp,v 1.5 2003/05/01 16:15:40 sblachowicz Exp $
  34.  *
  35.  * XMLWriter Class Implementation File
  36.  * -----------------------------------
  37.  * 
  38.  * Author: Consumer Group
  39.  * RealNetworks Inc., Copyright (C) 1997, All rights reserved
  40.  * January 12, 1999
  41.  *
  42.  * Abstraction:
  43.  * This file contains the implementation of the XMLWriter class and all it's 
  44.  * helper classes.
  45.  *
  46.  */
  47. // Includes for this file...
  48. #include "xmlwrite.h"
  49. #include "looseprs.h"
  50. #include "hxslist.h"
  51. #include "chxdataf.h"
  52. #include "hxcom.h"
  53. #include "hxbuffer.h"
  54. #include "hxstrutl.h"
  55. //#include <fcntl.h>
  56. // For debugging...
  57. #include "hxassert.h"
  58. #include "hxheap.h"
  59. #ifdef _DEBUG
  60. #undef HX_THIS_FILE             
  61. static const char HX_THIS_FILE[] = __FILE__;
  62. #endif
  63. #define MAX_WRITER_BUFFER 1024
  64. #if defined _WINDOWS
  65. #define WRITER_EOL "n"
  66. #elif defined _MACINTOSH
  67. #define WRITER_EOL "r"
  68. #else
  69. #define WRITER_EOL "n"
  70. #endif
  71. /*
  72.  * XMLWriter
  73.  * ---------
  74.  * Constructor.
  75.  *
  76.  * input:
  77.  * void
  78.  *
  79.  * output:
  80.  * N/A
  81.  *
  82.  */
  83. XMLWriter::XMLWriter(void)
  84. {
  85. }
  86. /*
  87.  * ~XMLWriter
  88.  * ----------
  89.  * Destructor.
  90.  *
  91.  * input:
  92.  * void
  93.  *
  94.  * output:
  95.  * N/A
  96.  *
  97.  */
  98. XMLWriter::~XMLWriter(void)
  99. {
  100.     // Clear it...
  101.     Clear();
  102. }
  103. /*
  104.  * CreateTag
  105.  * ---------
  106.  * Creates a tag in the writer and returns a pointer to it.
  107.  *
  108.  * input:
  109.  * const char *name     - Name for the tag.
  110.  *
  111.  * output:
  112.  * XMLWriterTag *     - Pointer to the newly created tag.
  113.  *
  114.  */
  115. XMLWriterTag *
  116. XMLWriter::CreateTag(const char *name)
  117. {
  118.     // Create the tag...
  119.     XMLWriterTag *newTag = new XMLWriterTag;
  120.     HX_ASSERT(newTag != NULL);
  121.     newTag->SetName(name);
  122.     
  123.     // Add the tag to the array...
  124.     m_tags.AddTail(newTag);
  125.     return newTag;
  126. }
  127. /*
  128.  * Write
  129.  * -----
  130.  * Writes all the data to a IHXBuffer object and returns a pointer to the buffer.
  131.  *
  132.  * input:
  133.  * IHXBuffer * - Pointer to an IHXBuffer.  User must delete it.
  134.  * INT32& length - Number of characters written out to the buffer.
  135.  *
  136.  * output:
  137.  * BOOL - TRUE if successful.
  138.  *
  139.  */
  140. BOOL
  141. XMLWriter::Write(IHXBuffer *buffer, INT32& numChars)
  142. {
  143.     HX_ASSERT(buffer != NULL);
  144.     // Get the size required...
  145.     INT32 length = GetLength();
  146.     // Set the size for the buffer...
  147.     buffer->SetSize(length + length/2);
  148.     // Go through the tags and write them to the buffer...
  149.     LISTPOSITION position = m_tags.GetHeadPosition();
  150.     while (position != NULL)
  151. ((XMLWriterTag *)(m_tags.GetNext(position)))->Write(buffer, numChars);
  152.     // Ok..
  153.     return TRUE;
  154. }
  155. /* 
  156.  * GetLength
  157.  * ---------
  158.  * Returns the entire length required for the tree of xml.
  159.  *
  160.  * input:
  161.  * void
  162.  *
  163.  * output:
  164.  * INT32     - Length to write the xml.
  165.  *
  166.  */
  167. INT32
  168. XMLWriter::GetLength(void) const
  169. {
  170.     INT32 length = 0;
  171.     // Go through the list of tags and sum up their individual lengths....
  172.     LISTPOSITION position = m_tags.GetHeadPosition();
  173.     while (position != NULL)
  174.     {
  175. XMLWriterTag *tag = (XMLWriterTag *)(m_tags.GetNext(position));
  176. length += tag->GetLength();
  177.     }
  178.     return length;
  179. }
  180. /* 
  181.  * Clear
  182.  * -----
  183.  * Clear the structure from memory.
  184.  *
  185.  * input:
  186.  * void
  187.  *
  188.  * output:
  189.  * void
  190.  *
  191.  */
  192. void
  193. XMLWriter::Clear(void)
  194. {
  195.     // If there are any tags in the list, delete them...
  196.     LISTPOSITION position = m_tags.GetHeadPosition();
  197.     while(position != NULL)
  198.     {
  199. delete (XMLWriterTag *)(m_tags.GetNext(position));
  200.     }
  201. }
  202. //*****************************************************************************************************************
  203. // XMLWriterAttribute Implementation
  204. //*****************************************************************************************************************
  205.  
  206. /*
  207.  * XMLWriterAttribute
  208.  * ------------------
  209.  * Writer attribute constructor.
  210.  *
  211.  * input:
  212.  * void
  213.  *
  214.  * output:
  215.  * N/A
  216.  *
  217.  */
  218. XMLWriterAttribute::XMLWriterAttribute(void) : m_name(NULL), m_value(NULL)
  219. {
  220. }
  221.  
  222. /* 
  223.  * ~XMLWriterAttribute
  224.  * -------------------
  225.  * Writer attribute destructor.
  226.  *
  227.  * input:
  228.  * void
  229.  *
  230.  * output:
  231.  * N/A
  232.  *
  233.  */
  234. XMLWriterAttribute::~XMLWriterAttribute(void)
  235. {
  236.     // Delete the strings...
  237.     if (m_name != NULL) delete [] m_name;
  238.     if (m_value != NULL) delete [] m_value;
  239.     m_name = m_value = NULL;
  240. }
  241. /* 
  242.  * Write
  243.  * -----
  244.  * Write to the given buffer.
  245.  *
  246.  * input:
  247.  * IHXBuffer *buffer     - Buffer to write to.
  248.  * INT32 loc     - Pointer into the buffer from where to begin to write.
  249.  *
  250.  * output:
  251.  * void
  252.  *
  253.  */
  254. void
  255. XMLWriterAttribute::Write(IHXBuffer *buffer, INT32& loc)
  256. {
  257.     HX_ASSERT(buffer != NULL);
  258.     
  259.     // If either the name or the value are empty, do not write anything out...
  260.     if (m_name == NULL) return;
  261.     // Properly format what we will write out...
  262.     char temp[MAX_WRITER_BUFFER]; /* Flawfinder: ignore */
  263.     temp[0] = '';
  264.     char tabs[MAX_WRITER_BUFFER]; /* Flawfinder: ignore */
  265.     tabs[0] = '';
  266.     // Create the proper indentation...
  267.     for (INT32 i = 0; i < m_depth; i++)
  268. SafeStrCat(tabs, "t", MAX_WRITER_BUFFER);
  269.     // Create the output string...
  270.     SafeSprintf(temp, MAX_WRITER_BUFFER, "%s%s="%s"", tabs, m_name, m_value);
  271.     // Write to file...
  272.     SafeStrCpy((char *)(buffer->GetBuffer()) + loc,  temp, buffer->GetSize()-loc);
  273.     loc += strlen(temp);
  274. }
  275. /*
  276.  * GetLength
  277.  * ---------
  278.  * Returns the length required to print this attribute.
  279.  *
  280.  * input:
  281.  * void
  282.  *
  283.  * output:
  284.  * INT32     - Length required.
  285.  *
  286.  */
  287. INT32 
  288. XMLWriterAttribute::GetLength(void) const
  289. {
  290.     // Get the lengths of the strings and return their sum...
  291.     INT32 nameLength = strlen(m_name);
  292.     INT32 valueLength = strlen(m_value);
  293.     return m_depth + nameLength + valueLength + 2;
  294. }
  295. /*
  296.  * SetName
  297.  * -------
  298.  * Set the name for the attribute.
  299.  *
  300.  * input:
  301.  * const char *name     - Name of the attribute.
  302.  *
  303.  * output:
  304.  * void
  305.  *
  306.  */
  307. void 
  308. XMLWriterAttribute::SetName(const char *name)
  309. {
  310.     if (m_name != NULL) delete [] m_name;
  311.     m_name = NULL;
  312.     if (name == NULL) return;
  313.     m_name = new char[strlen(name) + 1];
  314.     strcpy(m_name, name); /* Flawfinder: ignore */
  315. }
  316. /*
  317.  * SetValue
  318.  * --------
  319.  * Set the value for the attribute.
  320.  *
  321.  * input:
  322.  * const char *value - Value of the attribute.
  323.  *
  324.  * output:
  325.  * void
  326.  *
  327.  */
  328. void
  329. XMLWriterAttribute::SetValue(const char *value)
  330. {
  331.     if (m_value != NULL) delete [] m_value;
  332.     m_value = NULL;
  333.     if (value == NULL) return;
  334.     m_value = new char[strlen(value) + 1];
  335.     strcpy(m_value, value); /* Flawfinder: ignore */
  336. }
  337. //*****************************************************************************************************************
  338. // XMLWriterTag Implementation
  339. //*****************************************************************************************************************
  340. /* 
  341.  * XMLWriterTag
  342.  * ------------
  343.  * Constructor.
  344.  *
  345.  * input:
  346.  * void
  347.  *
  348.  * output:
  349.  * N/A
  350.  *
  351.  */
  352. XMLWriterTag::XMLWriterTag(void) : m_type(XMLPlainTag), m_name(NULL), m_comment(NULL), m_depth(0)
  353. {
  354. }
  355. /* 
  356.  * ~XMLWriterTag
  357.  * -------------
  358.  * Destructor.
  359.  *
  360.  * input:
  361.  * void
  362.  *
  363.  * output:
  364.  * N/A
  365.  *
  366.  */
  367. XMLWriterTag::~XMLWriterTag(void)
  368. {
  369.     // Go through the list of children and delete each of them.  This will then be
  370.     // repeated by the children's children and we will recursively delete the tree.
  371.     LISTPOSITION tagPosition = m_tags.GetHeadPosition();
  372.     while (tagPosition != NULL)
  373.     {
  374. delete (XMLWriterTag *)(m_tags.GetNext(tagPosition));
  375.     }
  376.     // Delete the attributes...
  377.     LISTPOSITION attrPosition = m_attributes.GetHeadPosition();
  378.     while (attrPosition != NULL)
  379.     {
  380. delete (XMLWriterAttribute *)(m_attributes.GetNext(attrPosition));
  381.     }   
  382.     // Delete the strings...
  383.     if (m_name != NULL) delete [] m_name;
  384.     if (m_comment != NULL) delete [] m_comment;
  385.     m_name = NULL;
  386.     m_comment = NULL;
  387. }
  388. /*
  389.  * GetLength
  390.  * ---------
  391.  * Returns the length required to print this and all it's attributes.
  392.  *
  393.  * input:
  394.  * void
  395.  *
  396.  * output:
  397.  * INT32     - The length required.
  398.  *
  399.  */
  400. INT32
  401. XMLWriterTag::GetLength(void) const
  402. {
  403.     INT32 length = 0;
  404.     // Get the combined attributes lengths...
  405.     LISTPOSITION position = m_attributes.GetHeadPosition();
  406.     while (position != NULL)
  407.     {
  408. length += ((XMLWriterAttribute *)(m_attributes.GetNext(position)))->GetLength();
  409.     }
  410.     // Get the combined lengths of the child tags...
  411.     position = m_tags.GetHeadPosition();
  412.     while (position != NULL)
  413.     {
  414. length += ((XMLWriterTag *)(m_tags.GetNext(position)))->GetLength();
  415.     }
  416.     // Tack on the length required in the different cases...
  417.     length += 2*m_depth + ((m_name != NULL)? 2*(strlen(m_name)) : 0) + 20 + ((m_comment != NULL)? strlen(m_comment) : 0);   // 20 is arbitrary, based on all the stuff needed for brackets and slashes.
  418.     return length;
  419. }
  420. /*
  421.  * Write
  422.  * -----
  423.  * Write out this tag to the given file object.
  424.  *
  425.  * input:
  426.  * IHXBuffer *buffer - Pointer to buffer to use.
  427.  * INT32& loc - Pointer to a location in the buffer where to print to.
  428.  *
  429.  * output:
  430.  * void
  431.  *
  432.  */
  433. void
  434. XMLWriterTag::Write(IHXBuffer *buffer, INT32& loc)
  435. {
  436.     char temp[MAX_WRITER_BUFFER]; /* Flawfinder: ignore */
  437.     char tabs[MAX_WRITER_BUFFER]; /* Flawfinder: ignore */
  438.     temp[0] = tabs[0] = '';
  439.     
  440.     // See the depth of this tag and create a string composed of depth number of tabs...
  441.     for (INT32 i = 0; i < m_depth; i++)
  442. SafeStrCat(tabs,  "t", MAX_WRITER_BUFFER);
  443.     // Switch on the type of tag...
  444.     switch (m_type)
  445.     {
  446.     case XMLPlainTag:
  447. {
  448.     // If the name field is empty, return...
  449.     if (m_name == NULL) return;
  450.     // If there are attributes....
  451.     if (m_attributes.GetCount() > 0)
  452.     {
  453. // Open the open tag...
  454. SafeSprintf(temp, MAX_WRITER_BUFFER, "%s<%s%s", tabs, m_name, WRITER_EOL);
  455. SafeStrCpy((char *)(buffer->GetBuffer()) + loc,  temp, buffer->GetSize()-loc);
  456. loc += strlen(temp);
  457. // Write the attributes...
  458. WriteAttributes(buffer, loc);
  459. // Close the open tag...
  460. SafeSprintf(temp, MAX_WRITER_BUFFER, ">%s", WRITER_EOL);
  461. SafeStrCpy((char *)(buffer->GetBuffer()) + loc,  temp, buffer->GetSize()-loc);
  462. loc += strlen(temp);
  463. // Write any other tags...
  464. WriteTags(buffer, loc);
  465. // Write the closing tag...
  466. SafeSprintf(temp, MAX_WRITER_BUFFER, "%s</%s>%s", tabs, m_name, WRITER_EOL);
  467. SafeStrCpy((char *)(buffer->GetBuffer()) + loc,  temp, buffer->GetSize()-loc);
  468. loc += strlen(temp);
  469.     }
  470.     // When there are no attributes, just open and close the tag...
  471.     else
  472.     {
  473. // Open the tag...
  474. SafeSprintf(temp, MAX_WRITER_BUFFER, "%s<%s>%s", tabs, m_name, WRITER_EOL);
  475. SafeStrCpy((char *)(buffer->GetBuffer()) + loc,  temp, buffer->GetSize()-loc);
  476. loc += strlen(temp);
  477. // Write the other tags...
  478. WriteTags(buffer, loc);
  479. // Close the tag...
  480. SafeSprintf(temp, MAX_WRITER_BUFFER, "%s</%s>%s", tabs, m_name, WRITER_EOL);
  481. SafeStrCpy((char *)(buffer->GetBuffer()) + loc,  temp, buffer->GetSize()-loc);
  482. loc += strlen(temp);
  483.     }
  484. }
  485. break;
  486.     case XMLCommentTag:
  487. {
  488.     // If the comment field is empty, return...
  489.     if (m_comment == NULL) return;
  490.     // Otherwise, format it and write it out...
  491.     SafeSprintf(temp, MAX_WRITER_BUFFER, "%s<-- %s -->%s", tabs, m_comment, WRITER_EOL);
  492.     SafeStrCpy((char *)(buffer->GetBuffer()) + loc,  temp, buffer->GetSize()-loc);
  493.     loc += strlen(temp);
  494. }
  495. break;
  496.     case XMLDirectiveTag:
  497. {
  498. }
  499. break;
  500.     case XMLProcInstTag:
  501. {
  502.     // If there are no attributes, then don't print out...
  503.     if (m_attributes.IsEmpty()) return;
  504.     if (m_name == NULL) return;
  505.     // Otherwise, format the beginning...
  506.     SafeSprintf(temp, MAX_WRITER_BUFFER, "%s<?%s ", tabs, m_name);
  507.     SafeStrCpy((char *)(buffer->GetBuffer()) + loc,  temp, buffer->GetSize()-loc);
  508.     loc += strlen(temp);
  509.     // Write out the attributes...
  510.     WriteAttributes(buffer, loc);
  511.     // Format the ending...
  512.     SafeSprintf(temp, buffer->GetSize()-loc, "?>%s", WRITER_EOL);
  513.     SafeStrCpy((char *)(buffer->GetBuffer()) + loc,  temp, buffer->GetSize()-loc);
  514.     loc += strlen(temp);
  515. }
  516. break;
  517.     }
  518. }
  519. /* 
  520.  * SetProcessingInstruction
  521.  * ------------------------
  522.  * Make this tag a processing instruction.
  523.  *
  524.  * input:
  525.  * const char *instruction     - Name of the instruction to use.
  526.  *
  527.  * output:
  528.  * void
  529.  *
  530.  */
  531. void 
  532. XMLWriterTag::SetProcessingInstruction(const char *instruction)
  533. {
  534.     m_type = XMLProcInstTag;
  535.     if (m_name != NULL) delete [] m_name;
  536.     m_name = NULL;
  537.     if (instruction != NULL)
  538.     {
  539. m_name = new char[strlen(instruction) + 1];
  540. strcpy(m_name, instruction); /* Flawfinder: ignore */
  541.     }
  542. }
  543. /*
  544.  * WriteAttributes
  545.  * ---------------
  546.  * Write out the attributes for this tag.
  547.  *
  548.  * input:
  549.  * IHXBuffer *buffer - Buffer to write to.
  550.  * INT32& loc - Location to where we start writing.
  551.  *
  552.  * output:
  553.  * void
  554.  *
  555.  */
  556. void 
  557. XMLWriterTag::WriteAttributes(IHXBuffer *buffer, INT32& loc)
  558. {
  559.     // If there are no attributes, return...
  560.     if (m_attributes.IsEmpty()) return;
  561.     // Write out the attributes to the buffer...
  562.     LISTPOSITION position = m_attributes.GetHeadPosition();
  563.     while (position != NULL)
  564.     {
  565. ((XMLWriterAttribute *)(m_attributes.GetNext(position)))->Write(buffer, loc);
  566. if (position != NULL) *(((char *)(buffer->GetBuffer())) + loc++) = 'n';
  567.     }
  568. }
  569. /*
  570.  * WriteTags
  571.  * ---------
  572.  * Write out the tags for this tag.
  573.  *
  574.  * input:
  575.  * IHXBuffer *buffer - Buffer to write to.
  576.  * INT32& loc - Location to where we start writing.
  577.  *
  578.  * output:
  579.  * void
  580.  *
  581.  */
  582. void 
  583. XMLWriterTag::WriteTags(IHXBuffer *buffer, INT32& loc)
  584. {
  585.     // If there are no attributes, return...
  586.     if (m_tags.IsEmpty()) return;
  587.     // Get the size and call write on each...
  588.     LISTPOSITION position = m_tags.GetHeadPosition();
  589.     while (position != NULL)
  590.     {
  591. ((XMLWriterTag *)(m_tags.GetNext(position)))->Write(buffer, loc);
  592.     }
  593. }
  594. /*
  595.  * CreateTag
  596.  * ---------
  597.  * Create a tag with the given name, adding it to the child list and return it.
  598.  *
  599.  * input:
  600.  * const char *name     - Name of the tag.
  601.  *
  602.  * output:
  603.  * XMLWriterTag *     - Pointer to the newly created tag.
  604.  *
  605.  */
  606. XMLWriterTag *
  607. XMLWriterTag::CreateTag(const char *name)
  608. {
  609.     XMLWriterTag *newTag = new XMLWriterTag;
  610.     HX_ASSERT(newTag != NULL);
  611.     newTag->SetName(name);
  612.     newTag->m_depth = m_depth + 1;
  613.     m_tags.AddTail(newTag);
  614.     return newTag;
  615. }
  616. /*
  617.  * AddAttribute
  618.  * ------------
  619.  * Add an attribute to the tag and then return a pointer to that attribute.
  620.  *
  621.  * input:
  622.  * const char *name     - Name of the attribute.
  623.  * const char *value     - Value of the attribute.
  624.  *
  625.  * output:
  626.  * XMLWriterAttribute *     - Attribute that was added.
  627.  *
  628.  */
  629. XMLWriterAttribute *
  630. XMLWriterTag::AddAttribute(const char *name, const char *value)
  631. {
  632.     // Create an attribute...
  633.     XMLWriterAttribute *newAttribute = new XMLWriterAttribute;
  634.     HX_ASSERT(newAttribute != NULL);
  635.     // Set the name and value...
  636.     newAttribute->SetName(name);
  637.     newAttribute->SetValue(value);
  638.     newAttribute->m_depth = m_depth;
  639.     // Add the attribute...
  640.     m_attributes.AddTail(newAttribute);
  641.     return newAttribute;
  642. }
  643. /* 
  644.  * CreateAttribute
  645.  * ---------------
  646.  * Creates an attribute, adding it to the list of attributes, then returning the pointer to it.
  647.  *
  648.  * input:
  649.  * void
  650.  *
  651.  * output:
  652.  * XMLWriterAttribute *     - The pointer to the newly created attribute.
  653.  *
  654.  */
  655. XMLWriterAttribute *
  656. XMLWriterTag::CreateAttribute(void)
  657. {
  658.     // Create the attribute...
  659.     XMLWriterAttribute *newAttribute = new XMLWriterAttribute;
  660.     HX_ASSERT(newAttribute != NULL);
  661.     // Add the attribute to the list of attributes...
  662.     m_attributes.AddTail(newAttribute);
  663.     newAttribute->m_depth = m_depth;
  664.     return newAttribute;
  665. }
  666. /*
  667.  * SetComment
  668.  * ----------
  669.  * Set the comment and set the type as a comment.
  670.  *
  671.  * input:
  672.  * const char *comment - Comment to set.
  673.  *
  674.  * output:
  675.  * void
  676.  *
  677.  */
  678. void
  679. XMLWriterTag::SetComment(const char *comment)
  680. {
  681.     if (m_comment != NULL) delete [] m_comment;
  682.     m_comment = NULL;
  683.     if (comment != NULL)
  684.     {
  685. m_comment = new char[strlen(comment) + 1];
  686. strcpy(m_comment, comment); /* Flawfinder: ignore */
  687.     }
  688.     m_type = XMLCommentTag;
  689. }
  690. /* 
  691.  * SetName
  692.  * -------
  693.  * Set the name of this tag.
  694.  *
  695.  * input:
  696.  * const char *name - Name to set for this tag.
  697.  *
  698.  * output:
  699.  * void
  700.  *
  701.  */
  702. void
  703. XMLWriterTag::SetName(const char *name)
  704. {
  705.     if (m_name != NULL) delete [] m_name;
  706.     m_name = NULL;
  707.     if (name != NULL)
  708.     {
  709. m_name = new char[strlen(name) + 1];
  710. strcpy(m_name, name); /* Flawfinder: ignore */
  711.     }
  712. }