Beispiel #1
0
        public int Compare(object x, object y)
        {
            FootnoteProperty one = x as FootnoteProperty;
            FootnoteProperty two = y as FootnoteProperty;

            string subone = one.Id.Replace("Footnote-", string.Empty);
            string subtwo = two.Id.Replace("Footnote-", string.Empty);

            int id1 = 0, id2 = 0;

            if (int.TryParse(subone, out id1) && int.TryParse(subtwo, out id2))
            {
                return(id1.CompareTo(id2));
            }

            return(one.Id.CompareTo(two.Id));
        }
Beispiel #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="fp"></param>
        /// <param name="parentEle"></param>
        protected void AddFootnoteResource( FootnoteProperty fp, XmlElement parentEle )
        {
            XmlElement resource = null;
            resource = this.xDoc.CreateElement(DocumentBase.XBRL_LINKBASE_PREFIX, FOOTNOTE_RESOURCE, DocumentBase.XBRL_LINKBASE_URL);

            XmlAttribute resAttr = xDoc.CreateAttribute( DocumentBase.XLINK_PREFIX, TYPE, DocumentBase.XLINK_URI );
            resAttr.Value = RESOURCE;
            resource.SetAttributeNode( resAttr );

            XmlAttribute resRoleAttr = xDoc.CreateAttribute( DocumentBase.XLINK_PREFIX, ROLE, DocumentBase.XLINK_URI );
            resRoleAttr.Value = FOOTNOTE_RESOURCE_ARCROLE;
            resource.SetAttributeNode( resRoleAttr );

            XmlAttribute labelAttr = xDoc.CreateAttribute( DocumentBase.XLINK_PREFIX, LABEL, DocumentBase.XLINK_URI );
            labelAttr.Value = fp.Id;
            resource.SetAttributeNode( labelAttr );

            XmlAttribute langAttr = xDoc.CreateAttribute(XML, LANG, DocumentBase.XBRL_INSTANCE_URL);
            langAttr.Value = fp.language;
            resource.SetAttributeNode( langAttr );

            try
            {
                resource.InnerXml = fp.markupData;
            }
            catch (Exception)
            {
                resource.InnerText = fp.markupData;
            }

            parentEle.AppendChild(resource);

            if ( writeComments )
            {
                XmlComment locComment = xDoc.CreateComment( TraceUtility.FormatStringResource( "XBRLParser.Info.InstanceDocMarkupAddress", fp.address ) );
                parentEle.InsertBefore(locComment, resource);
            }

            fp.HasBeenWritten = true;
        }
Beispiel #3
0
        public void Test_AddDuplicateFootnoteResources()
        {
            xDoc = new XmlDocument();
            xDoc.AppendChild( xDoc.CreateXmlDeclaration( "1.0", "utf-16", null ) );
            XmlElement root = xDoc.CreateElement( XBRL );
            xDoc.AppendChild( root );

            root.SetAttribute(DocumentBase.XMLNS, DocumentBase.XBRL_INSTANCE_URL);
            root.SetAttribute(string.Format(DocumentBase.NAME_FORMAT, DocumentBase.XMLNS, DocumentBase.XBRL_LINKBASE_PREFIX), DocumentBase.XBRL_LINKBASE_URL);
            root.SetAttribute(string.Format(DocumentBase.NAME_FORMAT, DocumentBase.XMLNS, DocumentBase.XLINK_PREFIX), DocumentBase.XLINK_URI);

            CreateInstanceSkeleton( root, true, true );

            ArrayList mps = new ArrayList();

            // markup property
            MarkupProperty mp = new MarkupProperty();
            mp.Id = "Item-01";
            mp.xmlElement = xDoc.CreateElement( "usfr_pt:element1" );
            mp.address = "$c$6";
            FootnoteProperty fp = new FootnoteProperty( "Footnote-01", "$c$7", "en", "this is the footnote" );
            mp.Link( fp );
            mps.Add( mp );

            // markup property 2
            MarkupProperty mp2 = new MarkupProperty();
            mp2.Id = "Item-02";
            mp2.xmlElement = xDoc.CreateElement( "usfr_pt:element2" );
            mp2.address = "$b$6";
            mp2.Link( fp );
            mps.Add( mp2 );

            AddFootnoteLocatorsAndArcs( mps );
            AddFootnoteResources( mps );

            System.IO.StringWriter xml = new System.IO.StringWriter();
            xDoc.Save( xml );
            Console.WriteLine( xml.ToString() );

            string expectedXml =
                @"<?xml version=""1.0"" encoding=""utf-16""?>
            <xbrl xmlns=""http://www.xbrl.org/2003/instance"" xmlns:link=""http://www.xbrl.org/2003/linkbase"" xmlns:xlink=""http://www.w3.org/1999/xlink"">
              <!--Context Section-->
              <!--Unit Section-->
              <!--Tuple Section-->
              <!--Element Section-->
              <!--Footnote Section-->
              <link:footnoteLink xlink:type=""extended"" xlink:role=""http://www.xbrl.org/2003/role/link"">
            <!--Document address: $c$6 - Element Name: usfr_pt:element1-->
            <link:loc xlink:type=""locator"" xlink:href=""#Item-01"" xlink:label=""Item-01_lbl"" />
            <link:footnoteArc xlink:type=""arc"" xlink:arcrole=""http://www.xbrl.org/2003/arcrole/fact-footnote"" xlink:from=""Item-01_lbl"" xlink:to=""Footnote-01"" order=""1"" />
            <!--Document address: $b$6 - Element Name: usfr_pt:element2-->
            <link:loc xlink:type=""locator"" xlink:href=""#Item-02"" xlink:label=""Item-02_lbl"" />
            <link:footnoteArc xlink:type=""arc"" xlink:arcrole=""http://www.xbrl.org/2003/arcrole/fact-footnote"" xlink:from=""Item-02_lbl"" xlink:to=""Footnote-01"" order=""1"" />
            <!--Document address: $c$7-->
            <link:footnote xlink:type=""resource"" xlink:role=""http://www.xbrl.org/2003/role/footnote"" xlink:label=""Footnote-01"" xml:lang=""en"">this is the footnote</link:footnote>
              </link:footnoteLink>
            </xbrl>";

            if( System.Environment.OSVersion.Platform.ToString() == "128")
            {
                expectedXml = expectedXml.Replace( "\r\n", "\n");
            }
            Assert.AreEqual( expectedXml, xml.ToString() );
        }
Beispiel #4
0
        /// <summary>
        /// Reads all the footnotes defined in a parameter-supplied <see cref="XmlElement"/>.  Places those 
        /// footnotes into a returned dictionary.
        /// </summary>
        /// <param name="root"></param>
        /// <param name="footnoteLinkString"></param>
        /// <param name="AddSuffix"></param>
        /// <returns></returns>
        private Dictionary<string, List<FootnoteProperty>> ReadFootnoteDataFromDoc(XmlElement root,
			string footnoteLinkString, bool AddSuffix  )
        {
            Dictionary<string, List<FootnoteProperty>> ret = new Dictionary<string, List<FootnoteProperty>>();

            XmlNodeList linkList = root.SelectNodes(footnoteLinkString, theManager);

            //if we have multiple footnotelinks it is possible for the footnoteid
            //to repeat. as each footnotelink can have the same footnote id
            Dictionary<XmlNode, string> suffixByFootnoteLink = new Dictionary<XmlNode, string>();
            if (linkList.Count > 1 && AddSuffix )
            {
                int counter = 1;
                foreach (XmlNode fl in linkList)
                {
                    suffixByFootnoteLink[fl] =      counter.ToString().PadLeft(4,'0');
                    counter++;
                }

            }

            XmlNodeList locList = root.SelectNodes("//link:footnote", theManager);
            foreach (XmlNode footnoteNode in locList)
            {
                string footnoteId = ((XmlElement)footnoteNode).GetAttribute("xlink:label");
                if (suffixByFootnoteLink.Count > 0)
                {
                    string suffix = string.Empty;
                    if (suffixByFootnoteLink.TryGetValue(footnoteNode.ParentNode, out suffix))
                    {
                        footnoteId += suffix;
                    }
                }
                string footnoteAddress = string.Empty;
                string footnoteLang = ((XmlElement)footnoteNode).GetAttribute("xml:lang");

                string footnoteData = ( (XmlElement)footnoteNode ).InnerXml;
                FootnoteProperty fp = new FootnoteProperty(footnoteId, footnoteAddress, footnoteLang, footnoteData);
                fnProperties.Add(footnoteId, fp);
            }

            locList = root.SelectNodes( footnoteLinkString  + "/link:loc", theManager);

            Dictionary<string, List<string>> labeltoElementIdMapDt = new Dictionary<string, List<string>>();
            foreach (XmlNode loc in locList)
            {
                string id = ((XmlElement)loc).GetAttribute("xlink:href");
                string[] idParts = id.Split('#');
                if (idParts != null && idParts.Length > 1)
                {
                    id = idParts[1];
                }
                string label = ((XmlElement)loc).GetAttribute("xlink:label");
                if (suffixByFootnoteLink.Count > 0)
                {
                    string suffix = string.Empty;
                    if (suffixByFootnoteLink.TryGetValue(loc.ParentNode, out suffix))
                    {
                        label += suffix;
                    }
                }
                List<string> data;
                if (!labeltoElementIdMapDt.TryGetValue(label, out data))
                {
                    data = new List<string>();
                    labeltoElementIdMapDt[label] = data;
                }
                data.Add(id);

            }

            locList = root.SelectNodes("//link:footnoteArc", theManager);
            foreach (XmlNode arcs in locList)
            {
                string from = ((XmlElement)arcs).GetAttribute("xlink:from");
                if (suffixByFootnoteLink.Count > 0)
                {
                    string suffix = string.Empty;
                    if (suffixByFootnoteLink.TryGetValue(arcs.ParentNode, out suffix))
                    {
                        from += suffix;
                    }
                }
                string to = ((XmlElement)arcs).GetAttribute("xlink:to");
                if (suffixByFootnoteLink.Count > 0)
                {
                    string suffix = string.Empty;
                    if (suffixByFootnoteLink.TryGetValue(arcs.ParentNode, out suffix))
                    {
                        to += suffix;
                    }
                }
                FootnoteProperty fp = fnProperties[to] as FootnoteProperty;
                if (fp == null) continue;
                List<string> data;
                if (labeltoElementIdMapDt.TryGetValue(from, out data))
                {

                    foreach (string id in data)
                    {

                        List<FootnoteProperty> fpsById;
                        if (!ret.TryGetValue(id, out fpsById))
                        {
                            fpsById = new List<FootnoteProperty>();
                            ret[id] = fpsById;
                        }
                        fpsById.Add(fp);

                    }
                }
            }

            return ret;
        }