//Gets the value of an XML declaration node
char* getDeclerationValue()
{
  //XML decleartion is the string between the question makr signs of an decleration node
  clearWhiteSpace();
  int length = 0;
  int insideQuotation = FALSE;

  //Loop until we finish reading outside of the quotes or we reach the question mark
  while((xmlArray[chrPtr] != ' ' && xmlArray[chrPtr] != '?') || insideQuotation == TRUE)
  {
    length++;
    chrPtr++;
    
    //Everything inside of quotation marks is part of the decleration
    if(xmlArray[chrPtr] == '"')
    {
      if(insideQuotation == TRUE)
      {
        insideQuotation = FALSE;
      }
      else
      {
        insideQuotation  = TRUE;
      }
    }
  }

  //read the decleration
  char *declerationvalue = readFromXML(length);

  //return the decleration that was read
  return declerationvalue;
}
//Gets the key/value pairs of the atributes until it 
//gets to the end of the encapsulating tag.
void getAttributes(XMLNode *xmlNode)
{
  //Clear the white space
  clearWhiteSpace();

  //Loop until we get to the end of the current tag we are in
  while(xmlArray[chrPtr] != '>')
  {
    //The attributes end with an equals sign and can not contain spaces
    int textLength = 0;
    while(xmlArray[chrPtr] != ' ' && xmlArray[chrPtr] != '=')
    {
      chrPtr++;
      textLength++;
    }

    //read the attribute
    char* attribute = readFromXML(textLength);

    //The value starts after a quotation mark after the equals sign
    moveToChar('=');
    moveToChar('"');
    chrPtr++;

    //Loop until we get to the end of the quotation mark
    textLength =0;
    while(xmlArray[chrPtr] != '"')
    {
      chrPtr++;
      textLength++;
    }

    //read the value
    char * value = readFromXML(textLength);

    //Add the attribute/value pair to the attributes of the node
    xmlAddAttribute(xmlNode, attribute, value); 

    //clean up the buffers
    free(attribute);
    free(value);
    
    //Continue moving on
    chrPtr++;
    clearWhiteSpace();
  }
}
Exemplo n.º 3
0
void clearLL(node * head) {
    node * temp = head;

    do {
        temp->data = clearWhiteSpace(temp->data);
        temp = temp->next;
    } while (temp != head);

}
//Returns a string of all of the characters until the next space or '>' character
char* getName()
{
    //First move through all the white space
  clearWhiteSpace();

  //Loop until the next space or a closing tag
  int nameLength = 0;
  while(xmlArray[chrPtr] != '>' && xmlArray[chrPtr] != ' ')
  {
    nameLength++;
    chrPtr++;
  }

  //Read the characters from the array
  char* returnValue = readFromXML(nameLength);  

  //Return the new string
  return returnValue;
}
//Passes through the xml array and adds children to currently passed in node
void parseNode(XMLNode *node)
{
  //Save off the previous chr ptr in case white spaces should be part of the text value
  int prevChrPtr = chrPtr;

  clearWhiteSpace();

  //Loop until the end of the file
  while(xmlArray[chrPtr] != '\0'){ 
    //Check if war are at the beginning of a tag
    if(xmlArray[chrPtr] == '<' && xmlArray[chrPtr + 1] != '/'){
      //Check if we are reading an xml decleration node
      chrPtr++;
      if(xmlArray[chrPtr] == '?'){
        //This muse be an xml decleration monde.  Move passed the 
        //question mark just read in and get the decleration part.
        chrPtr++;
        xmlAddChildNode(node, readXMLDeclerationNode());

        //Move to the end tab
        moveToChar('>');

        //Move past the end tab and fall off
        chrPtr++;
        clearWhiteSpace();
      }
      else{
        //This must be a regular element node.  Read the element node
        XMLNode* childNode = xmlAddChildNode(node, readXMLElementNode());

        //Get the attributes for the element
        getAttributes(childNode);
        //Move to the closing tab
        moveToChar('>');
        chrPtr++;

        //Recursivley call up and see if the current node has any children
        parseNode(childNode);
        
        //Now that we have all of its children, move past our closing tag.
        clearWhiteSpace();
                
        if(xmlArray[chrPtr] == '<'){
          moveToChar('>');

          if(xmlArray[chrPtr] == '>'){
            chrPtr++;
          }
        }
        
        //Now are are passed our closing tag.  See if we were are not at our
        //parents closing tag and, if so, fall off.
        clearWhiteSpace();

        if(xmlArray[chrPtr] == '<' && xmlArray[chrPtr + 1] == '/')
          break;
        

        //We were not the last sub element of our parent.  Loop again and add the next one as a child.
      }
    }
    else{
      //move back to the beginning of this section
      chrPtr = prevChrPtr;
      //printf("About to make text node, next 3 char are '%c%c%c'", xmlArray[chrPtr], xmlArray[chrPtr + 1], xmlArray[chrPtr + 2]);
      //We are not at the beginning of a tag, so we must be in the text
      //the node.  Read its text and fall off.
      xmlAddChildNode(node, readXMLTextNode());
      break;
    }
  }
}