我正在尝试用c#.net
编写一个程序修改具有
的热敏标签打印机.prn文件 <xpml></page></xpml><xpml><page quantity='25' pitch='35.0 mm'></xpml>N
如何在运行时更改数量属性,使用c#.net从25到用户输入说50或100或5?所以它将是
<xpml></page></xpml><xpml><page quantity='50' pitch='35.0 mm'></xpml>N
或
<xpml></page></xpml><xpml><page quantity='100' pitch='35.0 mm'></xpml>Nenter code here
或
<xpml></page></xpml><xpml><page quantity='5' pitch='35.0 mm'></xpml>N
完成.prn文件
<xpml><page quantity='0' pitch='35.0 mm'></xpml>I8,A
q843
O
JF
ZT
Q280,25
<xpml></page></xpml><xpml><page quantity='2' pitch='35.0 mm'></xpml>N
b569,70,Q,m2,s5,eL,"12345678"
A686,52,2,4,1,1,N,"12345678"
A823,267,2,4,1,1,N,"Hardware Kit (Egypt)"
b149,70,Q,m2,s5,eL,"12345678"
A266,52,2,4,1,1,N,"12345678"
A403,267,2,4,1,1,N,"Hardware Kit (Egypt)"
P2
<xpml></page></xpml><xpml><end/></xpml>
答案 0 :(得分:0)
请尝试以下操作:
string xml = "<root><xpml><page/></xpml><xpml><page quantity='25' pitch='35.0 mm'/></xpml></root>";
XElement element = XElement.Parse(xml);
XElement page = element.Descendants("page").Where(x => x.Attribute("quantity") != null).FirstOrDefault();
page.SetAttributeValue("quantity", 50);
答案 1 :(得分:0)
跟随字符串操作/正则表达式可以解决我的问题 但现在我发现没有必要只修改这一行 P命令实际上控制了所需打印的数量
string pattern = @"(quantity=')([0-9]+)";
Regex regex = new Regex(pattern);
string changedvlu = regex.Replace(rowsInTextFile[6], "quantity='" +
dgvrLabels.Cells["labels2print"].Value.ToString());
string cmdlableqty = rowsInTextFile[6].ToString();
int findpicthpos = cmdlableqty.IndexOf("pitch");
if (findpicthpos>0)
{
rowsInTextFile[6] = "<xpml></page></xpml><xpml><page quantity ="
+ "\'" + dgvrLabels.Cells["labels2print"].Value + "\' ";
rowsInTextFile[6] += cmdlableqty.Substring(findpicthpos);
}
else
MessageBox.Show("Problem in setting label qty:call developer");