Example #1
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 );
        }
Example #2
0
        private int LoadChildren( XmlNodeList childList, Element parent )
        {
            int numErrors = 0;
            XmlNode outerChild = GetFirstNonCommentNode( childList );

            while ( (outerChild != null) && (outerChild.Name.IndexOf( SEQ_TAG ) == -1)
                )
            {
                outerChild = outerChild.FirstChild;
            }
            if ( outerChild == null )
            {

                outerChild = GetFirstNonCommentNode( childList );
                while ( (outerChild != null) && (outerChild.Name.IndexOf( CHOICE_TAG ) == -1)
                    )
                {
                    outerChild = outerChild.FirstChild;
                }

                if ( outerChild == null )
                {
                    Common.WriteError( "XBRLParser.Error.AdvancedTuplesNotSupported", errorList );
                    ++numErrors;
                    return numErrors;
                }
                outerChild = outerChild.ParentNode;

            }

            // process the children of the tuple
            foreach ( XmlElement child in outerChild )
            {
                //ignore the comments
                if ( child.NodeType == XmlNodeType.Comment ) continue;

                if ( child.LocalName.CompareTo( CHOICE_TAG ) == 0 )
                {
                    if ( !LoadChoices( child, parent, ref numErrors ) )
                    {
                        return numErrors;
                    }
                }
                else
                {

                    Element e = LoadChild( child, parent, ref numErrors );

                    if ( e != null )
                    {
                        int minOccurs = 0;
                        int maxOccurs = 0;

                        GetOccurances( child, out minOccurs, out maxOccurs );

                        parent.AddChildInfo( e.Id, minOccurs, maxOccurs);
                    }

                }
            }

            return numErrors;
        }