473,549 Members | 2,731 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

whats wrong swith this code?

75 New Member
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 1588
kudos
127 Recognized Expert New Member
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
askalottaqs
75 New Member
i am getting an empty file :S
Dec 31 '07 #3
seocam
1 New Member
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
askalottaqs
75 New Member
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

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

Similar topics

3
2385
by: Chris Geerdink | last post by:
combo with PHP. what is wrong with the Javascript? else { include("mysql.php"); $query1 = mysql_query("INSERT INTO gbook (naam, email, text) VALUES ('".$_POST."', '".$_POST."', '".$_POST."')"); ?> <script language="JavaScript"> <!--
4
4058
by: asdf | last post by:
Hello! Can someone tell me whats wrong with this piece of code: Option Compare Database Option Explicit Sub retrieve() Dim rst As ADODB.Recordset Dim i As Integer
3
2036
by: mahsa | last post by:
Hi do you know whats wrong with this code? <asp:HyperLink id="HLink_Help" runat="server" NavigateUrl='<%# "javascript:window.open('comments.aspx?id=1,width=500,height=600, scrollBars=yes');" %>'>Need Help?</asp:HyperLink> -- mahsa
4
3524
by: blah | last post by:
Hello everyone, Ive been trying to get my application to "click" on a button in another application using SendMessage, Ive gotten this far but Im not sure whats wrong with this code, here is the whole application (its small for testing purposes) and it seems that window wraps the text, at least when I preview this post: using System; using...
7
2220
by: Mike Barnard | last post by:
It's a simple test... VERY SIMPLE. But... In an external stlyesheet some attributes don't show. With the same styles cut and pasted to the test internally it works as expected. Anyone tell me why? Its probably sooooooo obvious, but it is 1.19 am! Thanks. www.thunderin.co.uk/
1
7503
by: Abubakar | last post by:
Hi, In my application, Some of my thread gets stuck somewhere. The vs2k5 debugging "Thread" window shows that stuck thread and I can I dentify it. In its Name column the following text is written: "std::_Container_base::_Orphan_all". What does this mean? Now some general info about whats happnening here: :this is a call to a SendMessage...
5
4302
by: fcvcnet | last post by:
Hi, In swith statements, follow case is constant-expression, can it be a range? For example: ... case ' 0 ' : ... thanks.
5
2309
by: islayer | last post by:
can someone tell me what is wrong with the bold code? i am just learning perl. the program should create a perl file with a random name (5 letters, followed by a number), but the name is always just the number. whats wrong with my code? #!/usr/bin/perl use Fcntl; @array = (a..z); srand; foreach (1..5) { $name = int(rand...
5
1695
by: hiqu | last post by:
This issue is driving me nuts and not able to figure out whats wrong. I've this code in my firefox extension. Firefox always hangs and reports the script is busy. if I introduce a break statement in the for(;;) loop below, then no issue. Any help would be appreciated! function getStuff()
0
7446
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...
1
7469
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...
0
7808
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6040
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3498
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...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1057
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
757
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...

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.