Beispiel #1
0
        public void Test_ElementsNotEqual()
        {
            Element p1 = new Element( "p1_id", "parent_name", "subst1" );
            Element p2 = new Element( "p2_id", "parent_name", "subst1" );

            Assert.IsFalse( p1.Equals( p2 ), "p1 == p2" );

            Element p3 = new Element( "p3_id", "parent_name", "subst1" );
            Element p4 = new Element( "p3_id", "parent_name2", "subst1" );

            Assert.IsFalse( p3.Equals( p4 ), "p3 == p4" );

            Element p5 = new Element( "p5_id", "parent_name", "subst1" );
            Element p6 = new Element( "p5_id", "parent_name", "subst2" );

            Assert.IsFalse( p5.Equals( p6 ), "p5 == p6" );

            Element p7 = new Element( "p7_id", "parent_name", "subst1" );
            p7.AddOptionals( "type3", false, PeriodType.duration, BalanceType.credit, false );

            Element p8 = new Element( "p7_id", "parent_name", "subst1" );
            p8.AddOptionals( "type4", false, PeriodType.duration, BalanceType.credit, false );

            Assert.IsFalse( p7.Equals( p8 ), "p7 == p8" );

            Element p9 = new Element( "p9_id", "parent_name", "subst1" );
            p9.AddOptionals( "type3", false, PeriodType.duration, BalanceType.credit, false );

            Element p10 = new Element( "p9_id", "parent_name", "subst1" );
            p10.AddOptionals( "type3", true, PeriodType.duration, BalanceType.credit, false );

            Assert.IsFalse( p9.Equals( p10 ), "p9 == p10" );

            Element p11 = new Element( "p11_id", "parent_name", "subst1" );
            p11.AddOptionals( "type3", false, PeriodType.duration, BalanceType.credit, false );

            Element p12 = new Element( "p11_id", "parent_name", "subst1" );
            p12.AddOptionals( "type3", false, PeriodType.instant, BalanceType.credit, false );

            Assert.IsFalse( p11.Equals( p12 ), "p11 == p12" );

            Element p13 = new Element( "p13_id", "parent_name", "subst1" );
            p13.AddOptionals( "type3", false, PeriodType.duration, BalanceType.credit, false );

            Element p14 = new Element( "p13_id", "parent_name", "subst1" );
            p14.AddOptionals( "type3", false, PeriodType.duration, BalanceType.debit, false );

            Assert.IsFalse( p13.Equals( p14 ), "p13 == p14" );

            Element p15 = new Element( "p15_id", "parent_name", "subst1" );
            p15.AddOptionals( "type3", false, PeriodType.duration, BalanceType.credit, false );

            Element p16 = new Element( "p15_id", "parent_name", "subst1" );
            p16.AddOptionals( "type3", false, PeriodType.duration, BalanceType.credit, true );

            Assert.IsFalse( p15.Equals( p16 ), "p15 == p16" );

            Element p17 = new Element( "p17_id", "parent_name", "subst1" );
            p17.AddChild( p1 );

            Element p18 = new Element( "p17_id", "parent_name", "subst1" );

            Assert.IsFalse( p17.Equals( p18 ), "p17 == p18" );

            Element p19 = new Element( "p19_id", "parent_name", "subst1" );
            p19.AddChild( p1 );

            Element p20 = new Element( "p19_id", "parent_name", "subst1" );
            p20.AddChild( p2 );

            Assert.IsFalse( p19.Equals( p20 ), "p19 == p20" );

            // c1 is considered the same element even though it has different parents
            Element c1 = new Element( "c1" );
            Element p21 = new Element( "p21_id", "parent_name", "subst1" );
            p21.AddChild( c1 );

            Element c2 = new Element( "c1" );
            Element p22 = new Element( "p21_id", "parent_name", "subst1" );
            p22.AddChild( c2 );

            Assert.IsTrue( c1.Equals( c2 ), "c1 != c2" );
        }
Beispiel #2
0
        public void Test_ElementsEqual()
        {
            Element p1 = new Element( "p1_id", "parent_name", "subst1" );
            p1.AddOptionals( "type1", false, PeriodType.duration, BalanceType.credit, false );
            Element p2 = new Element( "p1_id", "parent_name", "subst1" );
            p2.AddOptionals( "type1", false, PeriodType.duration, BalanceType.credit, false );

            Assert.IsTrue( p1.Equals( p2 ), "p1 != P2" );

            Element p3 = new Element( "p3_id", "parent_name", "subst1" );
            p3.AddOptionals( "type3", false, PeriodType.duration, BalanceType.credit, false );
            p3.AddChild( p1 );

            Element p4 = new Element( "p3_id", "parent_name", "subst1" );
            p4.AddOptionals( "type3", false, PeriodType.duration, BalanceType.credit, false );
            p4.AddChild( p1 );

            Assert.IsTrue( p3.Equals( p4 ), "p3 != p4" );
        }
Beispiel #3
0
        public void ElementToXml()
        {
            Element p1 = new Element( "Parent1", "Parent1", "substGroup1" );
            p1.AddOptionals( "Test", true, Element.PeriodType.duration, Element.BalanceType.debit, false );

            Element c1 = new Element( "Child1", "Child1", "substGroup1" );
            c1.AddOptionals( "Test", true, Element.PeriodType.duration, Element.BalanceType.debit, false );

            p1.AddChild( c1 );
            p1.AddChildInfo(c1.Id, 1, 2);

            Element c2 = new Element( "Child2", "Child2", "substGroup1" );
            c2.AddOptionals( "Test", true, Element.PeriodType.duration, Element.BalanceType.debit, false );

            p1.AddChild( c2 );
            p1.AddChildInfo(c2.Id, 2, int.MaxValue);

            StringBuilder sb = new StringBuilder();

            p1.ToXmlString( 0, null, sb );

            string result = "<parentElement name=\"Parent1\" nillable=\"True\" abstract=\"False\" tuple=\"False\" type=\"Test\" substitutionGroup=\"substGroup1\" periodType=\"duration\" balanceType=\"debit\" minOccurs=\"0\" maxOccurs=\""+Int32.MaxValue+"\">\r\n" +
                                  "\t<element name=\"Child1\" nillable=\"True\" abstract=\"False\" tuple=\"False\" type=\"Test\" substitutionGroup=\"substGroup1\" periodType=\"duration\" balanceType=\"debit\" minOccurs=\"1\" maxOccurs=\"2\"/>\r\n" +
                                  "\t<element name=\"Child2\" nillable=\"True\" abstract=\"False\" tuple=\"False\" type=\"Test\" substitutionGroup=\"substGroup1\" periodType=\"duration\" balanceType=\"debit\" minOccurs=\"2\" maxOccurs=\""+Int32.MaxValue+"\"/>\r\n" +
                                  "</parentElement>\r\n";

            Console.WriteLine( "*** Element.ToXmlString() ***" );
            Console.WriteLine( sb.ToString() );
            Console.WriteLine( "*** Element.ToXmlString() End ***" );

            Assert.AreEqual( result, sb.ToString() );

            XmlDocument doc = new XmlDocument();

            doc.LoadXml( result );
        }
Beispiel #4
0
        public void ElementToXmlFragment()
        {
            Element e1 = new Element( "Test1", "Test1", "substGroup1" );
            e1.AddOptionals( "Test", true, Element.PeriodType.duration, Element.BalanceType.debit, false );

            StringBuilder sb = new StringBuilder();

            Element.WriteXmlFragment(e1, true, null, sb);
            Assert.AreEqual( "name=\"Test1\" nillable=\"True\" abstract=\"False\" tuple=\"False\" type=\"Test\" substitutionGroup=\"substGroup1\" periodType=\"duration\" balanceType=\"debit\" minOccurs=\"0\" maxOccurs=\""+Int32.MaxValue+"\"", sb.ToString() );

            sb.Remove(0, sb.Length);
            Element.WriteXmlFragment( null, true, null, sb );
            Assert.AreEqual( "name=\"\" nillable=\"False\" abstract=\"True\" tuple=\"False\" type=\"\" substitutionGroup=\"\" periodType=\"na\" balanceType=\"na\" minOccurs=\"0\" maxOccurs=\""+Int32.MaxValue+"\"", sb.ToString() );
        }
Beispiel #5
0
        private int AddAdditionalElementInfo( Element e, XmlNode elem, ArrayList errorList )
        {
            string type = null;
            string nillable = "false";
            string ptype = "na";
            string bal = "na";
            string abst = "false";

            // get optional arguments
            if ( !Common.GetAttribute( elem, TYPE_TAG, ref type, null ) )
            {
                if( elem.ChildNodes != null )
                {
                    foreach (XmlNode cn in elem.ChildNodes)
                    {
                        if (cn is XmlComment) continue;

                        if (cn.Name.IndexOf(@"complexType") > 0)
                        {
                            XmlNode restrictionNode = cn.SelectSingleNode(RESTRICTION_KEY, theManager);

                            if (restrictionNode != null)
                            {
                                type = restrictionNode.Attributes[BASE_TAG].Value;

                            }

                        }
                    }

                    if (type == null)
                    {
                        //Write it ourselves
                        Common.WriteError("XBRLParser.Warning.NoTagForLocator2", errorList, TYPE_TAG, elem.OuterXml);
                        return 1;
                    }
                }

            }

            ////fix type perfix to make sure it says xbrli if it is a xbrli type
            //if (!type.StartsWith("xbrli"))
            //{
            //    bool convertToxbrli= false;
            //    string[] parts = type.Split(':');
            //    if( parts.Length > 1 )
            //    {
            //    //it might be a different prefix but still uses the same namespace
            //    theManager.LookupNamespace(
            //}
            Common.GetAttribute(elem, NILLABLE_TAG, ref nillable, null);
            Common.GetAttribute(elem, ABSTRACT_TAG, ref abst, null);
            if (this.HasStandardXBRLIPrefix)
            {
                Common.GetAttribute(elem, PERIOD_TYPE_TAG, ref ptype, null);
                Common.GetAttribute(elem, BALANCE_TAG, ref bal, null);
            }
            else
            {
                //convert the value retured by type...

                type = this.ConvertToXBRLIPrefixIfValidPrefix(type);
                Common.GetAttribute(elem, ConvertXBRLIToValidPrefix(PERIOD_TYPE_TAG), ref ptype, null);
                Common.GetAttribute(elem, ConvertXBRLIToValidPrefix(BALANCE_TAG), ref bal, null);

            }

            e.AddOptionals( type,
                Boolean.Parse( nillable ),
                (Element.PeriodType)Enum.Parse( typeof( Element.PeriodType ), ptype, true ),
                (Element.BalanceType)Enum.Parse( typeof( Element.BalanceType ), bal, true ),
                Boolean.Parse( abst ) );

            if ( type != null && enumTable.Count > 0 && enumTable.ContainsKey( type ) )
            {
                // set the enumeration
                e.EnumData = enumTable[type] as Enumeration;
            }

            return 0;
        }