Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

object collection with multiple definitions, no Length 1

Status
Not open for further replies.

copeZero

Programmer
Aug 31, 2007
46
0
0
CA
Hi i have an array that contains values, but the array does not have a definition Length property, I does have a definitions for: label,slice

My goal is to iterate thru the loop for response.write some xml, like so:
Code:
Response.Write("<Risk><Lables>");
Response.Write("<Risks name='"+ccp[0].Label+"' change='"+ccp[0].Slice+"'></Risks>");
Response.Write("</Lables>");
Response.Write("<Lables>");
Response.Write("<Risks name='"+ccp[1].Label+"' change='"+ccp[1].Slice+"'></Risks>");

Response.Write("</Lables>");
Response.Write("<Lables>");
Response.Write("<Risks name='"+ccp[2].Label+"' change='"+ccp[2].Slice+"'></Risks>");
Response.Write("</Lables>");
Response.Write("</Risk>");

So how does one create a loop to handle this, my attempt did not work, it was something like this:

for (int i = 1; i <= listpc.Label.Length; i++)
{
for (int i = 1; i <= listpc.Slice.Length; i++)
{
Response.Write("xml");
}
}

 
Code:
MyObject[] objects = new MyObject[] { 
   new MyObject(), 
   new MyObject(), 
   new MyObject() 
};
foreach(MyObject o in objects)
{
   o.Label;
   o.Slice;
}

I would recommend looking into xmlreader/xmlwrite and xmldocument objects to assist with generating an xml document. these objects will create the formatting/syntax for xml, you just provide the nodes/attributes/data.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top