本文整理汇总了C#中PrintTicket.GetXmlStream方法的典型用法代码示例。如果您正苦于以下问题:C# PrintTicket.GetXmlStream方法的具体用法?C# PrintTicket.GetXmlStream怎么用?C# PrintTicket.GetXmlStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PrintTicket
的用法示例。
在下文中一共展示了PrintTicket.GetXmlStream方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ModifyPrintTicket
public static PrintTicket ModifyPrintTicket(PrintTicket ticket, string featureName, string newValue)
{
if (ticket == null)
{
throw new ArgumentNullException("ticket");
}
var xmlDoc = new XmlDocument();
xmlDoc.Load(ticket.GetXmlStream());
var manager = new XmlNamespaceManager(xmlDoc.NameTable);
manager.AddNamespace(xmlDoc.DocumentElement.Prefix, xmlDoc.DocumentElement.NamespaceURI);
var xpath = string.Format("//psf:Feature[contains(@name, 'InputBin')]/psf:Option", featureName);
var node = xmlDoc.SelectSingleNode(xpath, manager);
if (node != null)
{
node.Attributes["name"].Value = newValue;
}
var printTicketStream = new MemoryStream();
xmlDoc.Save(printTicketStream);
printTicketStream.Position = 0;
var modifiedPrintTicket = new PrintTicket(printTicketStream);
return modifiedPrintTicket;
}
示例2: ModifyPrintTicket
public static PrintTicket ModifyPrintTicket(PrintTicket ticket, string featureName, string newValue)
{
if (ticket == null)
{
throw new ArgumentNullException("ticket");
}
// read Xml of the PrintTicket
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(ticket.GetXmlStream());
// create NamespaceManager and add PrintSchemaFrameWork-Namespace hinzufugen (should be on DocumentElement of the PrintTicket)
// Prefix: psf NameSpace: xmlDoc.DocumentElement.NamespaceURI = "http://schemas.microsoft.com/windows/2003/08/printing/printschemaframework"
XmlNamespaceManager manager = new XmlNamespaceManager(xmlDoc.NameTable);
manager.AddNamespace(xmlDoc.DocumentElement.Prefix, xmlDoc.DocumentElement.NamespaceURI);
// search node with desired feature we're looking for and set newValue for it
string xpath = string.Format("//psf:Feature[@name='{0}']/psfSurpriseption", featureName);
XmlNode node = xmlDoc.SelectSingleNode(xpath, manager);
if (node != null)
{
node.Attributes["name"].Value = newValue;
}
// create a new PrintTicket out of the XML
MemoryStream printTicketStream = new MemoryStream();
xmlDoc.Save(printTicketStream);
printTicketStream.Position = 0;
PrintTicket modifiedPrintTicket = new PrintTicket(printTicketStream);
// for testing purpose save the printticket to file
//FileStream stream = new FileStream("modPrintticket.xml", FileMode.CreateNew, FileAccess.ReadWrite);
//modifiedPrintTicket.GetXmlStream().WriteTo(stream);
return modifiedPrintTicket;
}