使用 XSLT 以外的其他解决方案解析 XML
我的公司正在开发一个项目,需要在ABAP中读取XML文件。
- 当 XML 文件没有特定标记的数据时,它会忽略该数据。
- 有些标签是自动关闭的。例如 <标签/>;
SAP 开发人员表示,要读取 XML 文档,他首先将文档解析为 ABAP XML 结构。该过程在第 2 点上失败。然后,他必须创建一个 XSLT 将该数据转换为内部数据结构,而在第 1 点上失败,因此使得该任务很难在 ABAP 中实现。
确实是这样吗?那么有没有办法读取我们需要的特定字段?
My company is working on a project that needs to read XML files within ABAP.
- When the XML file has no data for a particular tag it omits that data.
- Some tags are self closing. e.g. <tag />
The SAP developer says that to read the XML document he first parses the document into an ABAP XML structure. This process fails on point 2. He must then create an XSLT to turn that data into an internal data structure, and that fails on point 1 therefore making the task very difficult to achieve within ABAP.
Is that definitely the case and is there then no way of reading the specific fields that we need?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 ABAP 中开始进行 XML 解析的最佳位置是 SAP XML图书馆。
尝试编写自己的解析算法可以说是一个非常糟糕的主意 - 让其他人(在本例中为 SAP)为您完成艰苦的工作。
The best place to start with XML parsing in ABAP is the SAP XML Library.
It is arguably a really bad idea to try and write your own parsing algorithm - let someone else (SAP, in this case) do the hard work for you.
我建议您首先应用 XSLT 将 XML 内容转换为 ABAP 处理器能够读取的形式。还有 iXML(看看示例程序 BCCIIXML*),但使用起来相当慢且麻烦......
I'd suggest you apply the XSLT first to bring the XML content into a form the ABAP processor is able to read. There's also iXML (take a look at the sample programs BCCIIXML*), but it's rather slow and cumbersome to use...
您只需读取文件(使用开放数据集),然后使用 find 等字符串函数解析 XML。它很难看,而且可能需要很多工作,但你绝对可以做到。
You can just read the file (using open dataset) and then parse the XML using string functions like find. Its ugly and could be A LOT of work, but you can definitely do it.