这既是一个XML问题,也是一个Qt问题:为什么下面对foo元素的attr属性的名称空间uri的测试失败?
{
const QString test("<foo xmlns='http://example.org/ns' attr='value'><empty/></foo>");
QXmlStreamReader r(test);
QVERIFY(r.namespaceProcessing());
QVERIFY(r.readNextStartElement());
QCOMPARE(r.name().toString(), QLatin1String("foo"));
QCOMPARE(r.namespaceUri().toString(),
QLatin1String("http://example.org/ns"));
QVERIFY(!r.attributes().isEmpty());
QCOMPARE(r.attributes().front().name().toString(),
QLatin1String("attr"));
// FAIL, namespaceUri() is empty:
QCOMPARE(r.attributes().front().namespaceUri().toString(),
QLatin1String("http://example.org/ns"));
}这是QXmlStreamReader的错误吗?或者XML属性通常不在用xmlns声明的名称空间中
发布于 2017-09-05 23:55:19
XML属性不在用xmlns声明的命名空间中。
有相同的问题,并在specification of namespaces in XML中找到了答案
默认名称空间声明适用于其作用域内所有无前缀的元素名称。默认命名空间声明不直接应用于属性名称;无前缀属性的解释由它们出现的元素决定。
https://stackoverflow.com/questions/11138009
复制相似问题