如何从访问VBA中的XML文件中读取注释 [英] How to read comment from an XML file in access VBA

查看:138
本文介绍了如何从访问VBA中的XML文件中读取注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我必须使用ms访问VBA将数据从xml文件存储在sql server中。这部分很简单。我被困的地方是我必须在db中输入的值之一是在xml文件中的注释中我不知道如何阅读注释。

我用谷歌搜索我所能得到的一切找到c#或java中的例子。



 <! -    状态10-04-2015 10:19    - >   
< 修复 > < span class =code-keyword>< ref > 111111 < / ref >
< span class =code-keyword>< repair_number1 > 1234445 < / repair_number1 >
< span class =code-keyword>< repair_number2 > xx x011 < / repair_number2 >
< status_code > X.2 < / status_code >
< status_description > X.2:xxxxxxxxxxxxxxxxxxxx < / status_description > ;
< / repair >
< / repair_status >





辩诉请告诉我如何在xml文件的评论中阅读日期时间



我尝试过:



我没有什么可以尝试的,因为我无法在Google上找到任何来源,我可以从中获取一些灵感

解决方案

< blockquote>不幸的是,我还面临着读取和容纳XML中的注释数据的要求。这是一个非常讨厌的做法,应该通过各种手段消除。那时候,我设法反击并拒绝了这些要求。



但是,如果你不幸地无法避免这种工作该怎么办?



使用古老的MSXML解析VBA(为什么?为什么?!为什么不是VB.NET?)的方法之一就是使用它的SAX2。如您所见,此方法可以为您提取注释: XML的简单API - 维基百科,免费的百科全书 [ ^ ]。



请从这里开始:

MSXML [ ^ ],

SAX2 [ ^ ],

https://msdn.microsoft.com/en-us/library/ms757033%28v=vs.85%29.aspx [ ^ ],

< a href =https://msdn.microsoft.com/en-us/library/ms759197%28v=vs.85%29.aspx>创建简单过滤器 [ ^ ]。



这个想法是:SAX提供了一个非常有效的仅向前界面来解析从头到尾的整个事物。在路上,你可以收集一些元素而忽略其他元素;你可以找出每个元素和其他标准的当前上下文,并决定是否需要它,如果你这样做,将所需数据添加到某个内部集合



在通常的实践中,comment是要始终被忽略的元素类型之一。希望你也一样。但正如您所看到的,可以为您保留此信息。 :-)



我很高兴Richard Deeming对我以前的解决方案发表评论。我为.NET编写了一个解决方案,但他指出了我的错误并建议寻找MSXML,提供适当的链接。



-SA

Hello,
I have to store data from xml file in sql server using ms access VBA. This part is simple. Where i am getting stuck is that one of the values that i have to enter in db is in comment in xml file an i don't know how to read the comment.
I googled and all i could find there is examples in c# or java.

<!--  status 10-04-2015 10:19 -->
<repair><ref>111111</ref>
<repair_number1>1234445</repair_number1>
<repair_number2>xxx011</repair_number2>
<status_code>X.2</status_code>
<status_description>X.2 : xxxxxxxxxxxxxxxxxxxx</status_description>
</repair>
</repair_status>



Please tell me how will i read the date-time in the comments in xml file

What I have tried:

there is nothing that i could try as i couldn't find any source on Google from where i could take some inspiration

解决方案

Unfortunately, I also faced the requirement to read and accommodate comment data in XML. This is a really nasty practice which should be eliminated by all means. At that time, I managed to fight back and deny such requirements.

But what to do if you, unfortunately, cannot avoid this kind of work?

One of the ways to parse with VBA (why? why?! why not VB.NET?) with ancient MSXML would be using its SAX2. As you can see, this approach can extract comments for you: Simple API for XML — Wikipedia, the free encyclopedia[^].

Please start here:
MSXML[^],
SAX2[^],
https://msdn.microsoft.com/en-us/library/ms757033%28v=vs.85%29.aspx[^],
Create a Simple Filter[^].

The idea is: SAX provides a very efficient forward-only interface to parse the whole thing from the beginning to the end. In the road, you can collect some elements and ignore other; you can figure out current context of each element and other criteria, and decide if you need it, if if you do, add required data to some internal collection.

In normal practice, comment is one of the element types to be always ignored. Wish you the same. But as you can see, this information can be preserved for you. :-)

I gladly credit Richard Deeming for his comment on my previous solution. I wrote a solution for .NET, but he pointed out my mistake and suggested to look for MSXML, provided appropriate link.

—SA


这篇关于如何从访问VBA中的XML文件中读取注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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