我们正在使用 SAX 解析器解析 XML 文件。是否可以从 XML 中获取架构位置?
<view id="..." title="..."
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="{schema}">
我想从 XML 中检索 {schema}
值。这可能吗?如何访问 noNamespaceSchemaLocation
的这个值?我正在使用默认的 SAX 解析器。
@Override
public void startElement(String uri, String localName,
String name, Attributes attributes)
{ .... }
谢谢。
最佳答案
这完全取决于您正在使用的工具/库类型(基本的 SAXParser?Xerces?JDom?...)但是您想要的是由 URI“http://www.w3.org/2001/XMLSchema-instance”定义的命名空间中属性“noNamespaceSchemaLocation”的值
在 JDom 中,它会是这样的:
Element view = ...; // get the view element
String value = view.getAttributeValue("noNamespaceSchemaLocation", Namespace.getNamespace("http://www.w3.org/2001/XMLSchema-instance"));
关于java - 从 XML 文件获取架构位置 (noNamespaceSchemaLocation),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9483034/