I figured out what I was doing wrong. Nothing except for how I chose to echo or display the XML.
Since it’s a dynamic call, I can’t view the page source to see the XML that gets returned. And I never verified that I was getting a String: I assumed that because it was inside a CDATA
block that the tags would be visible, but what I actually got was the tags being evaluated, and since ^<get><time /></get>
isn’t part of XHTML 1.1 . . . my XML never appeared.
So in the interest of saving some future developer a few minutes or hours or days of trouble, if you’re trying to parse POST-ed XMLHttpRequest XML DOM objects in a Python CGI web application and it looks like STDIN is empty or you’re not getting the POST contents, verify that you’re reading something by checking the length and extracting a part of the string. And convert your tags.
#!/Python24/python
import os
import sys
def main():
print "Content-Type: application/xml\n\n"
print "
\n";
for key in os.environ:
print key + "=" + os.environ[key] + "
\n"
if os.environ.has_key("CONTENT_LENGTH"):
length = int(os.environ["CONTENT_LENGTH"])
s = str(sys.stdin.read(length))
s = s.replace('< ', '<')
print "
" + s + "";
print "
\n]]>
if __name__ == '__main__':
main()