日期:2008-07-12  浏览次数:20521 次

//接上回
/// <summary>
  /// Create an Element under the given parent based on the name and value pair.

  /// </summary>
  public XMLElement CreateNodeElement(XMLNode parentNode, string sElementName, string sElementValue)
  {
   XMLElement newElem = null;
      
   try
   {
    newElem = m_XMLDocument.CreateElement(sElementName);
    newElem.InnerXML = Encode(sElementValue);
    XMLDocument ownerDoc = parentNode.OwnerDocument;
              
    if (ownerDoc != null)
    {       
     parentNode.AppendChild(newElem);
    }
    else
    {
     XMLElement root = m_XMLDocument.DocumentElement;
     root.AppendChild(newElem);
    }  
           
   }
   catch (Exception e)
   {
    HandleException ( e );
   }
   
   return newElem;
  }
  /// <summary>
  /// Creates and adds a comment before the given node.  If root node, or null,
  /// the comment node is Appended to the tree.
  /// </summary>
  public XMLNode CreateComment(XMLNode insertAfterThisNode, string sVal)
  {
   if ( insertAfterThisNode == null )
    return null;
   
   XMLNode createdNode = null;
   try
   {
    XMLComment commentNode = m_XMLDocument.CreateComment(Encode(sVal));
    createdNode = insertAfterThisNode.AppendChild(commentNode);
   }
   catch ( Exception e )
   {
    HandleException ( e );
   }
    
   return createdNode;     
  }  

  public XMLNode CreateXMLDeclaration(string version, string encoding, string standalone)
  {
   XMLNode createdNode = null;
   try
   {
    XMLDeclaration dec = m_XMLDocument.CreateXMLDeclaration(version, encoding, standalone);
    createdNode = m_XMLDocument.PrependChild ( dec );
   }
   catch ( Exception e )
   {
    HandleException ( e );
   }
   
   return createdNode;
  }         

  /// <summary>
  /// Delete an XMLNode from the tree
  /// </summary>
  public bool DeleteNodeElement(XMLNode targetNode)
  {
   bool bResult = false;
   
   try
   {
    XMLNode XMLNode = RootNode.RemoveChild(targetNode);
    if (XMLNode != null)
&