/////////////////////////////////////////////////////////////////////////////// // Diego Molla // diego@ics.mq.edu.au 2006- /////////////////////////////////////////////////////////////////////////////// // Filename: conexor.cpp /////////////////////////////////////////////////////////////////////////////// // This file is part of the AnswerFinder package. /////////////////////////////////////////////////////////////////////////////// // This file contains the implementation of the interface to conexor /////////////////////////////////////////////////////////////////////////////// // $Log$ /////////////////////////////////////////////////////////////////////////////// #include #include #include #include #include using namespace std; using namespace boost; /////////////////////////////////////////////////////////////////////////////// // Function: xmlTextAttr // Extract the text that corresponds with the given XML tag and all its // attributes // Preconditions: // - There are no nested elements of the given type // - There is only one attribute /////////////////////////////////////////////////////////////////////////////// pair > xmlTextAttr(string element, string inText) { regex markup("<\\s*"+element+"(\\s*|\\s+[^>]*)>(.*?)"); regex attrMarkup("\\b(.*?)=\"(.*?)\""); match_results what; pair > result; if (regex_search(inText,what,markup)) { cout << "Found element " << what[2].str() << endl; result.first = what[2].str(); cout << "Searching " << what[1].str() << endl; if (regex_search(what[1].str(),what,attrMarkup)) { cout << " Found attribute " << what[1].str() << " with value " << what[2].str() << endl; result.second[what[1].str()] = what[2].str(); } // if } // if return result; } // xmltext int main() { string text, tag; cout << "Write a fragment of XML: " << endl; getline(cin,text); while (text != "end") { cout << "Write the XML tag to search: " << endl; getline(cin,tag); xmlTextAttr(tag,text); cout << "Write a fragment of XML: " << endl; getline(cin,text); } // while } // main // end of file: conexor.cpp