尝试在 xhtml 文件上使用 Sax 解析器时出错

发布于 2024-09-29 03:02:42 字数 583 浏览 0 评论 0原文

我正在尝试使用 Java 中的 SAXParser 解析 xhml 文件,但出现异常:

“java.net.MalformedURLException: 未知协议:g"

导致例外的行是:

SAXBuilder.build(Destination)

虽然 Destination 是 xhml 文件的完整路径。 xhml文件的开头如下:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="../article.css" type="text/css"?>
<div id="article" xmlns="http://www.w3.org/1999/xhtml">

其中div是根元素。

我尝试在网上查找有关协议 g 或 MalformedURLException 的文档, 我也尝试使用名称空间,但无法完成这项工作。

有谁知道我能做些什么来使这项工作成功?

谢谢

I'm trying to parse an xhml file using SAXParser in Java, but gets an exception:

"java.net.MalformedURLException:
unknown protocol: g"

The line made that exception was:

SAXBuilder.build(Destination)

While Destination is the full path to the xhml file.
The beginning of the xhml file is as followed:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="../article.css" type="text/css"?>
<div id="article" xmlns="http://www.w3.org/1999/xhtml">

While div is the root element.

I tried to look for documentation over the web about protocol g or MalformedURLException,
i tried to play with the namespaces as well, but couldn't get this work.

Does anyone have any idea what can i do to make this work?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一口甜 2024-10-06 03:02:42

(基于评论中的讨论)SAXBuilder 将“Destination”视为 URL 而不是本地文件。使用 File 对象调用“build”。

(Based on discussion in the comments) SAXBuilder is treating "Destination" as a URL and not a local file. Call "build" with a File object instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文