gpt4 book ai didi

azure-cosmosdb - cosmosdb 的 XML 架构

转载 作者:行者123 更新时间:2023-12-05 00:14:24 27 4
gpt4 key购买 nike

我们可以在 cosmos Db 中添加 XML Schema 吗?如果是,我们如何查询它们?我可以将 XML 数据保存为字符串,但如何查询它们?

下面是我收藏的文档:

    {
"id": "4796300e-b1d3-4c60-abc3-9ac28fc87d45",
"BId": "55ce95c2-b7f6-4c9b-a288-2363881f14bb",
"SheetName": "<root><Tax_Type>tax</Tax_Type><Buildings_Limit /><Buildings_Value /><Contents_Limit /><Contents_Value /><Number_of_Stories /><Other_Limit /><Other_Value /><PremiumValue /><Roof_Geometry /><IsSoft_Story /><Sprinklers /><Tax>0</Tax><Tax_Percent>0</Tax_Percent><Year_Built /><Construction_Scheme /><Construction_Code /><Construction_Description /><Occupancy_Scheme /><Occupancy_Code /><Occupancy_Description /></root>",
"HeaderIndex": "1",
"_rid": "xxxxxxx",
"_self": "dbs/xxx==/colls/xxx=/docs/xxx==/",
"_etag": "\"xxxxx\"",
"_attachments": "attachments/",
"_ts": 1509170527
}

最佳答案

Cosmos DB(显然有 superseded Document DB)开发团队故意选择不支持 XML。他们的Schema-Agnostic Indexing Whitepaper阐明了选择背后的原因:

The schema of a document describes the structure and the type system of the document independent of the document instance.For example, the XML Schema specification provides the language for representing schemas for XML documents. Unlike XML, no such widely adopted schema standard exists for JSON. In contrast to XML, JSON’s type system is a strict subset of the type systems of many modern programming languages, most notably JavaScript. The simplicity of the JSON grammar is one the reasons for its ubiquitous adoption despite the lack of a schema specification. With a goal to eliminate the impedance mismatch between the database and the application programming models, DocumentDB exploits the simplicity of JSON and its lack of a schema specification. It makes no assumptions about the documents and allows documents within a DocumentDB collection to vary in schema, in addition to the instance specific values. In contrast to other document databases, DocumentDB’s database engine operates directly at the level of JSON grammar, remaining agnostic to the concept of a document schema

然后引擎为您提供了一堆 API 来查询您的数据:SQL , Cassandra , Mongo , Gremlin , TableEtcd (该列表将来可能会扩大)。

坏消息是您不能只是将 XML 放入其中并收工 - 没有 API 可以让您做到这一点。

好消息是您可以将 XML 转换为 JSON 并返回。一旦你得到你的 JSON,就有 heaps of client libraries可供选择(同样,该列表可能会随着时间的推移而增长)。

查找具体示例如何在 StackOverflow 上将 XML 转换为 JSON 很简单,例如:

  1. Javascript example
  2. Or C# if you feel so inclined

回到您的特定文档,您可以将字符串转换为子对象,如下所示:

{
"id": "4796300e-b1d3-4c60-abc3-9ac28fc87d45",
"BId": "55ce95c2-b7f6-4c9b-a288-2363881f14bb",
"SheetName": {
"Tax_Type": "tax",
"Buildings_Limit": {},
"Buildings_Value": {},
"Contents_Limit": {},
"Contents_Value": {},
"Number_of_Stories": {},
"Other_Limit": {},
"Other_Value": {},
"PremiumValue": {},
"Roof_Geometry": {},
"IsSoft_Story": {},
"Sprinklers": {},
"Tax": "0",
"Tax_Percent": "0",
"Year_Built": {},
"Construction_Scheme": {},
"Construction_Code": {},
"Construction_Description": {},
"Occupancy_Scheme": {},
"Occupancy_Code": {},
"Occupancy_Description": {}
},
"HeaderIndex": "1",
"_rid": "xxxxxxx",
"_self": "dbs/xxx==/colls/xxx=/docs/xxx==/",
"_etag": "\"xxxxx\"",
"_attachments": "attachments/",
"_ts": 1509170527
}

关于azure-cosmosdb - cosmosdb 的 XML 架构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46987016/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com