void SaxHandler::OnStartElement(const char *name, const TList *attributes)
{
    cout << "<" << name;

    TXMLAttr *attr;

    TIter next(attributes);
    while ((attr = (TXMLAttr*) next())) {
        cout << " " << attr->GetName() << "=\"" << attr->GetValue() << "\"";
    }

    cout  << ">";
}
Exemplo n.º 2
0
 void ParsePersonList(TXMLNode *node) {
    for (; node; node = node->GetNextNode()) {
       if (node->GetNodeType() == TXMLNode::kXMLElementNode) { // Element Node
          if (strcmp(node->GetNodeName(), "Person") == 0) {
             Int_t id=0;
             if (node->HasAttributes()) {
                TList *attrList = node->GetAttributes();
                TXMLAttr *attr = 0;
                TIter next(attrList);
                while ((attr=(TXMLAttr*)next())) {
                   if (strcmp(attr->GetName(), "ID") == 0) {
                      id = atoi(attr->GetValue());
                      break;
                   }
                }
             }
             listOfPerson->Add(ParsePerson(node->GetChildren(), id));
          }
       }
       ParsePersonList(node->GetChildren());
    }
 }
void ParseContext(TXMLNode *node)
{
   for ( ; node; node = node->GetNextNode()) {
      if (node->GetNodeType() == TXMLNode::kXMLElementNode) { // Element Node
         cout << node->GetNodeName() << ": ";
         if (node->HasAttributes()) {
            TList* attrList = node->GetAttributes();
            TIter next(attrList);
            TXMLAttr *attr;
            while ((attr =(TXMLAttr*)next())) {
               cout << attr->GetName() << ":" << attr->GetValue();
            }
         }
     }
     if (node->GetNodeType() == TXMLNode::kXMLTextNode) { // Text node
        cout << node->GetContent();
     }
     if (node->GetNodeType() == TXMLNode::kXMLCommentNode) { //Comment node
        cout << "Comment: " << node->GetContent();
     }

     ParseContext(node->GetChildren());
   }
}
void TBDataParser::OnStartElement(const char *element, const TList *attributes)
{
	TXMLAttr *attr;
	TIter next(attributes);

	char *name = element;
	_currentElement = new TString(element);
	
	char *method = NULL;

	while ((attr = (TXMLAttr*) next())) {
		char *attrName = attr->GetName();
		char *attrValue = attr->GetValue();

		if(!strcmp(attrName, "name")) {
			name = attrValue; 
		}
		
		if(!strcmp(attrName, "method")) {
			method = attrValue;	
			_currentMethod = new TString(method);
		}
		
	}

	TFolder *currentFolder = _foldersStack->Last();

	if(!strcmp(element, "vector")) {
		TString *nameString = new TString(name);
		vector<float> *values = new vector<float>;
		_values = values;

		nameString->ReplaceAll(" ","_");

		TObjString *currentVector = new TObjString(nameString->Data());

		TObjArray *vectorsStack = _vectorsStack;
		vectorsStack->AddLast(currentVector);

		TString *joinedName = new TString(((TObjString *) vectorsStack->First())->GetString().Data());

		for(Int_t i = 1; i < vectorsStack->GetEntries(); i++) {
			joinedName->Append("_");
			joinedName->Append(((TObjString *) vectorsStack->At(i))->GetString().Data());
		}
		
		TObjString *joinedNameObj = new TObjString(joinedName->Data());
		TObjArray *joinedNameStack = _joinedNameStack;
		
		TNtuple *vector = new TNtuple(joinedName->Data(),joinedName->Data(),"values");
		_vector = vector;
		currentFolder->Add(vector);

		if(joinedNameStack->Contains(joinedName->Data()))
			cout << joinedName->Data() << "Error: " << "vector already exists. Be sure that in your XML file every vector has a unique path + name combination" << endl;
			
		joinedNameStack->Add(joinedNameObj);
			
			
		return;
	}

	_foldersStack->AddLast(currentFolder->AddFolder(name, name));
}