Moqtar napisal(a):
I am using python to walk a directory and write the filename in an xml
document of type
<?xml version="1.0" encoding="ISO-8859-1"?>
<job>
<jobname>Test </jobname>
<jobtime>200607 120616</jobtime>
<Directory>
<dirname>C:\Pro gram Files\Acorden SourceXT</dirname>
<file>
<name>readme.tx t</name>
<time>200011041 444</time>
</file></Directory>
<Directory>
<dirname>C:\Pro gram Files\Yahoo</dirname>
</Directory>
</job>
the code works. But if the directoryname of file name contains the
character "&" .
for eg. <dirname>C:\Pro gram Files\LetterSiz e B&W</dirname>
it gives an error. i cannot view the xml document.
It gives an error because & normally starts an XML entity, which must
be defined first.
XML general entity starts with & and ends with ; so You lead your xml
parser to an error starting entity and not ending it;
To use special character in XML markup (even content) you must use
"escape sequence" - and its an entity ofcourse.
So You write special entity:
& - and it means &
You can also use a unicode value for a single character. It works like
this:
- it means 160 decimal in unicode (non braking space) number is
preceded with hash symbol.
Note that 160 is in decimal but most unicode charts are in hexadecimal
- you must convert it by yourself.
<dirname>C:\Pro gram Files\LetterSiz e B&W</dirname>
should be:
<dirname>C:\Pro gram Files\LetterSiz e B&W</dirname>
or
<dirname>C:\Pro gram Files\LetterSiz e B&W</dirname>
Unicode charts:
http://www.unicode.org/charts/