如何处理多个xml标准? [英] How to deal with multiple xml standards?

查看:31
本文介绍了如何处理多个xml标准?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一组本地包装类写入我们的机构 API(我在二级机构工作).这些类的目的是安全地从远程服务中提取副本,并允许我们的程序员从该服务的工作方式中抽象出来.服务的运作方式是保密的,但我也需要回答的问题是:

I am attempting to write a local set of wrapper classes into our institution API (I work at a post secondary institution). The purpose of these classes are to securely pull transcripts from a remote service, and to allow the abstraction away from how that service works to our programmers. How the service works is confidential however the question I need an answer too is this:

当每个成绩单回复以不同的 xml 格式出现时如何处理这个问题,具体取决于它来自哪所学校.有 30 多个.

例如:机构 A 在靠近根的文档顶部有一个标签,学生的 GPA 为 |GPA|4.0|/GPA|而另一个机构可能将它放在 XML 的完全不同的部分,靠近底部,可能有 3 个孩子的深度,并命名标签 |GradePointAverage|4.0|/GradePointAverage|(假装 | 是 xml 尖括号)

As an example: Institution A has the tag, at the top of the document near the root, for GPA of a student to be |GPA|4.0|/GPA| whereas another institution might have it in a completely different part of the XML, near the bottom and perhaps 3 children deep, and name the tag |GradePointAverage|4.0|/GradePointAverage| (Pretend | is xml angle brackets)

对于如何处理这种缺乏标准化的问题有什么建议吗?

Any suggestions how to deal with this lack of standardization?

推荐答案

听起来您的目标应该是一个通用数据模型,然后是 30 个能够从 XML 反序列化到该数据模型的不同类.根据它们的不同之处, 可能存在重用的重要方面,您甚至可以参数化一些差异.使用 LINQ to XML 可以相当容易地解析任何一种格式.

It sounds like you should aim for one common data model, and then 30 different classes which are able to deserialize from XML to that data model. Depending on exactly how different they are, there may be significant aspects of reuse, and you may even be able to parameterize some differences. Using LINQ to XML makes it reasonably easy to parse any one format.

我的目标是大量简单的代码,而不是少量的聪明"代码:解析每个单独的格式应该相当简单,并且希望易于测试.是的,编写此代码会很乏味,但最终应该很容易理解,并且如果需要,可以轻松添加更多格式.

I would aim for lots of simple code rather than a small amount of "clever" code: parsing each individual format should be reasonably straightforward, and hopefully easy to test. Yes, it'll be tedious to write this code, but it should end up being easy to follow, and easy to add more formats if you need to.

当然,您可以使用 XSLT 将转换为单一格式,但我个人更愿意编写 C# :)

You could use XSLT to perform a transformation into a single format of course, but personally I'd rather write C# :)

这假设您可以创建一个通用数据模型 - 如果格式非常不同,您可能会发现如果没有可怕的最低通用数据,您就无法准确表示每个文件中的数据-分母.想出一个好的数据模型可能和编写每个单独的解析器一样困难.

This assumes you can create a common data model - if the formats are very different, you may find that you can't accurately represent the data in each file without having a horrible lowest-common-denominator. Coming up with a good data model is likely to be as hard as writing each individual parser.

这篇关于如何处理多个xml标准?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆