I currently have a C# app that makes a socket connection to a system, sends an XML stream, then the target system responds back with an XML stream which I have read into a string. I currently have it set to display this into a multi-line textbox and i can see the entire XML file. I've been able to read in select nodes from the string and set textlabels to display each portion.
I'd like to change it so instead of a label (which is a pain to create and not automatic) it reads the XML Element that starts with "OutqEntry" into a dataset or datagrid (not sure which to use). But i'd like to have say 8 rows wide, and however many columns high from the XML.
This is what the XML stream looks like: (i've trimmed it down a bit to fit in the window)
And now the messy part. This is how I'm reading the nodes in and setting the labels:Code:<?xml version="1.0" encoding="utf-8" ?> <!-- FileName: iSeries_SpecificOutq_Reply.xml --> <DRV> <CommObject Type="Reply" Data="_SpecificOutq"> <SpecificOutq OutqName="SFOUTQ" OutqLib="DRVSFLEX"> <OutqEntry PrintFile="QSYSPRT" SplFileNbr="1" Formtype="TESTASCII" UserData="" NbrPages="1" Copies="1"/> <OutqEntry PrintFile="PRT0001" SplFileNbr="2" Formtype="CONBALANCE" UserData="" NbrPages="2" Copies="1"/> </SpecificOutq> </CommObject> </DRV>
Attachment 9664Code:XmlDocument doc = new XmlDocument(); doc.Load(new StringReader(s)); XmlNodeList splfname = doc.SelectNodes("/DRV/CommObject/SpecificOutq/OutqEntry/@PrintFile"); XmlNodeList frmtypename = doc.SelectNodes("/DRV/CommObject/SpecificOutq/OutqEntry/@Formtype"); XmlNodeList userdataname = doc.SelectNodes("/DRV/CommObject/SpecificOutq/OutqEntry/@UserData"); XmlNodeList cpysname = doc.SelectNodes("/DRV/CommObject/SpecificOutq/OutqEntry/@Copies"); XmlNodeList pagesname = doc.SelectNodes("/DRV/CommObject/SpecificOutq/OutqEntry/@NbrPages"); XmlNodeList outqname = doc.SelectNodes("/DRV/CommObject/SpecificOutq/@OutqName"); XmlNodeList libraryname = doc.SelectNodes("/DRV/CommObject/SpecificOutq/@OutqLib"); try { splf.Text = splfname[0].InnerText; outq.Text = outqname[0].InnerText; library.Text = libraryname[0].InnerText; userdata.Text = userdataname[0].InnerText; pages.Text = pagesname[0].InnerText; cpys.Text = cpysname[0].InnerText; frmtype.Text = frmtypename[0].InnerText; }
I end up with this, which looks good, but requires me to make 7 labels for each line, and if i wanted to display 50 things, thats a bunch of labels to create plus I can't use the data once its displayed. So something like a dataset or grid view would be nice but I just don't know how to take what I have and make the next step. I also have the program writing the stream to an XML file as well (thats the first code block above) so i could just re-read it in instead of trying to deal with the stream if thats easier.
Any ideas, direction or help would be greatly appreciated.