Esempio n. 1
0
        /// <summary>Sets an element or attribute value identified by an XPath-like query string.</summary>
        /// <remarks>
        ///   NOTE: This method makes calls to SIFXPathContext. If multiple calls to
        ///  <c>setElementOrAttribute</c> are being done, it is much more efficient to create
        ///  a new <c>SifXPathContext</c> by calling <c>SifXPathContext.NewInstance(sdo)</c> and then
        /// calling <c>.SetElementorAttributeon</c> on that SifXPathContext instance
        /// </remarks>
        /// <param name="xpath">An XPath-like query string that identifies the element or
        /// attribute to set. The string must reference elements and attributes
        /// by their <i>version-independent</i> names.
        /// </param>
        /// <param name="valu">The value to assign to the element or attribute if the
        /// query string does not set a value; may be null
        /// </param>
        /// <param name="adaptor"> A data source may be used for variable
        /// substitutions within the query string
        /// </param>
        public virtual void SetElementOrAttribute(string xpath,
                                                  string valu,
                                                  IFieldAdaptor adaptor)
        {
            SifVersion = Adk.SifVersion;
            SifXPathContext spc = SifXPathContext.NewSIFContext(this);

            if (adaptor is IXPathVariableLibrary)
            {
                spc.AddVariables("", (IXPathVariableLibrary)adaptor);
            }
            spc.SetElementOrAttribute(xpath, valu);
        }
Esempio n. 2
0
        private SifXPathContext GetXPathContext(
            SifElement mappedElement, IFieldAdaptor adaptor)

        {
            lock (this)
            {
                if (!mappedElement.ElementDef.Name.Equals(fElementDef.Name))
                {
                    throw new AdkMappingException(
                              "Unable to use object for mapping. MappingsContext expected an object of type '" +
                              fElementDef.Name + "' but was '" + mappedElement.ElementDef.Name + "'.", null);
                }

                if (fRootContext == null)
                {
                    fRootContext = SifXPathContext.NewSIFContext(mappedElement, fSIFVersion);
                    if (adaptor is IXPathVariableLibrary)
                    {
                        fRootContext.AddVariables("", (IXPathVariableLibrary)adaptor);
                    }
                }
                return(SifXPathContext.NewSIFContext(fRootContext, mappedElement));
            }
        }