postman 为输入XBRL文件创建了API,需要获取上下文列表,但得到了空数组

xu3bshqb  于 11个月前  发布在  Postman
关注(0)|答案(1)|浏览(93)

我为输入的XBRL文件创建了Web API,需要根据我将在 Postman 中放置的期间获得上下文的输出列表。但是我得到了空数组。我不明白问题在哪里。
任何建议都会有帮助。

public class Envelope
{
    public string Period { get; set; }
    public byte[] XBRLInstance { get; set; }
}

[ApiController]
[Route("api/xbrl")]
public class XBRLController : ControllerBase
{
    [HttpPost]
    [Consumes("application/json")]
    public IActionResult Post([FromBody] Envelope envelope)
    {
        // extract period and XBRLInstance from the envelope
        string period = envelope.Period;
        string xbrlInstance = Encoding.UTF8.GetString(envelope.XBRLInstance);

        // parse XBRLInstance into XDocument
        XDocument xbrlData = XDocument.Parse(xbrlInstance);

        // logic to filter XBRL data by period and return the relevant contexts
        List<string> filteredContexts = GetContextsByPeriod(xbrlData, period);

        // Return the list of contexts in the response
        return Ok(filteredContexts);
    }

    [HttpGet]
    private List<string> GetContextsByPeriod(XDocument xbrlData, string period)
    {
        XNamespace xbrli = "http://www.xbrl.org/2003/linkbase";
        //  logic to filter XBRL data by period and return the relevant contexts
        var filteredContexts = xbrlData.Descendants(xbrli + "context")
                                       .Where(context =>
                                       {
                                           // condition to filter by period
                                           string contextPeriod = context.Element(xbrli + "period").Value;
                                           return contextPeriod == period;
                                       })
                                       .Select(context => context.Attribute("id").Value)
                                       .ToList();

        return filteredContexts;
    }
}```

And in postman it looks like this
```{
 "Period": "2022-01-01/2022-12-31",
    "XBRLInstance": "PD94bWwgdm...."
}```
And I got empty array in body []

字符串

to94eoyn

to94eoyn1#

应该是:

XNamespace xbrli = "http://www.xbrl.org/2003/instance";

字符串
据我所知,你使用了错误的名称空间“http://www.xbrl.org/2003/linkbase“。

相关问题