943,832 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 462
  • Python RSS
Apr 5th, 2009
0

Python And XML

Expand Post »
Hello everyone!

I would like to read a xml file in order to return the content as a HTML response. I wonder if i need to parse the XML file or i can read the file as if it were an txt file. I am interested in this second way because i dont need to get part of the xml file,i just want to return every its content.

Thanks in advance...
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
currupipi is offline Offline
3 posts
since Apr 2009
Apr 5th, 2009
0

Re: Python And XML

Well xml files are text files so yes you can do open() and read just as you normally would a text file.
Featured Poster
Reputation Points: 975
Solved Threads: 140
Posting Virtuoso
scru is offline Offline
1,624 posts
since Feb 2007
Apr 5th, 2009
0

Re: Python And XML

Thanks for the help. I have tried unsuccessfully the following:

f=open('file.xml', 'r')
req.content_type='text/html'
req.write("<html>Reading...")
line=f.readline()
req.write(line)
req.write("</html>")

I tried the same with a txt file and it works,that is why im a bit confussed.

Thanks beforehand..
Last edited by currupipi; Apr 5th, 2009 at 6:39 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
currupipi is offline Offline
3 posts
since Apr 2009
Apr 6th, 2009
0

Re: Python And XML

It appears that req is an open file object of some type. Try flushing the output buffers (obj.flush()) or close the file.

-BV
Reputation Points: 86
Solved Threads: 40
Junior Poster
solsteel is offline Offline
141 posts
since Mar 2007
Apr 6th, 2009
0

Re: Python And XML

Hi again. I think i know a new thing about my problem.

I actually can open xml files and read the content. But i stops reading when it finds characters like <AS>. For example,if my xml file is:

This is my xml<>

It reads fine.

But when i start to fill in the tags,it does not read them. For example,it does not read "<a>" in case my xml file content is the following

This is my xml <a>

Thanks for helping
Last edited by currupipi; Apr 6th, 2009 at 7:46 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
currupipi is offline Offline
3 posts
since Apr 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Dictionaries python
Next Thread in Python Forum Timeline: Looking for quit command





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC