dgm9704 / Xoxo

read, write, compare, convert XBRL reports
GNU Lesser General Public License v3.0
27 stars 9 forks source link

[Question] how to add an explicit member with namespace specified #70

Closed ma3yta closed 4 years ago

ma3yta commented 4 years ago

My Code:

var instance = new Instance();
instance.CheckExplicitMemberDomainExists = true;
instance.AddDomainNamespace("h04", "http://sbr.gov.au/dims/RprtPyType.02.00.dims");
var entity = new Entity("http://www.ato.gov.au/abn", "18641935846");
entity.AddExplicitMember("h04:ReportPartyTypeDimension", "ReportingParty");

var ctx = new Diwen.Xbrl.Context
{
   Entity = entity,
   Id = "C001"
};

instance.Contexts.Add(ctx);

try
{
  var xml = instance.ToXml();
  Console.WriteLine(xml);
}
catch (Exception ex)
{
  Console.WriteLine(ex);
}

Actual Result: <xbrldi:explicitMember dimension=":ReportPartyTypeDimension">ReportingParty</xbrldi:explicitMember>

<?xml version="1.0" encoding="UTF-8"?>
<?instance-generator id="Diwen.Xbrl" version="1.0.4.0" creationdate="2020-08-31T17:47:05:26+07:00"?>
<xbrli:xbrl xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:link="http://www.xbrl.org/2003/linkbase" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xbrldi="http://xbrl.org/2006/xbrldi" xmlns:xbrli="http://www.xbrl.org/2003/instance">
    <link:schemaRef/>
    <xbrli:context id="C001">
        <xbrli:entity>
            <xbrli:identifier scheme="http://www.ato.gov.au/abn">18641935846</xbrli:identifier>
            <xbrli:segment>
                <xbrldi:explicitMember dimension=":ReportPartyTypeDimension">ReportingParty</xbrldi:explicitMember>
            </xbrli:segment>
        </xbrli:entity>
        <xbrli:period/>
    </xbrli:context>
</xbrli:xbrl>

Expected Result:

<xbrldi:explicitMember dimension="h04:ReportPartyTypeDimension">h04:ReportingParty</xbrldi:explicitMember>

<?xml version="1.0" encoding="UTF-8"?>
<?instance-generator id="Diwen.Xbrl" version="1.0.4.0" creationdate="2020-08-31T17:47:05:26+07:00"?>
<xbrli:xbrl xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:link="http://www.xbrl.org/2003/linkbase" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xbrldi="http://xbrl.org/2006/xbrldi" xmlns:xbrli="http://www.xbrl.org/2003/instance">
    <link:schemaRef/>
    <xbrli:context id="C001">
        <xbrli:entity>
            <xbrli:identifier scheme="http://www.ato.gov.au/abn">18641935846</xbrli:identifier>
            <xbrli:segment>
                <xbrldi:explicitMember dimension="h04:ReportPartyTypeDimension">h04:ReportingParty</xbrldi:explicitMember>
            </xbrli:segment>
        </xbrli:entity>
        <xbrli:period/>
    </xbrli:context>
</xbrli:xbrl>
dgm9704 commented 4 years ago

Hi, I will take a look and get back to you.

dgm9704 commented 4 years ago

I'm just back from vacation and my brain isn't yet in full XBRL mode so this might take some time :( Meanwhile if you already haven't done so, you could maybe take a look at the sample code in SBRInstanceTests.cs and see if that gives some ideas?

ma3yta commented 4 years ago

@dgm9704 resolved. thanks

var entity = new Entity("http://www.ato.gov.au/abn", "18641935846");
            instance.SetDimensionNamespace("h04", "http://sbr.gov.au/dims/RprtPyType.02.00.dims");
            var segment = new Segment(instance);
            segment.AddExplicitMember("ReportPartyTypeDimension", "h04:ReportingParty");
            entity.Segment = segment;
dgm9704 commented 4 years ago

Yes, I think the problem is that because my code is a bit stupid, the instance reference needs to be set before adding the member, otherwise the member doesn't have access to the namespaces, and they don't get set afterwards. This is not intuitive behaviour and it isn't mentioned anywhere. I apologize for this and will try to either fix this in the future, or at least make it obvious that things need to be done in a certain order (which is always bad imho) I am glad that you got it working though, nice job!

ma3yta commented 4 years ago

thank you for making this repo public.