问题描述
所以我试图在 VB6 中使用 SAX 解析来编辑一个 xml(输出是一个 xml)(对于一个古老的 COM 组件).我更喜欢使用 DOM 解析,但 xml 的大小(可能超过 20MB)迫使我使用 SAX.我对 VB6 比较陌生,我没有 SAX 解析经验.我在网上环顾四周,但即使是我找到的最好的资源 (http://www.developerfusion.com/article/84405/sax-and-vb-6/) 也让我对如何将 Grandchilren 标签与现有属性结合起来知之甚少为重命名的标签制作一个更长的属性.
So I am trying to edit an xml (output is an xml) using SAX parsing in VB6 (for an ancient COM component). I would prefer to use DOM parsing but the size of the xml (over 20MB's potentially) forces me to use SAX. I am relatively new to VB6 and I have no experience in SAX parsing. I have looked around online but even the best resource I have found (http://www.developerfusion.com/article/84405/sax-and-vb-6/) gives me little insight into how to combine grandchilren tags with existing attributes to make one longer attribute for a renamed tag.
我有基本的框架设置(如链接站点所示).我想我可以将大部分繁重的工作限制在两个或三个子过程中(_startDocument 中的前四行,使用 _startElement 获取描述标签,使用 endElement 将描述放入函数标签中).然而,我缺乏 VB6/SAX 知识真的让我很受伤.任何帮助将不胜感激.
I have the basic framework setup (as shown on the linked site). I think I might be able to limit most of the heavy lifting to two or three sub procedures (the first four lines in _startDocument, grab the description tag with _startElement, put the description into the function tag with endElement). However my lack of VB6/SAX knowledge is really hurting me here. Any help would be greatly appreciated.
这是现在的 XML 样子;
Here is what the XML looks like Now;
<errordetails>
<error desc="Count: 2"/>
<error desc="System: System X"/>
<error desc="Reason: Reason X"/>
<functions>
<function name="x1" Description="y1">
<violations count="2">
<violation><source>admin</source><description>the first reason</description></violation>
<violation><source>admin</source><description>the second reason</description></violation>
</violations>
</function>
<function name="x2" Description="y2">
<violations count="1">
<violation><source>admin</source><description>another reason</description></violation>
</violations>
</function>
</functions>
</errordetails>
这是我想要的 xml 的样子;
Here is what I want the xml to look like;
<errordetails>
<error desc="Count: 2"/>
<error desc="System: System X"/>
<error desc="Reason: Reason X"/>
<error desc="FunctionName: x1, FunctionDescription: y1, FunctionReason: the first reason, FunctionReason: the second reason"/>
<error desc="FunctionName: x2, FunctionDescription: y2, FunctionReason: another reason"/>
</errordetails>
推荐答案
您是否阅读过类似旧文章 SAX 的乐趣:Visual Basic 示例?
Have you read things like the old article The Joy of SAX: a Visual Basic Sample?
很难告诉你更多.SAX 实际上非常简单,您只需要像对待任何 VB6 表单一样将其作为状态机来处理即可.这意味着您将编写的大部分逻辑都将管理状态,例如在通过事件提供给您时累积和发出转换后的数据.
It is hard to tell you much more. SAX is pretty simple really, you just need to approach it much as you should any VB6 Form, as a state machine. This means most of the logic you'll write will manage state, like accumulating and emitting transformed data as it is fed to you through the events.
这篇关于在VB6中使用Sax解析编辑和编写XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!