Пример #1
0
        private bool ValidateDivision(ArrayList errors)
        {
            if (!DenominatorMeasure.Validate(errors) ||
                !NumeratorMeasure.Validate(errors))
            {
                return(false);
            }

            if (NumeratorMeasure.Equals(DenominatorMeasure))
            {
                Common.WriteError("XBRLParser.Error.NumerAndDenomEqual", errors, UnitID);
                return(false);
            }

            return(true);
        }
Пример #2
0
        /// <summary>
        /// Creates an <see cref="XmlElement"/> to represent this instance of <see cref="UnitProperty"/>.  Save the element
        /// as a property of this <see cref="UnitProperty"/>.
        /// </summary>
        /// <param name="doc">The <see cref="XmlDocument"/> from which any elements are to be created.</param>
        /// <param name="root">The root <see cref="XmlElement"/> to which elements will be appended.</param>
        /// <param name="errorList">A collection of <see cref="String"/> objects to which method
        /// will append any errors that render the properties invalid.</param>
        /// <param name="unit">An output parameter.</param>
        /// <param name="writeComment">Not used.</param>
        /// <param name="applyNamespaces">Namespaces are to be used in creating and naming newly created elements.</param>
        /// <returns>True if <see cref="XmlElement"/> could be successfully created and written.</returns>
        protected bool WriteXml(XmlDocument doc, XmlElement root, ArrayList errorList, out XmlElement unit, bool writeComment, bool applyNamespaces)
        {
            unit = applyNamespaces ? doc.CreateElement(UNIT, DocumentBase.XBRL_INSTANCE_URL) : doc.CreateElement(UNIT);

            this.xmlUnit = unit;
            ++UseCount;

            unit.SetAttribute(ID_ATTR, UnitID);

            /*if (writeComment)
             *      unit.AppendChild( doc.CreateComment( string.Format( "{0}: {1}", SCALE, Scale ) ) );*/

            switch (UnitType)
            {
            case UnitTypeCode.Standard:
                if (!StandardMeasure.Validate(errorList))
                {
                    unit = null;
                    return(false);
                }

                unit.AppendChild(StandardMeasure.CreateElement(doc, root, applyNamespaces));
                break;

            case UnitTypeCode.Divide:
                if (!ValidateDivision(errorList))
                {
                    unit = null;
                    return(false);
                }
                XmlElement divide = applyNamespaces ? doc.CreateElement(DIVIDE, DocumentBase.XBRL_INSTANCE_URL) : doc.CreateElement(DIVIDE);
                unit.AppendChild(divide);

                XmlElement numer = applyNamespaces ? doc.CreateElement(NUMER, DocumentBase.XBRL_INSTANCE_URL) : doc.CreateElement(NUMER);
                divide.AppendChild(numer);
                numer.AppendChild(NumeratorMeasure.CreateElement(doc, root, applyNamespaces));

                XmlElement denom = applyNamespaces ? doc.CreateElement(DENOM, DocumentBase.XBRL_INSTANCE_URL) : doc.CreateElement(DENOM);
                divide.AppendChild(denom);
                denom.AppendChild(DenominatorMeasure.CreateElement(doc, root, applyNamespaces));

                break;

            case UnitTypeCode.Multiply:
                foreach (Measure m in MultiplyMeasures)
                {
                    m.Validate(errorList);
                    unit.AppendChild(m.CreateElement(doc, root, applyNamespaces));
                }

                if (errorList.Count != 0)
                {
                    unit = null;
                    return(false);
                }
                break;
            }

            //doc.AppendChild( unit );
            return(true);
        }