<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Writting nan with capital letters in XML files]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">I am using QXmlStreamWritter to produce XML files containing my technical content. To do, so, I have "writters" as follows:</p>
<pre><code>    /**
     * @brief Write double value to XML stream as element
     * @param stream: XML stream
     * @param elementName: element name
     * @param value: value
     */
    static void writeDoubleToXMLElement(QXmlStreamWriter &amp; stream, const QString &amp; elementName, const double value) {
        stream.writeTextElement(elementName, QString::number(value, 'g', 10));
    }
</code></pre>
<p dir="auto">It works well and write "nan" if value is not a number. However, when using QXmlSchemaValidator, it think it expects "NaN" with capital letters (it fails with "nan")... I could test values and write "NaN" by my own but I would like to know if it is something configurable to avoid having to update all my "writers" functions.</p>
<p dir="auto">Thanks is advance.</p>
]]></description><link>https://forum.qt.io/topic/140374/writting-nan-with-capital-letters-in-xml-files</link><generator>RSS for Node</generator><lastBuildDate>Sat, 19 Sep 2026 21:04:13 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/140374.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 27 Oct 2022 20:59:09 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Writting nan with capital letters in XML files on Fri, 28 Oct 2022 07:08:06 GMT]]></title><description><![CDATA[<blockquote>
<p dir="auto">NaN seems to be defined in the XSD standard:</p>
</blockquote>
<p dir="auto">Yeah, understood.  Its just that <code>QXmlStreamWriter::writeTextElement()</code> only knows about text (not floats), while <code>QString::number()</code> knows nothing about XML.</p>
<p dir="auto">What you really want, is something like this:</p>
<pre><code>QString xsdNumber(const double number, const char format, const int precision)
{
    if (qIsInf(number)) {
        return (number &lt; 0) ? QStringLiteral("-INF") : QStringLiteral("INF");
    }

    if (qIsNaN(number)) return QStringLiteral("NaN");

    return QString::number(number, format, precision);
}

static void writeDoubleToXMLElement(QXmlStreamWriter &amp; stream, const QString &amp; elementName, const double value) {
        stream.writeTextElement(elementName, xsdNumber(value, 'g', 10));
}
</code></pre>
<p dir="auto">Note, I considered templating <code>xsdNumber()</code>'s <code>number</code> type so you could use <code>float</code>, <code>double</code> or <code>long double</code>, but since <code>QString::number()</code> only supports <code>double</code> (and integers), there's currently no value in adding that complexity.</p>
<p dir="auto">Cheers.</p>
]]></description><link>https://forum.qt.io/post/734357</link><guid isPermaLink="true">https://forum.qt.io/post/734357</guid><dc:creator><![CDATA[Paul Colby]]></dc:creator><pubDate>Fri, 28 Oct 2022 07:08:06 GMT</pubDate></item><item><title><![CDATA[Reply to Writting nan with capital letters in XML files on Fri, 28 Oct 2022 06:01:41 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for your quick answers.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/chrisw67">@<bdi>ChrisW67</bdi></a> - NaN seems to be defined in the XSD standard:<br />
<em>The ·lexical space· of double is the set of all decimal numerals with or without a decimal point, numerals in scientific (exponential) notation, and the ·literals· 'INF', '+INF', '-INF', and 'NaN'</em><br />
In <a href="https://www.w3.org/TR/xmlschema11-2/" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.w3.org/TR/xmlschema11-2/</a>.<br />
I wanted to benefit from that.</p>
<p dir="auto">Ok, I will check this case by hand!</p>
]]></description><link>https://forum.qt.io/post/734352</link><guid isPermaLink="true">https://forum.qt.io/post/734352</guid><dc:creator><![CDATA[Julieng031]]></dc:creator><pubDate>Fri, 28 Oct 2022 06:01:41 GMT</pubDate></item><item><title><![CDATA[Reply to Writting nan with capital letters in XML files on Thu, 27 Oct 2022 22:54:19 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/user/julieng031">@<bdi>Julieng031</bdi></a>,</p>
<p dir="auto">As <a class="plugin-mentions-user plugin-mentions-a" href="/user/chrisw67">@<bdi>ChrisW67</bdi></a> said, the <code>nan</code> is hard-coded. For example, you can <a href="https://github.com/qt/qtbase/blob/6.4.0/src/corelib/text/qlocale_tools.cpp#L71" target="_blank" rel="noopener noreferrer nofollow ugc">see it in Qt 6.4 here</a>:</p>
<pre><code>    } else if (qt_is_nan(d)) {
        if (bufSize &gt;= 3) {
            buf[0] = 'n';
            buf[1] = 'a';
            buf[2] = 'n';
            length = 3;
    } ...
</code></pre>
<p dir="auto">Assuming you cannot adjust the XML schema (maybe its provided by someone else?), you could simply handle NaN's manually, like:</p>
<pre><code>stream.writeTextElement(elementName,
    qIsNan(value) ? QString("NaN") : QString::number(value, 'g', 10));
</code></pre>
<p dir="auto">Cheers.</p>
]]></description><link>https://forum.qt.io/post/734338</link><guid isPermaLink="true">https://forum.qt.io/post/734338</guid><dc:creator><![CDATA[Paul Colby]]></dc:creator><pubDate>Thu, 27 Oct 2022 22:54:19 GMT</pubDate></item><item><title><![CDATA[Reply to Writting nan with capital letters in XML files on Thu, 27 Oct 2022 21:39:46 GMT]]></title><description><![CDATA[<p dir="auto">QString::number() is not configurable in the way you seek: "nan" is hard-coded.  It seems that if the format is specified entirely in upper-case then the output will be upper-case.  Not clear if this applies to "nan".</p>
<p dir="auto">QXmlSchemaValidator checks your XML against the schema you provide.  It is this schema that is rejecting "nan" in whatever element you have written it.   Are you sure the schema will accept any non-number in that element?</p>
]]></description><link>https://forum.qt.io/post/734333</link><guid isPermaLink="true">https://forum.qt.io/post/734333</guid><dc:creator><![CDATA[ChrisW67]]></dc:creator><pubDate>Thu, 27 Oct 2022 21:39:46 GMT</pubDate></item></channel></rss>