deps/kb_meme/meme-5.0.1/src/xml-util.c
/***********************************************************************
 * Read and set the alphabet from a parsed XML document.
 ***********************************************************************/
Read and set the alphabet from a parsed XML document.
Read and set the alphabet from a parsed XML document .
ALPH_T* read_alphabet_from_xml(xmlXPathContextPtr xpath_ctxt) {
  ALPH_T* alph;
  xmlXPathObjectPtr xpathObj = NULL;
  xmlChar* property = NULL;
  xpathObj = xpath_query(xpath_ctxt, "//*/alphabet");
  property = read_xml_node_property(
    xpathObj->nodesetval->nodeTab[0], 
    "length"
  );
  int alph_size = atoi((char *) property);
  xmlFree(property);
  xmlXPathFreeObject(xpathObj);
  xpathObj = xpath_query(xpath_ctxt, "//*/alphabet/letter");
  assert(alph_size == xpathObj->nodesetval->nodeNr);
  char* buffer = mm_calloc(sizeof(char), alph_size + 1);
  int i = 0;
  xmlNodePtr currLetterNode = NULL;
  for (i = 0; i < alph_size; i++) {
    currLetterNode = xpathObj->nodesetval->nodeTab[i];
    if (currLetterNode == NULL) {
      die("Error: missing letter %d in alphabet.\n", i);
    }
    property = read_xml_node_property(currLetterNode, "symbol");
    buffer[i] = *property;
    xmlFree(property);
  }
  buffer[i] = 0;
  alph = alph_type(buffer, alph_size+1);
  myfree(buffer);
  xmlXPathFreeObject(xpathObj);
  return alph;
}
ALPH_T * read_alphabet_from_xml ( xmlXPathContextPtr xpath_ctxt ) { ALPH_T * alph ; xmlXPathObjectPtr xpathObj = NULL ; xmlChar * property = NULL ; xpathObj = xpath_query ( xpath_ctxt , " " ) ; property = read_xml_node_property ( xpathObj -> nodesetval -> nodeTab [ 0 ] , " " ) ; int alph_size = atoi ( ( char * ) property ) ; xmlFree ( property ) ; xmlXPathFreeObject ( xpathObj ) ; xpathObj = xpath_query ( xpath_ctxt , " " ) ; assert ( alph_size == xpathObj -> nodesetval -> nodeNr ) ; char * buffer = mm_calloc ( sizeof ( char ) , alph_size + 1 ) ; int i = 0 ; xmlNodePtr currLetterNode = NULL ; for ( i = 0 ; i < alph_size ; i ++ ) { currLetterNode = xpathObj -> nodesetval -> nodeTab [ i ] ; if ( currLetterNode == NULL ) { die ( " \n " , i ) ; } property = read_xml_node_property ( currLetterNode , " " ) ; buffer [ i ] = * property ; xmlFree ( property ) ; } buffer [ i ] = 0 ; alph = alph_type ( buffer , alph_size + 1 ) ; myfree ( buffer ) ; xmlXPathFreeObject ( xpathObj ) ; return alph ; }
Read and set the alphabet from a parsed XML document.
Read and set the alphabet from a parsed XML document .
// The stated size of the alphabet had better match the // number of letter elements in the alphabet. // Get the letter symbol attribute