简体   繁体   English

使用SAX解析器解析具有多个XML标签的XML文件

[英]Parse XML file with multiple XML tags using SAX parser

I am trying to parse a XML file with multiple XML declarations. 我试图解析具有多个XML声明的XML文件。

<?xml version="1.0"?>
<Details xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://www.example.com/KDD/ID/1">

and I'm getting the following exception 我收到以下异常

the processing target matching  "[xX][mM][lL]" is not allowed

My parser works perfectly if there is a single xml declaration. 如果只有一个xml声明,我的解析器就可以完美地工作。 The XML file is very large and I cannot possibly go and remove all the tags. XML文件非常大,我无法去掉所有标签。 Is there any way to do this 有什么办法做到这一点

A well-formed XML Document may have only one XML Declaration and one Root Element. 格式正确的XML文档可能只有一个XML声明和一个根元素。

A well-formed XML External Parsed Entity may have more than one root note, but still may have only one XML Declaration. 格式正确的XML外部解析实体可能有多个根注释,但仍然可能只有一个XML声明。

If you want this to parse, you're going to have to preprocess your input -- break it up into separate documents, or remove the extra XML Declaration -- or fix whatever's generating the document in the first place so it produces correct XML, which is in the long run the better answer. 如果您要对此进行解析,则必须预处理输入-将其分解为单独的文档,或删除多余的XML声明-或首先修复生成文档的所有内容,以生成正确的XML,从长远来看,这是更好的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM