/**
  * Replaces <CODE>ParentTag.getTag(OldTagName, OccurrenceNumber)</CODE> with this tag. If not
  * enough tags are found, then this tag is just added to ParentTag.
  *
  * @param ParentTag The parent tag to search from.
  * @param OldTagName The path to the tag to be replaced.
  * @param OccurrenceNumber The occurrence number of the path in OldTagName to be replaced.
  * @return The tag that has been replaced if one existed, else null.
  */
 public XMLTag replace(XMLTag _ParentTag, String OldTagName, int OccurrenceNumber) {
   XMLTag OldTag = _ParentTag.getTag(OldTagName, OccurrenceNumber);
   if (OldTag != null) {
     // OldTag.removeTagFromParent().addTag(this);
     _ParentTag.exchangeChild(OldTag, this);
   } else {
     _ParentTag.addTag(this);
   }
   return OldTag;
 }
 /**
  * Returns the first tag corresponding to TagPath.
  *
  * @param TagPath The path to the desired tag.
  * @return The first tag corresponding to TagPath if one exists, else null.
  */
 public XMLTag getTag(String TagPath) {
   if (TagPath.startsWith("/")) {
     return getRootTag().getTag(TagPath.substring(1));
   }
   if (TagPath.trim().equals("")) {
     return this;
   }
   String[] TempStrings = TagPath.split("/", 2);
   if (TempStrings.length == 1) {
     if (TagPath.equals(".") || (this instanceof XMLFile && TagPath.equals(TagName))) {
       return this;
     }
     if (TagPath.equals("..")) {
       return ParentTag;
     }
     XMLTag[] Result = new XMLTag[0];
     Result = (XMLTag[]) ChildTags.toArray(new XMLTag[0]);
     int CurrentIndex = 0;
     while (CurrentIndex < Result.length && !Result[CurrentIndex].getName().equals(TagPath)) {
       CurrentIndex++;
     }
     if (CurrentIndex < Result.length) {
       return Result[CurrentIndex];
     } else {
       return null;
     }
   } else {
     XMLTag Result;
     if (TempStrings[0].equals("*")) {
       XMLTag[] TempTags = (XMLTag[]) ChildTags.toArray(new XMLTag[0]);
       for (int i = 0; i < TempTags.length; i++) {
         Result = TempTags[i].getTag(TempStrings[1]);
         if (Result != null) {
           return Result;
         }
       }
       return null;
     } else {
       Result = getTag(TempStrings[0]);
       if (Result != null) {
         return Result.getTag(TempStrings[1]);
       } else {
         return null;
       }
     }
   }
 }