public class BREResultHelper
{
public bool DebugTrace(string value)
{
System.Diagnostics.Debug.WriteLine("<" + value + ">");
return true;
}
public void AddValidationError(TypedXmlDocument resultMessage, string rule, string message)
{
var node = GetNode(resultMessage.Document.OwnerDocument, "//ns0:BREResult/BrokenRules");
AddNode(node, "BrokenRule");
AddNode(node.LastChild, "Rule", rule);
AddNode(node.LastChild, "Message", message);
}
public void AddSetting(TypedXmlDocument resultMessage, string key, string value)
{
var node = GetNode(resultMessage.Document.OwnerDocument, "//ns0:BREResult/Settings");
AddNode(node, "Setting");
AddNode(node.LastChild, "Key", key);
AddNode(node.LastChild, "Value", value);
}
private void AddNode(XmlNode node, string elementName)
{
XmlElement newElement = node.OwnerDocument.CreateElement(elementName);
node.AppendChild(newElement);
}
private void AddNode(XmlNode node, string elementName, string value)
{
XmlElement newElement = node.OwnerDocument.CreateElement(elementName);
XmlText elementText = node.OwnerDocument.CreateTextNode(value);
node.AppendChild(newElement);
node.LastChild.AppendChild(elementText);
}
private XmlNode GetNode(XmlDocument doc, string xpath)
{
XmlNamespaceManager xmlnsManager = new XmlNamespaceManager(doc.NameTable);
xmlnsManager.AddNamespace("ns0", "http://xyz.BizTalk.ESB.Schemas.BREResult");
return doc.SelectSingleNode(xpath, xmlnsManager);
}
}
public void AddValidationError(TypedXmlDocument resultMessage, string rule, string message)
{
XNamespace ns = "http://xyz.BizTalk.ESB.Schemas.BREResult";
XDocument doc = XDocument.Parse(resultMessage.Document.InnerXml);
XElement root = doc.Element(ns + "BREResult").Element("BrokenRules");
root.Add(new XElement("BrokenRule",
new XElement("Rule", rule),
new XElement("Message", message)));
resultMessage.Document.InnerXml = doc.ToXmlDocument().InnerXml;
}
Saturday, January 8, 2011
SAMPLE Microsoft.RuleEngine.TypedXmlDocument
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment