Hello together,
i have a problem with parsing a xml-file and perhaps someone know's my fault and has time to answer.
hint: the xml-file-content is just as smal for demonstration my problem.
I have a xml-file with the following content:
<TEST LONG-NAME="this / that">my inner text</TEST>
If i read in this file with the code as follows, the value of the attribute "LONG-NAME" is: this/ that My code:
import std/[xmlparser,xmltree]
var rn = loadXml("in.xml")
writeFile("out.xml", $rn)
My code writes the file, and the value of "LONG-NAME" is as i said above: the "space" before the "slash" is missing. I found out, this happens during "loadXml" and has nothing to do with the "write"-part.
I have a big file with many of those values with an "space" followed by a "slash".
What i'm doing wrong?
Can anyone help me please?
Bests Beckx
std/xmlparser doesn't seem to preserve whitespace.
Maybe try lowlevel std/parsexml or one of these:
https://nimpkgs.dayl.in/#/pkg/xml https://nimpkgs.dayl.in/#/pkg/tagger https://nimpkgs.dayl.in/#/pkg/expat
Good morning,
thx for your time and answers! Good to know, the mistake sit's not in front of my monitor in this case... Seems i am using the xml-modules correct :)
I will now contact the "producer" of the big xml-files to clarify this topic.
Thx and have a nice day
Beckx
I don't think it does. According to the spec an attribute value is CDATA by default, which means all internal white space should be normalized to a single space character, not removed. xmllint preserves both spaces:
$ echo '<TEST LONG-NAME="this / that">my inner text</TEST>' >test.xml
$ xmllint test.xml
<?xml version="1.0"?>
<TEST LONG-NAME="this / that">my inner text</TEST>