473,698 Members | 2,218 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

need help in writing xml document.


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.

Jul 12 '06 #1
3 1311

Moqtar wrote:
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.
You need to replace any & characters with &amp;

name = "LetterSize B&W"
name = name.replace("& ", "&amp;")

HTH

Jul 12 '06 #2

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:
&amp; - 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&amp;W</dirname>
or
<dirname>C:\Pro gram Files\LetterSiz e B&W</dirname>
Unicode charts:
http://www.unicode.org/charts/

Jul 12 '06 #3

Moqtar wrote:
I am using python to walk a directory and write the filename in an xml
document of type
Don't write XML documents. Use a DOM to do it for you.

If you think it's bad now with a trivial problem over &amp;, then just
wait until you have to port your app simultaneously to Czech and Arabic
within a week and you have a load of character set encoding issues to
worry about. The DOM saves you from all this - make use of it.

Jul 12 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2572
by: david farning | last post by:
I am doing my first work in python/xml Is is possiable to write a xmlTree in a single command? for example doc = libxml2.parseFile (filename) # add node to doc doc.write(filename) ??????????????
12
2139
by: Christoph Bergmann | last post by:
Hi... We want to write an open source web based TEXT editor and would be happy about any help ;-) Please notice: We do NOT want to write a web based WEB editor, where you can edit a web page without knowing HTML - we want to write a real programmer's editor located on a web page in your browser with features like...
8
4227
by: Johnny Knoxville | last post by:
I've added a favicon to my site (http://lazyape.filetap.com/) which works fine if you add the site to favourites the normal way, but I have some JavaScript code on a couple of pages with a link, which when you click it bookmarks the site (much easier). The favicon is never saved if the site is bookmarked this way. Does anyone have any ideas how to fix this?? This is the code: <script language="JavaScript">
3
4706
by: Dante | last post by:
Tonight I started writing a script that places a "Copy All" link before every PRE tag. The link would copy the code in the pre tag. I can't get this script to work. Can anyone help me? Here is my script: function makeIt() { var where = document.getElementsByTagName("TABLE").childNodes.childNodes.childNodes.childNodes; var base = document.getElementsByTagName("PRE"); var link = document.createElement("SPAN"); var text =...
70
2795
by: rahul8143 | last post by:
hello, 1) First how following program get executed i mean how output is printed and also why following program gives different output in Turbo C++ compiler and Visual c++ 6 compiler? void main() { int val=5; printf("%d %d %d %d",val,--val,++val,val--); } under turbo compiler its giving
10
2830
by: Peter Michaux | last post by:
Hi, Today I have been testing the event models from Netscape 4.8 and IE 4 to the current crop of browsers. I'd like to write a small event library similar in purpose to the Yahoo! UI event library but with less features and code. The Yahoo! event library is one of the best libraries in YUI but it still seems to me to have some confused code...that or I'm still confused. The Yahoo! UI library focuses on using addEventListener and
2
1731
by: howa | last post by:
Should we add document.close after each time when we used document.write() ?
2
3153
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button then the calender gone actually i want if i click outside off the calender then it should me removed ..How kan i do this ... Pls inform me as early as possible .. I am waiting for ur quick replay ...Here i attached the source code .... <!DOCTYPE...
0
1255
by: talk2pk | last post by:
When i am writing the images to the word file(using Clipboard.SetImage) and open another word doc, the process of writing those images migrates to the new opened document. Can anybody suggest why this is happening? The requirement is to write the images in the file which i have specified.The opening of another word doc should not effect the process. Here is the code: document.Application.Selection.TypeText("\n"); ...
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9026
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8893
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
4366
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2328
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.