XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 29th, 2004, 09:47 AM
zion_matrix zion_matrix is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 2 zion_matrix User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Exclamation "XML document must have a top level element. Error processing resource "

Hello,

I am seeking your urgent attention in debugging the above mentioned error message that I have been receiving. I need my code to be working today.

For the past four days I have been trying to get it to work.

It goes as follows:


<?php
if (!$db = mysql_connect('localhost','root')) {
die("Connection failed to the host 'localhost'");
exit;
}


if (!mysql_select_db('zioncd',$db)) {
die("Cannot connect to database 'Zion Cd'");
exit;
}


$cd = 'cd';
$query = "SELECT orderlev FROM $cd WHERE orderlev = 50";
$dbresult = mysql_query($query, $db);

// creates an xml document version 1.0; This returns the object reference.
$file = domxml_new_doc("1.0");

// create new element
$cd = $file->create_element('cd');
$cd = $file->append_child($cd);

// process each row from the sql query
while ($row = mysql_fetch_assoc($dbresult)) {
// creates a subnode for each row
$node = $file->create_element($cd); // $cd is the table name
$node = $zioncd->append_child($occ);

// add a child node for each field
foreach ($row as $fieldname => $fieldvalue) {
$childrow = $file->create_element($fieldname);
$childrow = $file->append_child($child);

$value = $file->create_text_node($fieldvalue);
$value = $child->append_child($value);
} // foreach
} // while

// get completed xml document

$xml_string = $doc->dump_mem(true);
echo $xml_string;
?>

Regards,

zion

Reply With Quote
  #2  
Old May 7th, 2004, 08:01 AM
wendra wendra is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: Germany
Posts: 14 wendra User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Sorry for responding to your problem too long. But, I guess it wouldn't hurt to give you some help, right? This is just a rough guess, I think the problem is with your XML file. XML files should be like:

Code:
<product>
<pcgame>SC</pcgame>
<programming>VB</programming>
...etc
</product>


But, it souldn't be like:

Code:
<pcgame>SC</pcgame>
<programming>VB</programming>
...etc


So, I think you only miss the high most element, in this case is <product></product>.

Does it help?

Last edited by wendra : May 10th, 2004 at 02:07 AM.

Reply With Quote
  #3  
Old May 7th, 2004, 02:03 PM
zion_matrix zion_matrix is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 2 zion_matrix User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
xml must have a top level element

This xml is mixed with php. It is supposed to automate pulling records from the database where the stock level is below the order level.

Thanks anyway for trying.

Reply With Quote
  #4  
Old May 10th, 2004, 01:39 AM
wendra wendra is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: Germany
Posts: 14 wendra User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
You're welcome. But I don't know any PHP, so I am really sorry, I can not help you more than that. Can somebody help with his problem?

Reply With Quote
  #5  
Old May 19th, 2004, 09:12 AM
NickBoldt NickBoldt is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 3 NickBoldt User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I think you're both right... whether it's PHP creating XML or straight XML, you still need a top-level element...

So, before you echo out your $xml_string, just wrap it with some dummy tags:

<?php
echo "<doc>\n";
echo $xml_string;
echo "</doc>\n";
?>

Does that fix the problem?

(I'm fairly new to XML, with a few years of PHP geekdom under my belt. I've seen that error before... IE6.0 throws that when you display a .xml file that doesn't contain a single top-level element, eg:

<foo>
<bar> ... </bar>
<bar> ... ... </bar>
</foo>
<foo>
<bar> ... </bar>
<bar> ... ... </bar>
</foo>

instead of

<doc>
<foo>
<bar> ... </bar>
<bar> ... ... </bar>
</foo>
<foo>
<bar> ... </bar>
<bar> ... ... </bar>
</foo>
</doc>

Reply With Quote
  #6  
Old May 19th, 2004, 03:57 PM
Syx Syx is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 1 Syx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Just thought I would stop by after googling for a fix to this error.

Your dummy <doc></doc> tags works a treat - thanks very much for the help (even though it was not intended for me!).


Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > "XML document must have a top level element. Error processing resource "


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT