将对象显示为HTML和XML

时间:2011-11-03 09:19:41

标签: php html xml

我有一个类证书,而这个证书又有不同的对象,例如TradingMarket是一个Object,Currency是一个Object,Issuer是一个Object。

现在我想以XML和HTML格式显示这些完整信息。对PHP编程不熟悉我不知道如何以更好的方式完成这两项操作。

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() {
        // ???????????????????
      }

  }

1 个答案:

答案 0 :(得分:0)

作为documented here尝试PEAR的XML_Serializer包,因为它可能会在XML前端执行您正在寻找的内容。

在HTML前端,您可以使用XSL样式表将XML呈现为HTML,或者更简单地说,您可以遍历对象的属性并使用echo和HTML标记输出它们。或者,您可以在HTML文档中输出上面的XML,并使用CSS对其进行样式设置。还是......