我正在尝试从 OData API 解析此 XML 文件以复制数据模型。我收到一条错误消息说
无法加载元数据
有很多包,可能有冲突——下面列出了我安装的所有包。路径对 XML 是正确的,它是有效的。
using System;
using System.Xml; // Add this using statement for XmlReader
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Csdl;
using Microsoft.OData.Edm.Validation;
class Program
{
static void Main()
{
// Load metadata XML file
string xmlFilePath = "./response.xml" ; // Update with your actual file path
string xmlContent = System.IO.File.ReadAllText(xmlFilePath);
// Parse metadata XML and get EdmModel
IEdmModel edmModel;
using (var reader = XmlReader.Create(new System.IO.StringReader(xmlContent)))
{
IEnumerable<EdmError> errors;
if (CsdlReader.TryParse(reader, out edmModel, out errors))
{
if (!errors.Any())
{
Console.WriteLine("Metadata loaded successfully.");
}
else
{
Console.WriteLine("Metadata loaded with errors:");
foreach (var error in errors)
{
Console.WriteLine($" {error}");
}
}
}
else
{
Console.WriteLine("Failed to load metadata.");
}
}
// Replicate data model from EdmModel
// You can implement your own logic here to replicate the data model based on the parsed EdmModel
// For example, you can access the EdmModel to get entity types, properties, and relationships, and use them to generate corresponding classes or data models in your application
// You can use the EdmModel to build and execute OData queries and requests, or to implement OData services
}
}
这是我为此安装的软件包。
Top-level Package Requested Resolved
* Microsoft.AspNetCore.OData 8.1.1 8.1.1
* Microsoft.OData.Core 7.15.0 7.15.0
* Microsoft.OData.Edm 7.15.0 7.15.0
* Microsoft.OData.ModelBuilder 1.0.9 1.0.9
* Microsoft.Spatial 7.15.0 7.15.0
路径正确,XML 有效,OData 和.NET Core 中有大量的包。也许一个是错的?