Storing XML information in an Array

Hey Everyone,

Right now I am working on storing around 9,000 zip codes in an array from an xml file. I’m not sure if What is going on because they keep returning zero as the values for the codes.

It would be cool if someone could take a peek and point me in the right direction.

The XML structure is like this:

  
<Grants>  
	<Grant AppNumber="FS-23234-01">  
		<ApplicantType>O</ApplicantType>  
		<Firstname>Carolyn</Firstname>  
		<Middlename/>  
		<Lastname>Abbate</Lastname>  
		<NameSuffix/>  
		<Institution>Princeton University</Institution>  
		<InstCity>Princeton</InstCity>  
		<InstState>NJ</InstState>  
		<InstPostalCode>08544</InstPostalCode>  
		<InstCountry>USA</InstCountry>  
		<CouncilDate>2001-07-01T00:00:00</CouncilDate>  
		<YearAwarded>2001</YearAwarded>  
		<ProjectTitle>Opera: Interpretation, Reading, Staging</ProjectTitle>  
		<Category>Music History and Criticism</Category>  
		<Program>Seminars for College Teachers</Program>  
		<Division>Education Programs</Division>  
		<ApprovedOutright>135422.0000</ApprovedOutright>  
		<ApprovedMatching>0.0000</ApprovedMatching>  
		<AwardOutright>135422.0000</AwardOutright>  
		<AwardMatching>0.0000</AwardMatching>  
		<OriginalAmount>135422.0000</OriginalAmount>  
		<BeginGrant>2001-10-01T00:00:00</BeginGrant>  
		<EndGrant>2002-09-30T00:00:00</EndGrant>  
		<ProjectDesc/>  
		<ToSupport/>  
		<SuppCount>0</SuppCount>  
	</Grant>  
	<Grant AppNumber="FS-50001-03">  
		<ApplicantType>O</ApplicantType>  
		<Firstname>Carolyn</Firstname>  
		<Middlename/>  
		<Lastname>Abbate</Lastname>  
		<NameSuffix/>  
		<Institution>Princeton University</Institution>  
		<InstCity>Princeton</InstCity>  
		<InstState>NJ</InstState>  
		<InstPostalCode>08544</InstPostalCode>  
		<InstCountry>USA</InstCountry>  
		<CouncilDate>2003-07-01T00:00:00</CouncilDate>  
		<YearAwarded>2003</YearAwarded>  
		<ProjectTitle>Opera: Interpretation Between Disciplines</ProjectTitle>  
		<Category>Music History and Criticism</Category>  
		<Program>Seminars for College Teachers</Program>  
		<Division>Education Programs</Division>  
		<ApprovedOutright>141969.0000</ApprovedOutright>  
		<ApprovedMatching>0.0000</ApprovedMatching>  
		<AwardOutright>141969.0000</AwardOutright>  
		<AwardMatching>0.0000</AwardMatching>  
		<OriginalAmount>141969.0000</OriginalAmount>  
		<BeginGrant>2003-10-01T00:00:00</BeginGrant>  
		<EndGrant>2004-09-30T00:00:00</EndGrant>  
		<ProjectDesc/>  
		<ToSupport>A six-week summer seminar for 15college teachers on the interpretation of opera that uses a broad range of academic disciplines.</ToSupport>  
		<SuppCount>0</SuppCount>  
	</Grant>  
</Grants>  

Here is what I have in the setup:

  
    grants.loadFile("NEH_Grants2000s.xml");  
      
    loaded = true;  
      
    if( !grants.loadFile("NEH_Grants2000s.xml")){  
        grants.saveFile("NEH_Grants2000s.xml");  
        loaded = false;  
    }  
  
      
      
      
    grants.pushTag("Grants");   
    int numTags = grants.getNumTags("Grant");    
    grants.popTag();    
       
      
    grants.pushTag("Grants");    
    for( int i = 0; i < numTags; i++ )    
    {    
        grants.pushTag("Grant", i),    
          
   
        zipCode = grants.getValue("InstPostalCode", 0,i);    
    
          
        grants.popTag();    
          
        zipCodes.push_back(zipCode);    
    }    
    grants.popTag();    
      
      
    string zip = "Zip Code is ";  
      
    zip += ofToString(zipCodes[1]);  
      
    ofSetWindowTitle(zip);  

In the header I have this for the array:

  
vector <int> zipCodes;  

Thanks everyone!

I think you want:

  
zipCode = grants.getValue("InstPostalCode", 0,0);  

since you’re looking for the 0th postcode that each grant contains, not, for instance, the 4000th postcode that a single grant contains, correct?

Hey Josh,

that was exactly it!

thank you so much!

No problem, I think we just need some better documentation on how the XML parsing works.