IBM Doors DXL: Analyze Module or String for HTML or XML Tags

Problem

A module or a string should be analyzed for HTML or XML Tags.

Approach

The tags withing a module attribute shall be counted and the output should be send to the DXL Interaction window.

By running through the whole string, opening and closing tags can be found.
Here the steps are the following:
1.) Create a Skip-List that counts all tags
2.) Create a loop over the current module
3.) Within the loop call the Method checkForTags and

Solution

pragma runLim, 0;

/********************************************************************
 * Author: 	Bjoern Karpenstein
 * Date: 	2014-09-16
 * Parameter: 
 * Skipliste tagCount (vorher mit Skip tagCount=create; erzeugen)
 * string textToCheck (der auf XML Tags zu prüfende Text)
 * string tag (nach welchen Tag sehen? Falls leer alle Tags sammeln
 ********************************************************************/
void checkForTags(Skip tagCount, string textToCheck, string tag)
{
   // init loop variables
 bool currentIsInTag = false;
 bool tagEnded = false;
 string tagBetweenBrackets = "";
 int x;
   	
 for (x=0; x<length(textToCheck)-1;x++)
 {
  if(textToCheck&#91;x:x&#93; "" == "<" "")
  {
    currentIsInTag = true;
    tagBetweenBrackets = "";
   }
           
   if(textToCheck&#91;x:x&#93; "" == ">" "" && currentIsInTag)
   {
     currentIsInTag = false;

     // Wenn der Tag schon vorhanden ... eins hochzählen
     int vorhanden = 0;

     if(find(tagCount, tagBetweenBrackets ">", vorhanden))
     {
       // nehmen und eins hochzählen
       if(matches(lower(tag), lower(tagBetweenBrackets)))
       {
	// Lösche den aktuellen Wert in Skip-Liste		   		   
	delete (tagCount, tagBetweenBrackets ">");
		   		   
	// Füge den aktuellen Wert inkrementiert in Stückliste ein
	put(tagCount, tagBetweenBrackets ">", vorhanden+1);
       }
    }
    else
    {
      // Wenn nicht vorhanden initial mit 1 einfügen
      if(matches(lower(tag), lower(tagBetweenBrackets)))
      {
         put(tagCount, tagBetweenBrackets ">", 1);
      }
     }  
    }
      
    if(currentIsInTag)
    {
       tagBetweenBrackets = tagBetweenBrackets textToCheck[x:x] "";
    }
  }   
}

void main()
{
  Object o;
  Module m = current;
  Filter off;
  Skip tagCount = create;
	
  for o in m do
  {		
    string engText = o."Text_english" "";
    string gerText = o."Text_german" "";
		
    checkForTags(tagCount, engText, "");
    checkForTags(tagCount, gerText, "");
  }
	
  for myIterator in tagCount do 
  {
    string keyValue = (string key(tagCount));
   
    int dasVorhandene=0;
	   
    if(find(tagCount, keyValue, dasVorhandene))
    {
      print keyValue " \t" dasVorhandene "\n";
    }
  }
	
  delete(tagCount);
}

main();

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.