-4

I have a XML that looks like this:

<data>
    <items>
        <item name="item1"></item>
        <item name="item2"></item>
        <item name="item3"></item>
        <item name="item4"></item>
    </items>
</data>

Can anyone tell me how to read the file and print every single letter, not only the contents but ALL THE CHARACTERS (including the letters in the brackets)?

ice_e
  • 1
  • 3
  • Could you clarify what you mean by "print" in your question? The duplicate question will read a file with the content above, including that within the angle brackets. Perhaps you're trying to display it within a web page, in which case it would be necessary to escape characters that would be interpreted as HTML/XML - but your question doesn't make that clear. It would help immensely to include the code you're using that doesn't suit, and explain what the problem is. – Mogsdad Jun 11 '15 at 18:11
  • By print, I mean to use "print". It turned out I set the content-type to be text/html and tried to print the xml. That was why all those in the brackets were not shown. Now I set it to be text/text and it works just fine. – ice_e Jun 11 '15 at 21:56

1 Answers1

1

Right back at ya.

import os
filepath='xml_file.xml'
total_bytes=os.stat(filepath).st_size
f = open(filepath,'rb')
for char_index in xrange(total_bytes):
    one_char=f.read(1)
    print "here is the char at offset: %s : %s" % (char_index,one_char)
f.close()
parity3
  • 643
  • 9
  • 18