This project is read-only.
Here is some sample code for unboxing content objects automatically.
public static void UnboxContentObjectForGeoRSS(ContentObject ContentObj, List<IGeoRSS> UnboxedContentObjects)
    {
      CAP Capmsg;
      EDXLHAVE Havemsg;
      SitRep SitRepmsg;
      TEP TEPmsg;
      CoTWrapper cotmsg;
      ResourceMessageType RMmsg;

      int index = -1;
      index = ContentObj.IndexOfNamedKeywordList(EDXLConstants.ContentKeywordListName);
      if (ContentObj.XMLContent != null && ContentObj.ContentKeyword != null && index != -1)
      {
        foreach (XElement doc in ContentObj.XMLContent.EmbeddedXMLContent)
        {
          if (ContentObj.ContentKeyword[index].Value.Contains("EDXL-CAP") || ContentObj.ContentKeyword[index].Value.Contains("CAP"))
          {
            Capmsg = new CAP();
						XmlDocument xdoc = new XmlDocument();
						using (XmlReader xr = doc.CreateReader())
						{
							xdoc.Load(xr);
						}
            Capmsg.ReadXML(xdoc.FirstChild);
            UnboxedContentObjects.Add(Capmsg);
          }
          else if (ContentObj.ContentKeyword[index].Value.Contains("EDXL-HAVE") || ContentObj.ContentKeyword[index].Value.Contains("HAVE"))
          {
            Havemsg = new EDXLHAVE();
						XmlDocument xdoc = new XmlDocument();
						using (XmlReader xr = doc.CreateReader())
						{
							xdoc.Load(xr);
						}
            Havemsg.ReadXML(xdoc.FirstChild);
            UnboxedContentObjects.Add(Havemsg);
          }
          else if (ContentObj.ContentKeyword[index].Value.Contains("EDXL-RM") || ContentObj.ContentKeyword[index].Value.Contains("EDXL-RM ResponseToRequestResource") ||
            ContentObj.ContentKeyword[index].Value.Contains("EDXL-RM ReportResourceDeploymentStatus") || ContentObj.ContentKeyword[index].Value.Contains("EDXL-RM ResponseToRequestExtendedDeploymentDuration") ||
            ContentObj.ContentKeyword[index].Value.Contains("EDXL-RM ResponseToRequestReturn") || ContentObj.ContentKeyword[index].Value.Contains("EDXL-RM OfferUnsolicitedResource") ||
            ContentObj.ContentKeyword[index].Value.Contains("EDXL-RM ReleaseResource") || ContentObj.ContentKeyword[index].Value.Contains("EDXL-RM ResponseToRequestResource") ||
            ContentObj.ContentKeyword[index].Value.Contains("EDXL-RM RequestQuote") || ContentObj.ContentKeyword[index].Value.Contains("EDXL-RM RequestResource") ||
            ContentObj.ContentKeyword[index].Value.Contains("EDXL-RM RequestReturn") || ContentObj.ContentKeyword[index].Value.Contains("EDXL-RM RequestExtendedDeploymentDuration") ||
            ContentObj.ContentKeyword[index].Value.Contains("EDXL-RM RequestInformation") || ContentObj.ContentKeyword[index].Value.Contains("EDXL-RM ResponseToRequestQuote") ||
            ContentObj.ContentKeyword[index].Value.Contains("EDXL-RM ResponseToRequestInformation") || ContentObj.ContentKeyword[index].Value.Contains("EDXL-RM CommitResource") ||
            ContentObj.ContentKeyword[index].Value.Contains("EDXL-RM RequestResourceDeploymentStatus"))
          {
            RMmsg = new ResourceMessageType();
            XmlDocument xdoc = new XmlDocument();
            using (XmlReader xr = doc.CreateReader())
            {
              xdoc.Load(xr);
            }
            RMmsg.ReadXML(xdoc.FirstChild);
            UnboxedContentObjects.Add(RMmsg);
          }
          else if (ContentObj.ContentKeyword[index].Value.Contains("EDXL-SitRep") ||
           ContentObj.ContentKeyword[index].Value.Contains("EDXL-SitRep CasualtyAndIllnessSummary") ||
           ContentObj.ContentKeyword[index].Value.Contains("EDXL-SitRep FieldObservation") ||
           ContentObj.ContentKeyword[index].Value.Contains("EDXL-SitRep ManagementReportingSummary") ||
           ContentObj.ContentKeyword[index].Value.Contains("EDXL-SitRep ResponseResourcesTotals") ||
           ContentObj.ContentKeyword[index].Value.Contains("EDXL-SitRep SituationInformation"))
          {
            // Normal XML
            XmlDocument xdoc = new XmlDocument();
            using (XmlReader xr = doc.CreateReader())
            {
              xdoc.Load(xr);
            }

            // Transform to XDocument (A type of XElement)
            XDocument xDoc = new XDocument();
            using (XmlWriter xmlWriter = xDoc.CreateWriter())
            {
              xdoc.WriteTo(xmlWriter);
            }
           

            EDXLSharp.EDXLSitRepLib.SitRep SitRepMsg = new EDXLSharp.EDXLSitRepLib.SitRep(xDoc.Root);

            UnboxedContentObjects.Add(SitRepMsg);
          }
          else if (ContentObj.ContentKeyword[index].Value.Contains("MEXL-SitRep") || ContentObj.ContentKeyword[index].Value.Contains("SitRep"))
          {
            SitRepmsg = new SitRep();
            XmlDocument xdoc = new XmlDocument();
            using (XmlReader xr = doc.CreateReader())
            {
              xdoc.Load(xr);
            }
            SitRepmsg.ReadXML(xdoc.FirstChild);
            UnboxedContentObjects.Add(SitRepmsg);
          }
          else if (ContentObj.ContentKeyword[index].Value.Contains("MEXL-TEP") || ContentObj.ContentKeyword[index].Value.Contains("TEP"))
          {
            TEPmsg = new TEP();
            XmlDocument xdoc = new XmlDocument();
            using (XmlReader xr = doc.CreateReader())
            {
              xdoc.Load(xr);
            }
            TEPmsg.ReadXML(xdoc.FirstChild);
            UnboxedContentObjects.Add(TEPmsg);
          }
          else if (ContentObj.ContentKeyword[index].Value.Contains("CoTEvent"))
          {
            cotmsg = new CoTWrapper();
            XmlDocument xdoc = new XmlDocument();
            using (XmlReader xr = doc.CreateReader())
            {
              xdoc.Load(xr);
            }
            cotmsg.ReadXML(xdoc.FirstChild);
            UnboxedContentObjects.Add(cotmsg);
          }
        }
      }
    }

Last edited Jun 1, 2011 at 1:50 PM by dmcgarry, version 1

Comments

qkorbulic Dec 20, 2013 at 5:22 PM 
Hello, in this bit of code (below), EDXLConstants.ContentKeywordListName is a URL to an XML based list of message types. IndexOfNamedKeywordList requires a string that should represent a named list.

index = ContentObj.IndexOfNamedKeywordList(EDXLConstants.ContentKeywordListName);

This is not working: though no error is returned, index continues to be -1 after this line. Can anyone provide pointers on why this might not be working.

Thanks