public static TransportMessage DeserializeFromXml(OracleAQMessage message) { if (message == null) { return(null); } XmlDocument bodyDoc; using (OracleXmlType type = (OracleXmlType)message.Payload) { bodyDoc = type.GetXmlDocument(); } var bodySection = bodyDoc.DocumentElement.SelectSingleNode("Body").FirstChild as XmlCDataSection; var headerDictionary = new SerializableDictionary <string, string>(); var headerSection = bodyDoc.DocumentElement.SelectSingleNode("Headers"); if (headerSection != null) { headerDictionary.SetXml(headerSection.InnerXml); } Address replyToAddress = null; var replyToAddressSection = bodyDoc.DocumentElement.SelectSingleNode("ReplyToAddress"); if (replyToAddressSection != null && !string.IsNullOrWhiteSpace(replyToAddressSection.InnerText)) { replyToAddress = Address.Parse(replyToAddressSection.InnerText.Trim()); } MessageIntentEnum messageIntent = default(MessageIntentEnum); var messageIntentSection = bodyDoc.DocumentElement.SelectSingleNode("MessageIntent"); if (messageIntentSection != null) { messageIntent = (MessageIntentEnum)Enum.Parse(typeof(MessageIntentEnum), messageIntentSection.InnerText); } var transportMessage = new TransportMessage(new Guid(message.MessageId).ToString(), headerDictionary) { Body = bodySection != null?Encoding.UTF8.GetBytes(bodySection.Data) : new byte[0], ReplyToAddress = replyToAddress, MessageIntent = messageIntent, }; return(transportMessage); }
/// <summary> /// Demonstrate the properties and methods on OracleXmlType /// </summary> /// <param name="connectStr"></param> /// <returns></returns> public static void PropDemo(OracleXmlType xml) { try { // Value property Console.WriteLine("Value property: "); Console.WriteLine(xml.Value); Console.WriteLine(""); // Get an Oracle XML Stream OracleXmlStream strm = xml.GetStream(); Console.WriteLine("GetStream() method: "); Console.WriteLine(strm.Value); Console.WriteLine(""); strm.Dispose(); // Get a .NET XmlReader XmlReader xmlRdr = xml.GetXmlReader(); XmlDocument xmlDocFromRdr = new XmlDocument(); xmlDocFromRdr.Load(xmlRdr); Console.WriteLine("GetXmlReader() method: "); Console.WriteLine(xmlDocFromRdr.OuterXml); Console.WriteLine(""); xmlDocFromRdr = null; xmlRdr = null; // Get a .NET XmlDocument XmlDocument xmlDoc = xml.GetXmlDocument(); Console.WriteLine("GetXmlDocument() method: "); Console.WriteLine(xmlDoc.OuterXml); Console.WriteLine(""); xmlDoc = null; // IsExists method string xpathexpr = "/PO/SHIPADDR"; string nsmap = null; if (xml.IsExists(xpathexpr, nsmap)) { // Extract method OracleXmlType xmle = xml.Extract(xpathexpr, nsmap); // IsEmpty property if (xmle.IsEmpty) { Console.WriteLine("Extract() method returns empty xml data"); } else { Console.WriteLine("Extracted XML data: "); Console.WriteLine(xmle.Value); } Console.WriteLine(""); xmle.Dispose(); } // Use XSLT on the OracleXmlType StringBuilder blr = new StringBuilder(); blr.Append("<?xml version=\"1.0\"?> "); blr.Append("<xsl:stylesheet version=\"1.0\" "); blr.Append("xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"> "); blr.Append(" <xsl:template match=\"/\"> "); blr.Append(" <NEWPO> "); blr.Append(" <xsl:apply-templates select=\"PO\"/> "); blr.Append(" </NEWPO> "); blr.Append(" </xsl:template> "); blr.Append(" <xsl:template match=\"PO\"> "); blr.Append(" <xsl:apply-templates select=\"CUSTNAME\"/> "); blr.Append(" </xsl:template> "); blr.Append(" <xsl:template match=\"CUSTNAME\"> "); blr.Append(" <CNAME> <xsl:value-of select=\".\"/> </CNAME> "); blr.Append(" </xsl:template> </xsl:stylesheet> "); string pmap = null; OracleXmlType xmlt = xml.Transform(blr.ToString(), pmap); //Print the transformed xml data Console.WriteLine("XML Data after Transform(): "); Console.WriteLine(xmlt.Value); // Update the CNAME in the transformed xml data xpathexpr = "/NEWPO/CNAME/text()"; xmlt.Update(xpathexpr, nsmap, "NewName"); // See the updated xml data Console.WriteLine("XML Data after Update(): "); Console.WriteLine(xmlt.Value); Console.WriteLine(""); xmlt.Dispose(); } catch (Exception e) { Console.WriteLine("Error: {0}", e.Message); } }