将 XML 转换为 protobuf
我正在编写一个 java 应用程序,它将模式限制的 XML 作为输入,并需要将其转换为 protbuf。无需进行任何处理;我只需要从 XML 中获取一些字段并使用它们来创建 protobuf。
我希望我可以使用 JIBX 将 XML 直接映射到我的 protobuf 的 Builder 类,从而消除任何中间工作。然而,JIBX 要求正在构建的对象的设置方法返回 void (http://jibx.sourceforge.net/details/binding-attributes.html)。 Protobuf 生成的 Builder 类遵循构建器设计模式,并且不会从其 setter 方法返回 void。
有没有办法绕过这个问题,让 JIBX 直接将 XML 转换为 protobuf 类?也许我应该考虑使用另一种 XML 解析工具*?或者我是否必须编写一些中间代码来促进 XML 和 protobuf 之间的转换?
*注意:我收到的输入 XML 非常大,我只需要其中的少数字段。这使得我无法使用一些较重的 XML 解析工具。
I am writing a java application that takes schema-bounded XML as input and needs to translate it to a protbuf. There is no processing needed to be done; I simply need to grab a few fields from the XML and use them to create a protobuf.
I was hoping I could use JIBX to directly map the XML to my protobuf's Builder class, thus eliminating any middle work. However, JIBX requires the set-methods of the object being built to return void (http://jibx.sourceforge.net/details/binding-attributes.html). Protobuf's generated Builder class follows the builder design pattern and does not return void from its setter method.
Is there anyway to circumvent this issue and have JIBX directly translate XML to a protobuf class? Perhaps there is another XML parsing tool* I should look into using? Or will I have to write some intermediate code to facilitate the translation between XML and protobuf?
*note: the input XML I am receiving is extremely large, and I only need a handful of fields from it. This discounts some of the heavier XML parsing tools from my use.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终对输入 xml 执行 XSL 转换,并通过(小型)自定义 SAX 解析器提供输出以创建 protobuf。感谢您的帮助!
I ended up performing an XSL Transformation on the input xml and fed the output through a (small) custom SAX Parser to create the protobuf. Thanks for the help!