Example #1
0
        /// <summary>
        /// It returns the SvgElement with the given XML Id.
        /// </summary>
        /// <param name="sId">XML identifier of the element.</param>
        /// <returns>
        /// The SvgElement with the given XML Id. Null if no element can be found.
        /// </returns>
        public SvgElement GetSvgElement(string sId)
        {
            SvgElement eleToReturn = null;

            IDictionaryEnumerator e = m_elements.GetEnumerator();

            bool bLoop = e.MoveNext();

            while (bLoop)
            {
                string sValue = "";

                SvgElement ele = (SvgElement)e.Value;
                sValue = ele.GetAttributeStringValue(SvgAttribute._SvgAttribute.attrCore_Id);
                if (sValue == sId)
                {
                    eleToReturn = ele;
                    bLoop       = false;
                }

                bLoop = e.MoveNext();
            }

            return(eleToReturn);
        }
Example #2
0
        /// <summary>
        /// It creates a new element copying all attributes from eleToClone; the new
        /// element is inserted under the parent element provided.
        /// </summary>
        /// <param name="parent">Parent element. If null the element is added under the root.</param>
        /// <param name="eleToClone">Element to be cloned</param>
        /// <returns></returns>
        public SvgElement CloneElement(SvgElement parent, SvgElement eleToClone)
        {
            // calculate unique id
            string sOldId = eleToClone.GetAttributeStringValue(SvgAttribute._SvgAttribute.attrCore_Id);
            string sNewId = sOldId;

            if (sOldId != "")
            {
                int i = 1;

                // check if it is unique
                while (GetSvgElement(sNewId) != null)
                {
                    sNewId = sOldId + "_" + i.ToString();
                    i++;
                }
            }

            // clone operation
            SvgElement eleNew = AddElement(parent, eleToClone.getElementName());

            eleNew.CloneAttributeList(eleToClone);

            if (sNewId != "")
            {
                eleNew.SetAttributeValue(SvgAttribute._SvgAttribute.attrCore_Id, sNewId);
            }

            if (eleToClone.getChild() != null)
            {
                eleNew.setChild(CloneElement(eleNew, eleToClone.getChild()));

                if (eleToClone.getChild().getNext() != null)
                {
                    eleNew.getChild().setNext(CloneElement(eleNew, eleToClone.getChild().getNext()));
                }
            }

            return(eleNew);
        }