XmlParser和XmlSlurper名称空间是否可识别

XmlParser和XmlSlurper名称空间是否可识别

本文介绍了默认情况下,XmlParser和XmlSlurper名称空间是否可识别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当回答这个问题与名称空间(SOAP)相关的和,我实际上无法确定它们是否默认为非命名空间。



虽然 文档 默认情况下可识别的非名称空间): =http://docs.groovy-lang.org/latest/html/gapi/groovy/util/XmlSlurper.html#XmlSlurper() =nofollow noreferrer> XmlSlurper

  public XmlSlurper()throws ParserConfigurati onException,SAXException {
this(false,true);
}

  public XmlParser()抛出ParserConfigurationException,SAXException {
this(false,true);
}

我发现这也是。幸运的是另一位用户发布了PR来解决问题。有人应该加入公关解决文档问题,这也给我和其他人造成了混乱。


When answering this question How to read values from XML Request and write into XML Response using Groovy? related to namespaces (SOAP) with XmlSlurper and XmlParser, I realized that I was actually not able to tell if they are non-namespace-aware by default.

While documentation says so (non-namespace-aware by default):

XmlSlurper

XmlParser

Code is exactly the opposite (namespace-aware by default):

XmlSlurper:

public XmlSlurper() throws ParserConfigurationException, SAXException {
    this(false, true);
}

XmlParser:

public XmlParser() throws ParserConfigurationException, SAXException {
    this(false, true);
}

I found also this answer claiming that XMLSlurper is non-namespace aware by default.

解决方案

As of Groovy 2.4.6, the documentation is wrong:

/**
 * Creates a non-validating and non-namespace-aware <code>XmlSlurper</code> which does not allow DOCTYPE declarations in documents.
 *
 * @throws ParserConfigurationException if no parser which satisfies the requested configuration can be created.
 * @throws SAXException for SAX errors.
 */
public XmlSlurper() throws ParserConfigurationException, SAXException {
    this(false, true);
}

It actually creates a namespace-aware parser (second parameter true).

There is also a bug I reported where the namespace prefixes are not handled properly: https://issues.apache.org/jira/browse/GROOVY-7781. Fortunately another user issued a PR to fix. Someone should put in a PR to fix the documentation issue as well as this has caused confusion to myself and others multiple times.

这篇关于默认情况下,XmlParser和XmlSlurper名称空间是否可识别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 20:49