【发布时间】:2021-10-30 14:37:37
【问题描述】:
我正在尝试将 XML 文件读入 Apache Beam 管道。一些元素具有命名空间,命名空间声明在根节点处声明。我能够使用标准 JAXB 解析器在 Apache Beam 之外解析 xml。但是,当我将 XmlIO.read() 函数与梁一起使用时,会出现以下异常:
com.ctc.wstx.exc.WstxParsingException:未声明的命名空间前缀“g”。
<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">
<channel>
<item>
<!-- Basic Product Information -->
<g:id><![CDATA[SAMI9000NAVKIT]]></g:id>
<title><![CDATA[Original Samsung Galaxy S i9000 Navigation Kit]]></title>
<link><![CDATA[https://www.mobileciti.com.au/original-samsung-galaxy-s-i9000-navigation-kit]]></link>
<description><![CDATA[<p>SAMSUNG Galaxy S (i9000) Navigation Kit - Consists of handset cradle, window shield mount and car charger.</p>]]></description>
<g:product_category><![CDATA[Electronics > Communications > Telephony > Mobile Phone Accessories]]></g:product_category>
<g:product_type><![CDATA[Accessories > Car Kits]]></g:product_type>
....
</item>
</channel>
</rss>
束码:
.from(<Full file path>)
.withRootElement("rss")
.withRecordElement("item").withRecordClass(Item.class));
没有命名空间的 XML 可以正常工作。任何指针都非常感谢。谢谢
【问题讨论】:
标签: java xml namespaces apache-beam