是否有更好的正则表达式来解析 DTD

发布于 2024-08-08 05:02:17 字数 794 浏览 4 评论 0原文

我已经获得了 OFX 1.03 的 DTD(尽管他们已经开发并发布了 1.60,但他们的最新版本,但我离题了...)

我想使用正则表达式来将实体、元素、其他标签拆分为多个部分以进行进一步的分组处理这样我会采取这样的标签:

<!ENTITY % ACCTTOMACRO "(BANKACCTTO | CCACCTTO | INVACCTTO)">

并创建一个像这样的对象

new EntityTag { string Name = "%ACCTTOMACRO"; string[] ChildTypes = new string[] {"BANKACCTTO", "CCACCTTO", "INVACCTTO"}};

我有一个如下所示的正则表达式:

Regex re = new Regex(@"<!(\b)+([\s\S])?[^>]+>");  

诚然,我是正则表达式的新手,所以到目前为止我已经做得很好了,它为我提供了每个标签的 DTD 上的匹配集合,没有注释。

我想利用分组来促进前面提到的对象的创建。

如果我走在完全错误的道路上,请指导我,但是如果您下载了此文档,我想您可能会发现它不标准。 (Visual Studio 会根据此文档的格式设置一些危险信号)

我不希望任何人遇到麻烦,但对于好奇的人来说,这里是 链接 下载规格。

I've got the DTD for OFX 1.03 (their latest version despite having developed and released 1.60, but I digress...)

I would like to use regex to have groups that split an entity, element, other tags into its parts for further processing such that I would take a tag like this:

<!ENTITY % ACCTTOMACRO "(BANKACCTTO | CCACCTTO | INVACCTTO)">

And create an object like this

new EntityTag { string Name = "%ACCTTOMACRO"; string[] ChildTypes = new string[] {"BANKACCTTO", "CCACCTTO", "INVACCTTO"}};

I've got a regular expression that looks like this:

Regex re = new Regex(@"<!(\b)+([\s\S])?[^>]+>");  

Admittedly, I'm new to regex, so I've done good so far getting this which gives me a match collection over the DTD for each tag without comments.

I would like to leverage grouping to facilitate creation of the previously mentioned object.

If I'm on the totally wrong path, please instruct me, however if you do download this document, I think you may find its not standard. (Visual studio throws up some red flags with the way this document is formatted)

I don't expect anyone to go to the trouble, but for the curious here is the link to download the specs.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妖妓 2024-08-15 05:02:17

看起来他们也有可用的架构。为什么不下载架构并使用 XML 解析器(例如 LINQ-to-XML)解析它?

It looks like they've got schema available as well. Why not download the schema instead and parse that with an XML parser (for instance, LINQ-to-XML)?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文