471,356 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,356 software developers and data experts.

whats wrong swith this code?

Expand|Select|Wrap|Line Numbers
  1. xml = minidom.Document()
  2.  
  3. # Creates user element
  4. userElem = xml.createElement("user")
  5.  
  6. # Set attributes to user element
  7. userElem.setAttribute("name", "Sergio Oliveira")
  8. userElem.setAttribute("nickname", "seocam")
  9. userElem.setAttribute("email", "seocam@seocam.net")
  10. userElem.setAttribute("photo","seocam.png")
  11.  
  12. # Append user element in xml document
  13. xml.appendChild(userElem)
  14.  
  15. fp = open("d://file.xml","w")
  16. xml.writexml(fp, "    ", "", "\n", "UTF-8")
  17.  


i get this result when i open the xml[internet explorer]


The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.


--------------------------------------------------------------------------------

XML document must have a top level element. Error processing resource 'file:///D:/file.xml'.



thanks for kind of help in advance :D
Dec 30 '07 #1
4 1517
kudos
127 Expert 100+
How about pasting the resulting xml file?

-kudos

Expand|Select|Wrap|Line Numbers
  1. xml = minidom.Document()
  2.  
  3. # Creates user element
  4. userElem = xml.createElement("user")
  5.  
  6. # Set attributes to user element
  7. userElem.setAttribute("name", "Sergio Oliveira")
  8. userElem.setAttribute("nickname", "seocam")
  9. userElem.setAttribute("email", "seocam@seocam.net")
  10. userElem.setAttribute("photo","seocam.png")
  11.  
  12. # Append user element in xml document
  13. xml.appendChild(userElem)
  14.  
  15. fp = open("d://file.xml","w")
  16. xml.writexml(fp, "    ", "", "\n", "UTF-8")
  17.  


i get this result when i open the xml[internet explorer]


The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.


--------------------------------------------------------------------------------

XML document must have a top level element. Error processing resource 'file:///D:/file.xml'.



thanks for kind of help in advance :D
Dec 31 '07 #2
i am getting an empty file :S
Dec 31 '07 #3
seocam
1
Are you importing the minidom library?

Expand|Select|Wrap|Line Numbers
  1. from xml.dom import minidom
  2.  
Expand|Select|Wrap|Line Numbers
  1. xml = minidom.Document()
  2.  
  3. # Creates user element
  4. userElem = xml.createElement("user")
  5.  
  6. # Set attributes to user element
  7. userElem.setAttribute("name", "Sergio Oliveira")
  8. userElem.setAttribute("nickname", "seocam")
  9. userElem.setAttribute("email", "seocam@seocam.net")
  10. userElem.setAttribute("photo","seocam.png")
  11.  
  12. # Append user element in xml document
  13. xml.appendChild(userElem)
  14.  
  15. fp = open("d://file.xml","w")
  16. xml.writexml(fp, "    ", "", "\n", "UTF-8")
  17.  


i get this result when i open the xml[internet explorer]


The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.


--------------------------------------------------------------------------------

XML document must have a top level element. Error processing resource 'file:///D:/file.xml'.



thanks for kind of help in advance :D
Jan 2 '08 #4
yea i already have that imported!

never mind i wrote another code from a whle different approach, thnx 4 the help anyway m8 ;)
Jan 2 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Chris Geerdink | last post: by
4 posts views Thread by asdf | last post: by
3 posts views Thread by mahsa | last post: by
4 posts views Thread by blah | last post: by
5 posts views Thread by fcvcnet | last post: by
5 posts views Thread by islayer | last post: by
5 posts views Thread by hiqu | last post: by

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.