2

I have a class certificate which in turn has different objects like TradingMarket is an Object, Currency is an Object and Issuer is an Object.

Now I want to display this complete information as XML and HTML. being new to PHP programming I have no clue how to do these both operation in a better way.

class Certificate {
      private $isin;
      private $tradingMarket;
      private $currency;
      private $issuer;
      private $issuingPrice;
      private $currentPrice;

      public function __construct($isin, $tradingMarket, $currency, $issuer, $issuingPrice, $currentPrice) {
          $this->isin = $isin;
          $this->tradingMarket = $tradingMarket;
          $this->currency = $currency;
          $this->issuer = $issuer;
          $this->issuingPrice = $issuingPrice;
          $this->currentPrice = $currentPrice;

      } 

      public function setTradingMarket($tradingMarket) {
          $this->tradingMarket = $tradingMarket;
      }
      public function getTradingMarket() {
          return $this->tradingMarket;
      }

      public function setCurrency($currency) {
          $this->currency = $currency;
      }
      public function getCurrency() {
          return $this->currency;
      }

      public function setIssuer($issuer) {
          $this->issuer = $issuer;
      }
      public function getIssuer() {
          return $this->issuer;
      }

      public function setIssuingPrice($issuingPrice) {
          $this->issuingPrice = $issuingPrice;
      }
      public function getIssuingPrice() {
          return $this->issuingPrice;
      }

      public function setCurrentPrice($currentPrice) {
          $this->currentPrice = $currentPrice;
      }
      public function getCurrentPrice() {
          return $this->currentPrice;
      }

      public function displayAsHtml() {
       //?????????
      }

      public function displayAsXml() {
        // ???????????????????
      }

  }
hakre
  • 193,403
  • 52
  • 435
  • 836
user991047
  • 315
  • 4
  • 12
  • Related: http://stackoverflow.com/questions/7979807/how-to-extends-this-sample-class-with-new-properties – hakre Nov 25 '12 at 12:51

1 Answers1

0

As documented here try PEAR's XML_Serializer package, as that will likely do what you're looking for on the XML front.

On the HTML front you could then use an XSL stylesheet to render the XML as HTML, or, more simply, you could just iterate through the properties of your objects and output them with echo and HTML tags. Or you can output the XML from above in an HTML document and use CSS to style it. Or...

Community
  • 1
  • 1
Benjie
  • 7,701
  • 5
  • 29
  • 44