Hallo,
Ich versuche ObjektOrientiert (wie ich es aus Java kenne) eine gallerie zu programmieren (zur übung)
ich habe mir zwei klassen erstellt
Gallery
Picture
picture.class.php
gallery.class.php
zu guter letzt hab ich noch eine php file, die mir das xml dann zusammensammelt und an den browser schickt.
createxml.php
wenn ich mir nun die generated.xml anschaue, die das skript speichert passt das zu 100%
ABER
Google Chrome sagt mir:
Internet Explorer zeigt mir gar nichts an!
und Firefox motzt:
wenn ich mir nun den quellcode kopiere und im editor ansehe sehe ich folgendes:
eine leerzeile und dann zwei Fragezeichen (hex: 3F 3F)
wo die her kommen ist mir ein rätsel, da ich im code lediglich den header angebe und dann das xml raus schreibe (was ja, wie in der datei korrekt ist)
Was mache ich Falsch?
danke schon mal
lumo
Ich versuche ObjektOrientiert (wie ich es aus Java kenne) eine gallerie zu programmieren (zur übung)
ich habe mir zwei klassen erstellt
Gallery
Picture
picture.class.php
PHP-Code:
<?php
class Picture {
public $title = 'title';
public $fileName = 'fileName';
public $owner = 'owner';
public $exclude = false;
public $allowOriginalDownload = false;
/**
* internal function
*/
private function addXMLElement($xml, $name, $value) {
$xml->startElement($name);
$xml->text($value);
$xml->endElement();
}
public function addXML($xml) {
$xml->startElement('picture');
$this->addXMLElement($xml, 'fileName', $this->fileName);
$this->addXMLElement($xml, 'title', $this->title);
$this->addXMLElement($xml, 'owner', $this->owner);
$this->addXMLElement($xml, 'exclude', $this->exclude ? 'true' : 'false');
$this->addXMLElement($xml, 'allowOriginalDownload', $this->allowOriginalDownload? 'true' : 'false');
$xml->endElement();
}
}
?>
PHP-Code:
<?php
class Gallery {
public $title = '';
public $folderName = '';
public $paging = true;
public $pageLimit = 100;
public $pictures = array();
/**
* default constructor
*/
function __construct($folderName) {
# todo: load global gallery configs here
$this->folderName = $folderName;
$this->title = $folderName;
}
/**
* internal function
*/
private function addXMLElement($xmlDoc, $name, $value) {
$xmlDoc->startElement($name);
$xmlDoc->text($value);
$xmlDoc->endElement();
}
/**
* add a picture to this gallery
*/
public function addPicture($picture) {
$this->pictures[] = $picture;
}
public function toXML() {
$xml=new XMLWriter();
//lets store our XML into the memory so we can output it later
$xml->openMemory();
//lets also set the indent so its a very clean and formatted XML
$xml->setIndent(true);
//now we need to define our Indent string,which is basically how many blank spaces we want to have for the indent
$xml->setIndentString("\t");
$xml->startDocument('1.0','UTF-8');
//lets start our main element,lets call it “XML”
$xml->startElement('xml');
$xml->startElement('gallery');
# add name element
$this->addXMLElement($xml, 'title', $this->title);
# add folderName element
$this->addXMLElement($xml, 'folderName', $this->folderName);
# add paging element
$this->addXMLElement($xml, 'paging', $this->paging ? 'true' : 'false');
# add pageLimit element
$this->addXMLElement($xml, 'pageLimit', $this->pageLimit);
# add the pictures
$xml->startElement('pictures');
foreach ($this->pictures as &$pic) {
$pic->addXML($xml);
}
$xml->endElement();
$xml->endElement();
$xml->endElement();
#$xml->endDocument();
return $xml->outputMemory(true);
}
}
?>
createxml.php
PHP-Code:
<?php
include 'gallery.class.php';
include 'picture.class.php';
#createXML('sampleGallery');
$gallery = new Gallery('sampleGallery');
$gallery->addPicture(new Picture());
//Set the content-type header to xml
header("Content-Type:text/xml");
//echo the XML declaration
echo $gallery->toXML();
//and save it to disk
file_put_contents("generated.xml",$gallery->toXML());
?>
ABER
Google Chrome sagt mir:
This page contains the following errors:
error on line 1 at column 1: Document is empty
Below is a rendering of the page up to the first error.
error on line 1 at column 1: Document is empty
Below is a rendering of the page up to the first error.
und Firefox motzt:
XML Parsing Error: not well-formed
Location: http://localhost/dev/FolderGallery/createXML.php
Line Number 1, Column 2:<?xml version="1.0" encoding="UTF-8"?>
-^
Location: http://localhost/dev/FolderGallery/createXML.php
Line Number 1, Column 2:<?xml version="1.0" encoding="UTF-8"?>
-^
eine leerzeile und dann zwei Fragezeichen (hex: 3F 3F)
wo die her kommen ist mir ein rätsel, da ich im code lediglich den header angebe und dann das xml raus schreibe (was ja, wie in der datei korrekt ist)
Was mache ich Falsch?

danke schon mal
lumo

Kommentar