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 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 #3
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 #4
0
        private Element LoadChild( XmlElement child, Element parent, ref int numErrors )
        {
            string elementRef = null;

            if ( !Common.GetAttribute( child, REF_TAG, ref elementRef, null ) )
            {
                if ( child.Name == "attribute" )
                {
                    Common.WriteWarning( "Tuple has an attribute defined and Parser does not read attributes " + child.OuterXml, errorList, child.OuterXml );
                    return null;
                }

                // write our own error
                Common.WriteError( "XBRLParser.Warning.NoTagForLocator2", errorList, REF_TAG, child.OuterXml );
                ++numErrors;
                return null;
            }

            // lookup the element
            string[] refStrings = elementRef.Split( ':' );
            //
            //				if ( refStrings.Length != 2 )
            //				{
            //					Common.WriteError( "XBRLParser.Warning.IncorrectRefFormat", errorList, elementRef, refStrings.Length.ToString(), child.OuterXml );
            //					++numErrors;
            //					continue;
            //				}

            string ns = theManager.LookupNamespace( theManager.NameTable.Get( refStrings[0] ) );

            if ( ns == null )
            {
                Common.WriteError( "XBRLParser.Warning.IncorrectChildNamespace", errorList, new string[] { refStrings[0], elementRef, schemaFile, child.OuterXml } );
                ++numErrors;
                return null;
            }

            string elemId = elementRef.Replace( ':', '_' );

            Element e = allElements[elemId] as Element;

            // TODO: stupid check?
            // No, not stupid - we need to bind the element that is defined in another schema to this parent,
            // but we have no way to get the other element
            if ( ns != targetNamespace )
            {
                // see if it's in one of the dependant taxonomies
                foreach ( Taxonomy t in dependantTaxonomies )
                {
                    // see if it's in all elements, if so, return it
                    if (t.allElements == null) continue;
                    if ( (e = t.allElements[elemId] as Element) != null )
                    {
                        break;
                    }
                }

                if ( e == null )
                {

                    if (this.TopLevelTaxonomy != null)
                    {
                        foreach (Taxonomy t in TopLevelTaxonomy.dependantTaxonomies)
                        {
                            // see if it's in all elements, if so, return it
                            if (t.allElements == null) continue;
                            if ((e = t.allElements[elemId] as Element) != null)
                            {
                                break;
                            }
                        }
                    }

                    if (e == null)
                    {
                        // if we made it here there is no element that matches
                        Common.WriteError("XBRLParser.Warning.NotSupportedRemoteLinks", errorList, new string[] { refStrings[0], elementRef, schemaFile, child.OuterXml });
                        ++numErrors;
                        return null;
                    }
                }
            }

            // lookup the child node in the element table
            // this ensures we always get the element, even though it may have been removed from the

            if ( e == null )
            {
                if ( refStrings.Length == 1 )
                {
                    Common.WriteError( "XBRLParser.Warning.IncorrectRefFormat", errorList, elementRef, refStrings.Length.ToString(), child.OuterXml );
                    ++numErrors;
                    return null;
                }
                else
                {
                    e = allElements[refStrings[1]] as Element;

                    if ( e == null )
                    {
                        Common.WriteError( "XBRLParser.Error.ComplexElementsNotSupported", errorList, elemId, elementRef );
                        ++numErrors;
                        return null;
                    }
                }
            }

            //e.Parent = parent;

            parent.AddChild( e );

            return e;
        }