【问题标题】:QXmlStreamReader and empty namespaceUri() on attributes属性上的 QXmlStreamReader 和空 namespaceUri()
【发布时间】:2012-06-21 12:20:27
【问题描述】:

这既是一个 Qt 问题,也是一个 XML 问题:为什么以下对 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 声明的命名空间中?

【问题讨论】:

    标签: xml qt xml-namespaces qxmlstreamreader


    【解决方案1】:

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

    有同样的问题,在specification of namespaces in XML找到答案:

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

    【讨论】:

      猜你喜欢
      • 2016-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-16
      • 1970-01-01
      • 2014-06-30
      相关资源
      最近更新 更多