/// <summary> /// Create a new <see cref="EmbeddedUnitWrapper"/> with the given /// values. /// </summary> /// <param name="up">The underlying unit property.</param> /// <param name="otherUPs">Other unit properties.</param> public EmbeddedUnitWrapper( UnitProperty up, List<UnitProperty> otherUPs ) { this.UnderlyingUnitProperty = up; this.OtherUnits = new List<UnitProperty>( otherUPs ); if( OtherUnits.Contains( this.UnderlyingUnitProperty ) ) OtherUnits.Remove( this.UnderlyingUnitProperty ); }
/// <summary> /// Determines whether the value of a supplied <see cref="UnitProperty"/> is equivalent to the value /// of this instance of <see cref="UnitProperty"/>. /// </summary> /// <param name="up">A <see cref="UnitProperty"/> /// that is to be compared to this instance of <see cref="UnitProperty"/>.</param> /// <returns>A <see cref="Boolean"/> indicating if the object values are equal (true) or not (false).</returns> /// <remarks>Two <see cref="UnitProperty"/> items values are considered equal if their unit types and measures /// are equal. The measures compared depend upon the unit type.</remarks> public bool ValueEquals(UnitProperty up) { // don't check id if (UnitType == up.UnitType) { switch (UnitType) { case UnitTypeCode.Standard: return(StandardMeasure.Equals(up.StandardMeasure)); case UnitTypeCode.Multiply: if (!MultiplyMeasures[0].Equals(up.MultiplyMeasures[0])) { return(false); } return(MultiplyMeasures[1].Equals(up.MultiplyMeasures[1])); case UnitTypeCode.Divide: if (!NumeratorMeasure.Equals(up.NumeratorMeasure)) { return(false); } return(DenominatorMeasure.Equals(up.DenominatorMeasure)); } } return(false); }
public MergedContextUnitsWrapper( string keyName, ContextProperty cp, UnitProperty up ) : this(keyName, cp) { if ( up != null ) { this.UPS.Add( up ); } }
/// <summary> /// Compare the values of two unit properties to help with sorting... /// </summary> /// <param name="other">A <see cref="UnitProperty"/> /// that is to be compared to this instance of <see cref="UnitProperty"/>.</param> /// <returns></returns> public int CompareValue(UnitProperty other) { // don't check id int ret = this.UnitType.CompareTo(other.UnitType); if (ret != 0) { return(ret); } switch (UnitType) { case UnitTypeCode.Standard: ret = StandardMeasure.CompareValue(other.StandardMeasure); if (ret != 0) { return(ret); } break; case UnitTypeCode.Multiply: ret = MultiplyMeasures[0].CompareValue(other.MultiplyMeasures[0]); if (ret != 0) { return(ret); } ret = MultiplyMeasures[1].CompareValue(other.MultiplyMeasures[1]); if (ret != 0) { return(ret); } break; case UnitTypeCode.Divide: ret = NumeratorMeasure.CompareValue(other.NumeratorMeasure); if (ret != 0) { return(ret); } ret = DenominatorMeasure.CompareValue(other.DenominatorMeasure); if (ret != 0) { return(ret); } break; } return(0); }
/// <summary> /// Determines whether a supplied <see cref="object"/> is equivalent to this instance /// of <see cref="UnitProperty"/>. /// </summary> /// <param name="obj">An <see cref="Object"/>, assumed to be a <see cref="UnitProperty"/> /// that is to be compared to this instance of <see cref="UnitProperty"/>.</param> /// <returns>A <see cref="Boolean"/> indicating if the objects are equal (true) or not (false).</returns> /// <remarks>Two <see cref="UnitProperty"/> objects are considered equal if their unit types, /// scale, and measure are equal. The specific measure compared depends on the unit type.</remarks> public bool ValueEquals(object obj) { if (!(obj is UnitProperty)) { return(false); } UnitProperty up = obj as UnitProperty; if (UnitType != up.UnitType) { return(false); } if (Scale != up.Scale) { return(false); } switch (UnitType) { case UnitTypeCode.Standard: if (!StandardMeasure.Equals(up.StandardMeasure)) { return(false); } break; case UnitTypeCode.Multiply: if (!MultiplyMeasures[0].Equals(up.MultiplyMeasures[0])) { return(false); } if (!MultiplyMeasures[1].Equals(up.MultiplyMeasures[1])) { return(false); } break; case UnitTypeCode.Divide: if (!NumeratorMeasure.Equals(up.NumeratorMeasure)) { return(false); } if (!DenominatorMeasure.Equals(up.DenominatorMeasure)) { return(false); } break; } return(true); }
/// <summary> /// Determines whether a supplied <see cref="object"/> is equivalent to this instance /// of <see cref="UnitProperty"/>. /// </summary> /// <param name="obj">An <see cref="Object"/>, assumed to be a <see cref="UnitProperty"/> /// that is to be compared to this instance of <see cref="UnitProperty"/>.</param> /// <returns>A <see cref="Boolean"/> indicating if the objects are equal (true) or not (false).</returns> /// <remarks>Two <see cref="UnitProperty"/> objects are considered equal if <see cref="ValueEquals(Object)"/> /// for the two objects is true and their unit id properties are equal.</remarks> public override bool Equals(object obj) { if (!(obj is UnitProperty)) { return(false); } UnitProperty up = obj as UnitProperty; if (UnitID != up.UnitID) { return(false); } return(ValueEquals(obj)); }
public static bool IsCustomUnit( UnitProperty up ) { if( up == null ) return false; if( up.StandardMeasure == null || string.IsNullOrEmpty( up.StandardMeasure.MeasureValue ) ) return false; if( up.UnitType != UnitProperty.UnitTypeCode.Standard ) return false; if( InstanceReportColumn.IsPureUnit( up ) || InstanceReportColumn.IsSharesUnit( up ) || InstanceReportColumn.IsMonetaryUnit( up ) ) return false; return true; }
//TODO remove - unused public EmbeddedUnitWrapper( UnitProperty up ) { this.UnderlyingUnitProperty = up; }
public object Clone() { //Clones all base type properties and shallow clones any complex types //Complex types will be recloned further down in the code. MergedContextUnitsWrapper mcu = this.MemberwiseClone() as MergedContextUnitsWrapper; mcu.contextRef = new ContextProperty( this.contextRef.ContextID ); mcu.contextRef.EntitySchema = this.contextRef.EntitySchema; mcu.contextRef.EntityValue = this.contextRef.EntityValue; mcu.contextRef.PeriodDisplayName = this.contextRef.PeriodDisplayName; mcu.contextRef.PeriodEndDate = this.contextRef.PeriodEndDate; mcu.contextRef.PeriodStartDate = this.contextRef.PeriodStartDate; mcu.contextRef.PeriodType = this.contextRef.PeriodType; mcu.contextRef.Segments = new ArrayList(); #region clone segments foreach( Segment seg in this.contextRef.Segments ) { Segment segClone = new Segment(); //Setting DimensionInfo sets some of the other properties on the Segment, so to ensure that //the object is truely cloned set DimensionInfo first then set the other properties if (seg.DimensionInfo != null) { segClone.DimensionInfo = seg.DimensionInfo.Clone() as ContextDimensionInfo; } segClone.Name = seg.Name; segClone.ValueName = seg.ValueName; segClone.ValueType = seg.ValueType; segClone.Namespace = seg.Namespace; segClone.Schema = seg.Schema; mcu.contextRef.AddSegment( segClone ); } #endregion #region clone scenarios foreach( Scenario scen in this.contextRef.Scenarios ) { Segment scenClone = new Segment(); //Setting DimensionInfo sets some of the other properties on the scenario, so to ensure that //the object is truely cloned set DimensionInfo first then set the other properties if (scen.DimensionInfo != null) { scenClone.DimensionInfo = scen.DimensionInfo.Clone() as ContextDimensionInfo; } scenClone.Name = scen.Name; scenClone.ValueName = scen.ValueName; scenClone.ValueType = scen.ValueType; scenClone.Namespace = scen.Namespace; scenClone.Schema = scen.Schema; mcu.contextRef.AddScenario( scen ); } #endregion #region clone unit properties mcu.UPS = new List<UnitProperty>(); foreach (UnitProperty up in this.UPS) { UnitProperty upClone = new UnitProperty(up.UnitID, up.UnitType); upClone.Scale = up.Scale; if (up.StandardMeasure != null) { upClone.StandardMeasure = new Aucent.MAX.AXE.XBRLParser.Measure(); upClone.StandardMeasure.MeasureNamespace = up.StandardMeasure.MeasureNamespace; upClone.StandardMeasure.MeasureSchema = up.StandardMeasure.MeasureSchema; upClone.StandardMeasure.MeasureValue = up.StandardMeasure.MeasureValue; } if (up.MultiplyMeasures != null) { upClone.MultiplyMeasures = new Aucent.MAX.AXE.XBRLParser.Measure[up.MultiplyMeasures.Length]; for (int i = 0; i < up.MultiplyMeasures.Length; i++) { upClone.MultiplyMeasures[i] = new Aucent.MAX.AXE.XBRLParser.Measure(); upClone.MultiplyMeasures[i].MeasureNamespace = up.MultiplyMeasures[i].MeasureNamespace; upClone.MultiplyMeasures[i].MeasureSchema = up.MultiplyMeasures[i].MeasureSchema; upClone.MultiplyMeasures[i].MeasureValue = up.MultiplyMeasures[i].MeasureValue; } } if (up.NumeratorMeasure != null) { upClone.NumeratorMeasure = new Aucent.MAX.AXE.XBRLParser.Measure(); upClone.NumeratorMeasure.MeasureNamespace = up.NumeratorMeasure.MeasureNamespace; upClone.NumeratorMeasure.MeasureSchema = up.NumeratorMeasure.MeasureSchema; upClone.NumeratorMeasure.MeasureValue = up.NumeratorMeasure.MeasureValue; } if (up.DenominatorMeasure != null) { upClone.DenominatorMeasure = new Aucent.MAX.AXE.XBRLParser.Measure(); upClone.DenominatorMeasure.MeasureNamespace = up.DenominatorMeasure.MeasureNamespace; upClone.DenominatorMeasure.MeasureSchema = up.DenominatorMeasure.MeasureSchema; upClone.DenominatorMeasure.MeasureValue = up.DenominatorMeasure.MeasureValue; } mcu.UPS.Add(upClone); } #endregion mcu.CurrencySymbol = this.CurrencySymbol; mcu.CurrencyCode = this.CurrencyCode; return mcu; }
/// <summary> /// Add the provided property to the other units list. /// </summary> /// <param name="up">The <see cref="UnitProperty"/> to add to the /// other units list.</param> public void AddOtherUnits( UnitProperty up ) { AddOtherUnits( new UnitProperty[]{ up } ); }
/// <summary> /// Sets the unit reference and text properties of this <see cref="MarkupProperty"/>. /// </summary> /// <param name="up">The unit id of this <see cref="UnitProperty"/> will be /// included in unit text property.</param> public void SetUnit(UnitProperty up) { this.unitRef = up; this.unitText = (up == null) ? string.Empty : "unit: " + up.UnitID; }
private static string GetColumnCurrencyCode( InstanceReportColumn col, out UnitProperty unitProp ) { unitProp = new UnitProperty(); string cc = string.Empty; if( col == null ) return cc; foreach( UnitProperty up in col.Units ) { if( InstanceReportColumn.IsMonetaryUnit( up ) ) { cc = InstanceUtils.GetCurrencyCodeFromUnit( up ); if( cc == null ) continue; cc = cc.Trim().ToUpper(); if( cc == string.Empty ) continue; unitProp = up; return cc; } } return string.Empty; }
/// <summary> /// Determines whether the value of a supplied <see cref="UnitProperty"/> is equivalent to the value /// of this instance of <see cref="UnitProperty"/>. /// </summary> /// <param name="up">A <see cref="UnitProperty"/> /// that is to be compared to this instance of <see cref="UnitProperty"/>.</param> /// <returns>A <see cref="Boolean"/> indicating if the object values are equal (true) or not (false).</returns> /// <remarks>Two <see cref="UnitProperty"/> items values are considered equal if their unit types and measures /// are equal. The measures compared depend upon the unit type.</remarks> public bool ValueEquals(UnitProperty up) { // don't check id if (UnitType == up.UnitType) { switch (UnitType) { case UnitTypeCode.Standard: return StandardMeasure.Equals(up.StandardMeasure); case UnitTypeCode.Multiply: if (!MultiplyMeasures[0].Equals(up.MultiplyMeasures[0])) return false; return MultiplyMeasures[1].Equals(up.MultiplyMeasures[1]); case UnitTypeCode.Divide: if (!NumeratorMeasure.Equals(up.NumeratorMeasure)) return false; return DenominatorMeasure.Equals(up.DenominatorMeasure); } } return false; }
public static bool IsSharesUnit( UnitProperty up ) { if( up == null ) return false; if( up.UnitType == UnitProperty.UnitTypeCode.Standard && string.Equals( up.StandardMeasure.MeasureValue, "shares", StringComparison.CurrentCultureIgnoreCase ) ) { return true; } return false; }
public static bool IsExchangeRateUnit( UnitProperty up ) { if( up == null ) return false; //currency / currency = "exchangeRate" if( up.UnitType == UnitProperty.UnitTypeCode.Divide && string.Equals( up.NumeratorMeasure.MeasureNamespace, InstanceUtils.CURRENCY_NAMESPACE, StringComparison.CurrentCultureIgnoreCase ) && string.Equals( up.DenominatorMeasure.MeasureNamespace, InstanceUtils.CURRENCY_NAMESPACE, StringComparison.CurrentCultureIgnoreCase ) ) { return true; } return false; }
internal static bool TryCreateFromXml(XmlNode elem, XmlNamespaceManager theManager, out UnitProperty up, ref ArrayList errors) { up = new UnitProperty(); up.UnitID = elem.Attributes[ID_ATTR].Value; XmlNodeList measures = theManager == null?elem.SelectNodes(Measure.MEASURE) : elem.SelectNodes("./link2:" + Measure.MEASURE, theManager); if (measures.Count > 0) { if (measures.Count == 1) { up.UnitType = UnitTypeCode.Standard; return(Measure.TryCreateFromXml(measures[0], ref up.StandardMeasure, ref errors)); } else { up.UnitType = UnitTypeCode.Multiply; up.MultiplyMeasures = new Measure[measures.Count]; for (int i = 0; i < measures.Count; ++i) { if (!Measure.TryCreateFromXml(measures[i], ref up.MultiplyMeasures[i], ref errors)) { return(false); } } } } else { XmlNode divide = theManager == null?elem.SelectSingleNode(DIVIDE) : elem.SelectSingleNode("./link2:" + DIVIDE, theManager); if (divide != null) { up.UnitType = UnitTypeCode.Divide; XmlNode numerator = theManager == null?divide.SelectSingleNode(NUMER) : divide.SelectSingleNode("./link2:" + NUMER, theManager); XmlNode denominator = theManager == null?divide.SelectSingleNode(DENOM) : divide.SelectSingleNode("./link2:" + DENOM, theManager); if (numerator == null) { Common.WriteError("XBRLParser.Error.MissingRequiredField", errors, NUMER); return(false); } else if (denominator == null) { Common.WriteError("XBRLParser.Error.MissingRequiredField", errors, DIVIDE); return(false); } if (!Measure.TryCreateFromXml(numerator.FirstChild, ref up.NumeratorMeasure, ref errors)) { return(false); } else if (!Measure.TryCreateFromXml(denominator.FirstChild, ref up.DenominatorMeasure, ref errors)) { return(false); } return(up.ValidateDivision(errors)); } else { Common.WriteError("XBRLParser.Error.MissingRequiredField", errors, "measure"); return(false); } } return(true); }
public static string GetCurrencyCodeFromUnit( UnitProperty up ) { if( up == null ) return string.Empty; string code = string.Empty; if( up.UnitType == UnitProperty.UnitTypeCode.Standard && up.StandardMeasure.MeasureSchema.Contains( "4217" ) ) { code = up.StandardMeasure.MeasureValue; } else if( up.UnitType == UnitProperty.UnitTypeCode.Divide && up.NumeratorMeasure != null && up.NumeratorMeasure.MeasureSchema.Contains( "4217" ) ) { code = up.NumeratorMeasure.MeasureValue; } if( code == null ) return string.Empty; code = code.Trim().ToUpper(); return code; }
public static bool IsMonetaryUnit( UnitProperty up ) { if( up == null ) return false; if( up.UnitType == UnitProperty.UnitTypeCode.Standard && string.Equals( up.StandardMeasure.MeasureNamespace, InstanceUtils.CURRENCY_NAMESPACE, StringComparison.CurrentCultureIgnoreCase ) ) { return true; } return false; }
private void PopulateNumeric() { Element.PeriodType periodType = Element.PeriodType.duration; element = new Node( Element.CreateMonetaryElement("test", false, Element.BalanceType.credit, periodType) ); contextRef = new ContextProperty(); contextRef.PeriodType = periodType; unitRef = new UnitProperty(); markupData = "-123.12"; }
/// <summary> /// Compare the values of two unit properties to help with sorting... /// </summary> /// <param name="other">A <see cref="UnitProperty"/> /// that is to be compared to this instance of <see cref="UnitProperty"/>.</param> /// <returns></returns> public int CompareValue(UnitProperty other) { // don't check id int ret = this.UnitType.CompareTo(other.UnitType); if (ret != 0) return ret; switch (UnitType) { case UnitTypeCode.Standard: ret = StandardMeasure.CompareValue(other.StandardMeasure); if (ret != 0) return ret; break; case UnitTypeCode.Multiply: ret = MultiplyMeasures[0].CompareValue(other.MultiplyMeasures[0]); if (ret != 0) return ret; ret = MultiplyMeasures[1].CompareValue(other.MultiplyMeasures[1]); if (ret != 0) return ret; break; case UnitTypeCode.Divide: ret = NumeratorMeasure.CompareValue(other.NumeratorMeasure); if (ret != 0) return ret; ret = DenominatorMeasure.CompareValue(other.DenominatorMeasure); if (ret != 0) return ret; break; } return 0; }
public void ValidateInvalidNonNumeric() { PopulateNonNumeric(); unitRef = new UnitProperty(); //TestValidate(1); }
internal static bool TryCreateFromXml(XmlNode elem, XmlNamespaceManager theManager, out UnitProperty up, ref ArrayList errors) { up = new UnitProperty(); up.UnitID = elem.Attributes[ID_ATTR].Value; XmlNodeList measures = theManager == null ? elem.SelectNodes(Measure.MEASURE) : elem.SelectNodes("./link2:" + Measure.MEASURE, theManager); if (measures.Count > 0) { if (measures.Count == 1) { up.UnitType = UnitTypeCode.Standard; return Measure.TryCreateFromXml(measures[0], ref up.StandardMeasure, ref errors); } else { up.UnitType = UnitTypeCode.Multiply; up.MultiplyMeasures = new Measure[measures.Count]; for (int i = 0; i < measures.Count; ++i) { if (!Measure.TryCreateFromXml(measures[i], ref up.MultiplyMeasures[i], ref errors)) { return false; } } } } else { XmlNode divide = theManager == null ? elem.SelectSingleNode(DIVIDE) : elem.SelectSingleNode("./link2:" + DIVIDE, theManager); if (divide != null) { up.UnitType = UnitTypeCode.Divide; XmlNode numerator = theManager == null ? divide.SelectSingleNode(NUMER) : divide.SelectSingleNode("./link2:" + NUMER, theManager); XmlNode denominator = theManager == null ? divide.SelectSingleNode(DENOM) : divide.SelectSingleNode("./link2:" + DENOM, theManager); if (numerator == null) { Common.WriteError("XBRLParser.Error.MissingRequiredField", errors, NUMER); return false; } else if (denominator == null) { Common.WriteError("XBRLParser.Error.MissingRequiredField", errors, DIVIDE); return false; } if (!Measure.TryCreateFromXml(numerator.FirstChild, ref up.NumeratorMeasure, ref errors)) { return false; } else if (!Measure.TryCreateFromXml(denominator.FirstChild, ref up.DenominatorMeasure, ref errors)) { return false; } return up.ValidateDivision(errors); } else { Common.WriteError("XBRLParser.Error.MissingRequiredField", errors, "measure"); return false; } } return true; }
public void CreateFromXml() { string startXml = @"<?xml version=""1.0"" encoding=""utf-16""?> <?xml-stylesheet type=""text/xsl"" href=""Test.xsl""?> <!--XBRLParser message--> <!--Based on XBRL 2.1--> <!--Created on SomeDate--> <xbrl xmlns=""http://www.xbrl.org/2003/instance"" xmlns:link=""http://www.xbrl.org/2003/linkbase"" xmlns:xlink=""http://www.w3.org/1999/xlink"" xmlns:usfr_pt=""http://www.xbrl.org/2003/usfr"" xmlns:iso4217=""http://www.xbrl.org/2003/iso4217""> <link:schemaRef xlink:type=""simple"" xlink:href=""test.xsd"" /> <!--Context Section--> <context id=""current_AsOf""> <entity> <identifier scheme=""http://www.rivetsoftware.com"">Rivet</identifier> </entity> <period> <instant>2003-12-31</instant> </period> </context> <!--Unit Section--> <unit id=""u1""> <!--Scale: 2--> <measure>iso4217:USD</measure> </unit> <!--Element Section--> <!--Document address: Excel - Sheet1!$A$1--> <usfr_pt:element1 contextRef=""current_AsOf"" unitRef=""u1"" decimals=""10"">1234500</usfr_pt:element1> </xbrl>"; XmlDocument xDoc = new XmlDocument(); xDoc.LoadXml( startXml ); XmlNamespaceManager theManager = new XmlNamespaceManager( xDoc.NameTable ); theManager.AddNamespace( "link2", "http://www.xbrl.org/2003/instance" ); theManager.AddNamespace( "usfr_pt", "http://www.xbrl.org/2003/usfr" ); ContextProperty cp = new ContextProperty( "current_AsOf" ); cp.EntityValue = "Rivet"; cp.EntitySchema = "http://www.rivetsoftware.com"; cp.PeriodType = Element.PeriodType.instant; cp.PeriodStartDate = new DateTime( 2003, 12, 31 ); ArrayList contexts = new ArrayList( ); contexts.Add( cp ); UnitProperty up = new UnitProperty( "u1", UnitProperty.UnitTypeCode.Standard ); up.StandardMeasure.MeasureNamespace = "iso4217"; up.StandardMeasure.MeasureSchema = "http://www.xbrl.org/2003/iso4217"; up.StandardMeasure.MeasureValue = "USD"; MarkupProperty realMP = new MarkupProperty(); realMP.contextRef = cp; realMP.unitRef = up; realMP.elementId = "usfr_pt_element1"; realMP.element = new Node( new Element( "element1" ) ); realMP.markupData = "1234500"; realMP.precisionDef = new Precision( Precision.PrecisionTypeCode.Decimals, 10 ); ArrayList units = new ArrayList(); units.Add( up ); XmlNodeList elemList = xDoc.SelectNodes( "//usfr_pt:element1", theManager ); Assert.AreEqual( 1, elemList.Count, "elem not found" ); MarkupProperty mp = null; ArrayList errors = new ArrayList(); Assert.IsTrue( MarkupProperty.TryCreateFromXml( 0, elemList, contexts, units, out mp, ref errors ), "markup property not created" ); Assert.IsTrue( mp.Equals( realMP ), "elem different from the real deal" ); Assert.AreEqual( "http://www.xbrl.org/2003/usfr", mp.elementNamespace, "namespace wrong" ); }
private UnitProperty CreateStandardUnit( string id, int scale, string ns, string schema, string val ) { UnitProperty up = new UnitProperty( id, UnitProperty.UnitTypeCode.Standard ); up.Scale = scale; up.StandardMeasure.MeasureNamespace = ns; up.StandardMeasure.MeasureSchema = schema; up.StandardMeasure.MeasureValue = val; return up; }
public void CreateFromXml() { string startXml = @"<?xml version=""1.0"" encoding=""utf-16""?> <!--Blah Blah Blah--> <!--Based on XBRL 2.1--> <!--Blah Blah Blah--> <xbrl xmlns=""http://www.xbrl.org/2003/instance"" xmlns:link=""http://www.xbrl.org/2003/linkbase"" xmlns:xlink=""http://www.w3.org/1999/xlink"" xmlns:usfr_pt=""http://www.xbrl.org/2003/usfr"" xmlns:iso4217=""http://www.xbrl.org/2003/iso4217""> <link:schemaRef xlink:type=""simple"" xlink:href=""test.xsd"" /> <!--Context Section--> <context id=""current_AsOf""> <entity> <identifier scheme=""http://www.rivetsoftware.com"">Rivet</identifier> </entity> <period> <instant>2003-12-31</instant> </period> </context> <!--Unit Section--> <unit id=""u1""> <!--Scale: 0--> <measure>iso4217:USD</measure> </unit> <unit id=""u2""> <!--Scale: 3--> <measure>iso4217:USD</measure> </unit> <!--Tuple Section--> <usfr_pt:tupleParent1> <!--Tuple Set Name: set1--> <!--Document address: Excel - Sheet1!$A$2--> <usfr_pt:element2 contextRef=""current_AsOf"" unitRef=""u2"" decimals=""10"">98765000</usfr_pt:element2> <!--Tuple Set Name: set1--> <!--Document address: Excel - Sheet1!$A$1--> <usfr_pt:element1 contextRef=""current_AsOf"" unitRef=""u1"" decimals=""10"">12345</usfr_pt:element1> </usfr_pt:tupleParent1> </xbrl>"; XmlDocument xDoc = new XmlDocument(); xDoc.LoadXml( startXml ); XmlNamespaceManager theManager = new XmlNamespaceManager( xDoc.NameTable ); theManager.AddNamespace( "link2", "http://www.xbrl.org/2003/instance" ); theManager.AddNamespace( "usfr_pt", "http://www.xbrl.org/2003/usfr" ); ContextProperty cp = new ContextProperty( "current_AsOf" ); cp.EntityValue = "Rivet"; cp.EntitySchema = "http://www.rivetsoftware.com"; cp.PeriodType = Element.PeriodType.instant; cp.PeriodStartDate = new DateTime( 2003, 12, 31 ); ArrayList contexts = new ArrayList( ); contexts.Add( cp ); UnitProperty up = new UnitProperty( "u1", UnitProperty.UnitTypeCode.Standard ); up.StandardMeasure.MeasureNamespace = "iso4217"; up.StandardMeasure.MeasureSchema = "http://www.xbrl.org/2003/iso4217"; up.StandardMeasure.MeasureValue = "USD"; ArrayList units = new ArrayList(); units.Add( up ); UnitProperty up2 = new UnitProperty( "u2", UnitProperty.UnitTypeCode.Standard ); up2.StandardMeasure.MeasureNamespace = "iso4217"; up2.StandardMeasure.MeasureSchema = "http://www.xbrl.org/2003/iso4217"; up2.StandardMeasure.MeasureValue = "USD"; units.Add( up2 ); XmlNodeList elemList = xDoc.SelectNodes( "//usfr_pt:tupleParent1", theManager ); Assert.IsNotNull( elemList, "elem not found" ); Assert.AreEqual( 1, elemList.Count, "elem count is wrong" ); TupleSet ts = null; ArrayList tupleMarkups; ArrayList errors = new ArrayList(); TupleSet.TryCreateFromXml(elemList[0], contexts, units, out ts, out tupleMarkups, ref errors); Assert.AreEqual(2, tupleMarkups.Count, "wrong number of elements returned"); Assert.AreEqual(2, ts.Children.Count , "wrong number of elements returned"); }
/// <summary> /// Creates a new ContextUnitWrapper. /// </summary> public ContextUnitWrapper(string keyName, ContextProperty cp, UnitProperty up) { this.KeyName = keyName; this.CP = cp; this.UP = up; }
/// <summary> /// Appends unit nodes to a parameter supplied root element if they do not exist in <see cref="xDoc"/>. /// Sets the "unitRef" attribute to reflect the unit id /// of a parameter-supplied <see cref="UnitProperty"/>. /// </summary> /// <param name="root">The document-level root element to which elements will be appended.</param> /// <param name="elem">The element whose attributes are to be set.</param> /// <param name="errors">A collection of <see cref="String"/> objects to which method /// will append any errors.</param> /// <param name="presProp">A <see cref="Precision"/> from which precision attributes will be created.</param> /// <param name="unit">A <see cref="UnitProperty"/> from which unit elements will be created.</param> protected void AppendUnitInfo(XmlElement root, XmlElement elem, UnitProperty unit, Precision presProp, ArrayList errors) { elem.SetAttribute( UNIT_REF, unit.UnitID ); if ( presProp != null ) { elem.Attributes.Append( presProp.CreateAttribute( xDoc ) ); } string mergeKey = mergeDocs ? @"//link2:" : @"//"; if ( this.xDoc.SelectSingleNode( string.Format( mergeKey + "unit[@id=\"{0}\"]", unit.UnitID ), theManager ) == null ) { XmlElement unitNode = null; if ( mergeDocs ) { units.Add( unit ); if ( unit.CreateElementWithNamespaces( xDoc, root, errors, out unitNode, this.writeComments ) ) { root.InsertAfter( unitNode, unitComment ); } } else { if ( unit.CreateElement( xDoc, root, errors, out unitNode, this.writeComments ) ) { root.InsertAfter( unitNode, unitComment ); } } } }