XMLWriter条件 [英] XMLWriter conditions

查看:52
本文介绍了XMLWriter条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于打印标签的表格.它是2列标签x 5行.这基于Infopath.加载Infopath表单后,它将创建Windows表单,并用数据填充datagrid.然后,用户可以选择需要打印的记录.但是,我需要将行计数为奇数的每条记录都放在左侧,而行计数为偶数的每条记录都放在右边.我在左侧和右侧之间有不同的XML字段.请参见下面的代码.

I have a form that will be used to print labels. It's 2 columns of labels x 5 rows. This is based on Infopath. When the Infopath form loads, it creates a Windows Form and fills a datagrid with data. The user can then select which records need to be printed. However, I need to put every record where the row count is odd onto the left side, and every record where the row count is even on the right. I have distinct XML fields between the left and right sides. See code below.

            foreach (DataRow dr in ds.Tables["Inspection"].Rows)

            {

                strPrint = dr["Print"].ToString();

                strPN = dr["PN"].ToString();

                strOC = dr["OC"].ToString();

                strNF = dr["NF"].ToString();

                strCEMB = dr["CEMB"].ToString();

                strQty = dr["QTY"].ToString();

                strDate = dr["NF_DATE"].ToString();



                int count = ds.Tables["Inspection"].Rows.Count;



                using (XmlWriter writer = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Section", NamespaceManager).AppendChild())

                {

                    while (i <= count)

                    {

                        if (i % 2 != 0)

                        {

                            writer.WriteStartElement("rptSection", myNameSpace);

                            writer.WriteElementString("lPN", myNameSpace, strPN);

                            writer.WriteElementString("lOC", myNameSpace, strOC);

                            writer.WriteElementString("lNF", myNameSpace, strNF);

                            writer.WriteElementString("lQty", myNameSpace, strQty);

                            writer.WriteElementString("lDate", myNameSpace, strDate);

                        }

                        else

                        {

                            writer.WriteElementString("rPN", myNameSpace, strPN);

                            writer.WriteElementString("rOC", myNameSpace, strOC);

                            writer.WriteElementString("rNF", myNameSpace, strNF);

                            writer.WriteElementString("rQty", myNameSpace, strQty);

                            writer.WriteElementString("rDate", myNameSpace, strDate);

                            writer.WriteEndElement();

                        }

                    }

                    writer.Close();

                }

}

i += 1;

}

推荐答案

只需看一眼,就好像您在一个if块中编写StartElement,在另一个if中编写EndElement一样.

希望这会有所帮助.
Just glancing at this, it looks like you are writing the StartElement in one if block and the EndElement in the else. Depending on your count, it would seem possible to have one without the other, causing the error.

Hope this helps.


这篇关于XMLWriter条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆