// no-id variant public bool CheckAddNarWrapper1(PropsWrapping1 wrapper) { return CheckAddNarWrapper1(wrapper, string.Empty); }
public bool AddNarPropertyToWrapper1(PropsWrapping1 wrapper, object newProperty) { return AddNarPropertyToWrapper1(wrapper, string.Empty, newProperty); }
// Code History: // 2014-02-26 mws // ****************************************************************************** // ***** G E N E R I C // ******************************************************************************* /// <summary> /// Adds a nar: element which is a member of the PropsWrapping1 enumeration /// as child of the root element. Checks first if the element already exists. /// </summary> /// <param name="wrapper">The wrapping element which should be added</param> /// <param name="wrapperId">The @id value of the wrapping element /// - used for elements with unbounded cardinality</param> /// <returns>True if successfully executed</returns> public bool CheckAddNarWrapper1(PropsWrapping1 wrapper, string wrapperId) { ResetErrState(); string wrapperParentXPath, wrapperParentChildNameSeq; var wrapperXPath = string.Empty; var wrapperLocalName = string.Empty; var wrapperChildNameSeq = string.Empty; if (!GetNarWrapper1Details(wrapper, wrapperId, out wrapperParentXPath, out wrapperParentChildNameSeq, out wrapperXPath, out wrapperLocalName, out wrapperChildNameSeq)) { return false; } if (!ExistsXN(wrapperXPath)) { XmlElement newWrapperXElement = XmlDoc.CreateElement(wrapperLocalName, G2NsCs); if (!string.IsNullOrEmpty(wrapperId)) { if (wrapperLocalName == "partMeta") newWrapperXElement.SetAttribute("partid", wrapperId); else newWrapperXElement.SetAttribute("id", wrapperId); } AddNarPropertyToParent(wrapperParentXPath, wrapperParentChildNameSeq, newWrapperXElement); } return true; }
// no-id variant public bool AddNarPropertyToWrapper1(PropsWrapping1 wrapper, object newProperty, out XmlElement propertyXe) { return AddNarPropertyToWrapper1(wrapper, string.Empty, newProperty, out propertyXe); }
public bool AddNarPropertyToWrapper1(PropsWrapping1 wrapper, string wrapperId, object newProperty) { XmlElement dummyXe; return AddNarPropertyToWrapper1(wrapper, wrapperId, newProperty, out dummyXe); }
// Code History: // 2014-02-25 mws // ******************************************************************************* /// <summary> /// Adds a child nar: element to a wrapping element (member of the PropsWrapping1 enumeration) /// </summary> /// <param name="wrapper">Wrapping element</param> /// <param name="wrapperId">If required: the @id value of the wrapping element</param> /// <param name="newProperty">Object representing the element/property to be added</param> /// <param name="propertyXe">Return the XmlElement of the added element</param> /// <returns>True if successfully executed</returns> public bool AddNarPropertyToWrapper1(PropsWrapping1 wrapper, string wrapperId, object newProperty, out XmlElement propertyXe) { ResetErrState(); propertyXe = null; var wrapperXPath = string.Empty; var wrapperLocalName = string.Empty; var wrapperChildNameSeq = string.Empty; if (!GetNarWrapper1Details(wrapper, wrapperId, out wrapperXPath, out wrapperLocalName, out wrapperChildNameSeq)) { return false; } var newPropName = string.Empty; var newPropUsageCode = string.Empty; var newPropCard = string.Empty; FieldInfo[] fi = newProperty.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance); foreach (FieldInfo info in fi) { if (info.Name == "Xname") { try { newPropName = info.GetValue(newProperty).ToString(); } catch (NullReferenceException ex) { continue; } continue; } if (info.Name == "Xusagecode") { try { newPropUsageCode = info.GetValue(newProperty).ToString(); } catch (NullReferenceException ex) { continue; } continue; } if (info.Name == "Xcard") { try { newPropCard = info.GetValue(newProperty).ToString(); } catch (NullReferenceException ex) { continue; } continue; } } // check if the wrapper element exists, if not: add it. if (!CheckAddNarWrapper1(wrapper, wrapperId)) return false; // create a new XmlElement from the property class propertyXe = XmlDoc.CreateElement(newPropName, G2NsCs); NarProperty2XmlElement(newProperty, propertyXe); // add the new XmlElement as a child of the wrapper AddNarPropertyToParent(wrapperXPath, wrapperChildNameSeq, propertyXe); return true; }
/// <summary> /// Returns a set of data about a member of the PropsWrapping1 enumeration /// = top level elements of a NewsML-G2 item wrapping other properties /// </summary> /// <param name="wrapper">Wrapping property about which the details are requested</param> /// <param name="wrapperId">The @id of the wrapping element</param> /// <param name="wrapperXPath">Returned XPath of the wrapping element</param> /// <param name="wrapperLocalName">Local name of the wrapping element</param> /// <param name="wrapperChildNameSeq">Child name sequence of the wrapping element</param> /// <returns>True if successfully executed</returns> public bool GetNarWrapper1Details(PropsWrapping1 wrapper, string wrapperId, out string wrapperXPath, out string wrapperLocalName, out string wrapperChildNameSeq) { string dummy1, dummy2; return GetNarWrapper1Details(wrapper, wrapperId, out dummy1, out dummy2, out wrapperXPath, out wrapperLocalName, out wrapperChildNameSeq); }
// Code History: // 2014-02-26 mws // ****************************************************************************** /// <summary> /// Returns a set of data about a member of the PropsWrapping1 enumeration /// = top level elements of a NewsML-G2 item wrapping other properties /// </summary> /// <param name="wrapper">Wrapping property about which the details are requested</param> /// <param name="wrapperId">The @id of the wrapping element</param> /// <param name="wrapperParentXPath">Returned XPath of the parent of the wrapping element</param> /// <param name="wrapperParentChildNameSeq">Returned child name sequence of the wrapping element's parent</param> /// <param name="wrapperXPath">Returned XPath of the wrapping element</param> /// <param name="wrapperLocalName">Local name of the wrapping element</param> /// <param name="wrapperChildNameSeq">Child name sequence of the wrapping element</param> /// <returns>True if successfully executed</returns> public bool GetNarWrapper1Details(PropsWrapping1 wrapper, string wrapperId, out string wrapperParentXPath, out string wrapperParentChildNameSeq, out string wrapperXPath, out string wrapperLocalName, out string wrapperChildNameSeq ) { ResetErrState(); wrapperParentXPath = "/nar:" + RootElemName; wrapperParentChildNameSeq = NameSeqFullRoot; wrapperXPath = string.Empty; wrapperLocalName = string.Empty; wrapperChildNameSeq = string.Empty; switch (wrapper) { case PropsWrapping1.Catalog: if (string.IsNullOrEmpty(wrapperId)) { SetErrState(G2DocProcErrEnum.NoWrapperIdAvailable); return false; } wrapperLocalName = "catalog"; wrapperXPath = wrapperParentXPath + "/nar:catalog[@id='" + wrapperId + "']"; wrapperChildNameSeq = "nar:tile nar:scheme"; break; case PropsWrapping1.ConceptSet: wrapperLocalName = "conceptSet"; wrapperXPath = wrapperParentXPath + "/nar:" + wrapperLocalName; wrapperChildNameSeq = "nar:concept"; break; case PropsWrapping1.ContentMeta: wrapperLocalName = "contentMeta"; wrapperXPath = wrapperParentXPath + "/nar:" + wrapperLocalName; if ((RootElemName == "newsItem") || (RootElemName == "packageItem")) wrapperChildNameSeq = NameSeqContentMetaAfD; else wrapperChildNameSeq = NameSeqContentMetaAcD; break; case PropsWrapping1.ContentSet: wrapperLocalName = "contentSet"; wrapperXPath = wrapperParentXPath + "/nar:" + wrapperLocalName; wrapperChildNameSeq = NameSeqContentSet; break; case PropsWrapping1.GroupSet: wrapperLocalName = "groupSet"; wrapperXPath = wrapperParentXPath + "/nar:" + wrapperLocalName; wrapperChildNameSeq = "nar:group"; break; case PropsWrapping1.ItemMeta: wrapperLocalName = "itemMeta"; wrapperXPath = wrapperParentXPath + "/nar:" + wrapperLocalName; wrapperChildNameSeq = NameSeqItemMeta; break; case PropsWrapping1.NMHeader: wrapperLocalName = "header"; wrapperXPath = wrapperParentXPath + "/nar:" + wrapperLocalName; wrapperChildNameSeq = NameSeqNMHeader; break; case PropsWrapping1.NMitemSet: wrapperLocalName = "itemSet"; wrapperXPath = wrapperParentXPath + "/nar:" + wrapperLocalName; wrapperChildNameSeq = ""; break; case PropsWrapping1.NewsConverageSet: wrapperLocalName = "newsCoverageSet"; wrapperXPath = wrapperParentXPath + "/nar:" + wrapperLocalName; wrapperChildNameSeq = "nar:newsCoverage"; break; case PropsWrapping1.PartMeta: if (string.IsNullOrEmpty(wrapperId)) { SetErrState(G2DocProcErrEnum.NoWrapperIdAvailable); return false; } wrapperLocalName = "partMeta"; wrapperXPath = wrapperParentXPath + "/nar:partMeta[@partid='" + wrapperId + "']"; wrapperChildNameSeq = NameSeqPartMeta; break; case PropsWrapping1.RightsInfo: wrapperLocalName = "rightsInfo"; wrapperXPath = wrapperParentXPath + "/nar:" + wrapperLocalName; wrapperChildNameSeq = NameSeqRightsInfo; break; } return true; }