首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >属性上的QXmlStreamReader和空namespaceUri()

属性上的QXmlStreamReader和空namespaceUri()
EN

Stack Overflow用户
提问于 2012-06-21 20:20:28
回答 1查看 512关注 0票数 1

这既是一个XML问题,也是一个Qt问题:为什么下面对foo元素的attr属性的名称空间uri的测试失败?

代码语言:javascript
复制
{
    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声明的名称空间中

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-09-05 23:55:19

XML属性不在用xmlns声明的命名空间中。

有相同的问题,并在specification of namespaces in XML中找到了答案

默认名称空间声明适用于其作用域内所有无前缀的元素名称。默认命名空间声明不直接应用于属性名称;无前缀属性的解释由它们出现的元素决定。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11138009

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档