PHP, XML and namespaces

  • Thread starter Deleted member 66701
  • Start date

Deleted member 66701

D

Deleted member 66701

XML - DTD's and XSD's - one or the other but not both?

EDIT:- Topic renamed to make it clear what I'm asking:-

************************************************
*XML - DTD's and XSD's - one or the other but not both?*
************************************************

Hi all

I've the following code


Code:
<?php


header("Content-type: text/xml; charset=utf-8");


echo '<?xml version="1.0" encoding="UTF-8"?>';

echo '<?xml-stylesheet type="text/xsl" href="artists.xsl"?>';

// echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';

echo '<artists xmlns="http://discography.frontierwebdesign.co.uk/discography" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://discography.frontierwebdesign.co.uk/discography artists.xsd">';

//perform query and store in $result
$results = mysql_query("SELECT * FROM `ARTIST`");

	while($row = mysql_fetch_array($results)) {
		echo '<artist>';
			
			echo "<fname>" .
			$row["artist_fname"] .
			"</fname>";
			
			echo "<sname>" .
			$row["artist_sname"] .
			"</sname>";

			echo "<id>" .
			$row["artist_id"] .
			"</id>";
			
			echo "<bio>" .
			htmlentities($row["artist_description"]) .
			"</bio>";
			
			echo '<albums>';

				//perform query and store in $result
				$albumResult = mysql_query("SELECT * 
						          FROM `ARTIST_ALBUM`
						          INNER JOIN `ALBUM`
						          ON `ARTIST_ALBUM`.`album_id` =
						          `ALBUM`.`album_id`
						          WHERE `artist_id` =
						          {$row['artist_id']}
						          ORDER BY `album_year` ASC
				");

				while($albumRow = mysql_fetch_array($albumResult)) {
					echo '<album>';
			
						echo "<name>" .
							$albumRow["album_name"] .
							"</name>";

							echo "<album_id>" .
							$albumRow["album_id"] .
							"</album_id>";
			
					echo '</album>';
			}
	
			echo '</albums>';			
			
		echo '</artist>';
	}
	
echo '</artists>';

?>


That is passing validation (here) but I get a "No DOCTYPE found! Checking XML syntax only." comment. If I add the relevant doctype (see line six commented code) then it breaks and I get a raft of errors (there is no attribute "xmlns" and so on - which you'd fully expect).

Now, I don't think I need to declare a doctype if I'm using an xsd to validate, but my uni lecturer thinks differently - are they correct?
 
Last edited by a moderator:
Soldato
Joined
23 Feb 2009
Posts
4,976
Location
South Wirral
My experience in Java is this is a really bad idea. Never mix them and if you are using name spaces don't bother with a DTD, use xsd instead.

Search on stack overflow you will likely find this has been asked before and will get chapter and verse on the topic.
 

Deleted member 66701

D

Deleted member 66701

OP
My experience in Java is this is a really bad idea. Never mix them and if you are using name spaces don't bother with a DTD, use xsd instead.

Search on stack overflow you will likely find this has been asked before and will get chapter and verse on the topic.

That's pretty much what I thought.

Thanks!
 

Deleted member 66701

D

Deleted member 66701

OP
I'm gonna go with the cool kids answer, that isn't an answer.... any reason you aren't using JSON? ;)

XML for this assignment, JSON is in a later one.

It's beneficial to know both.

Back on topic - I won the argument with the tutor - no doctype decleration in the PHP/XML file. I have put "!DOCTYPE html" in the XSL though and it works fine and the xml validates:-

http://www.validome.org/xml/validat...ontierwebdesign.co.uk/discography/artists.php

He also gave me two extension activities - to look at PHP GET and an autocomplete search function - to keep me busy as I've already completed the assignment even though it's not due in until 03/05/2015 :) Implemented both extension activities that same evening - if I don't get a good grade for this one.................
 
Last edited by a moderator:

Deleted member 66701

D

Deleted member 66701

OP
FYI - Assignment graded, thanks for everyones help:-

Capture_zpsqpzmohvf.png~original


Assignment was to create a database implementation with PHP driven SQL transformed into XML and styled by XSLT.

I added Jquery autocomplete, PHP Get and JSON external arrays.
 
Back
Top Bottom