/** * {@inheritDoc} * * Format: * * <ProductSalePrice product_code="xxx" group_name="">xx.xx</ProductSalePrice> */ public function toXml($version = Version::CURRENT, array $options = array()) { if ($version < Version::NINE) { return; } $xmlObject = new SimpleXmlElement('<Module />'); $xmlObject->addAttribute('code', 'discount_saleprice'); $xmlObject->addAttribute('feature', 'discount'); $salePrice = $xmlObject->addChild('ProductSalePrice', $this->getPrice()); $salePrice->addAttribute('product_code', $this->getProductCode()); $salePrice->addAttribute('group_name', $this->getGroupName()); return $xmlObject; }
public function asXml() { $xml = new SimpleXmlElement("<blueprint></blueprint>"); $xml->addAttribute("key", $this->getKey()); $xml->addAttribute("type", "form"); $xml->addAttribute("name", $this->getName()); foreach ($this->fields() as $field) { $f = $xml->addChild("field"); $f->addAttribute("key", $field->getKey()); $f->addChild("displayName", $field->getDisplayName()); $f->addChild("format", $field->getFormat()); $f->addChild("href", $field->getHref()); } return $xml->asXml(); }
public function serialize($fmt, $app) { if (trim($fmt) === '') { $fmt = 'application/json'; } $types = explode(',', $fmt); $count = count($types); $base = $app->request->getUrl() . $app->request->getRootUri(); for ($i = 0; $i < $count; $i++) { if (strstr($types[$i], 'application/xml') !== false) { $app->response->headers->set('Content-Type', 'application/xml;odata.metadata=minimal'); $xml = new SimpleXmlElement('<?xml version="1.0" encoding="utf-8"?><service/>'); $xml->addAttribute('xmlns', 'http://www.w3.org/2007/app'); $xml->addAttribute('xmlns:atom', 'http://www.w3.org/2005/Atom'); $xml->addAttribute('xmlns:m', 'http://docs.oasis-open.org/odata/ns/metadata'); $xml->addAttribute('xml:base', $base); $xml->addAttribute('m:context', $base . '/$metadata'); $workspace = $xml->addChild('workspace'); $title = $workspace->addChild('atom:title', 'Default'); $title->addAttribute('type', 'text'); foreach ($this->collections as $collection) { $col = $workspace->addChild('collection'); $col->addAttribute('href', $collection->getUrl()); $title = $col->addChild('atom:title', $collection->getName()); $title->addAttribute('type', 'text'); } echo $xml->asXml(); return; } else { if (strstr($types[$i], 'application/json') !== false) { $app->response->headers->set('Content-Type', 'application/json;odata.metadata=minimal'); $resp = array(); $resp['@odata.context'] = $base . '/$metadata'; $collections = array(); foreach ($this->collections as $collection) { array_push($collections, array('name' => $collection->getName(), 'kind' => 'EntitySet', 'url' => $collection->getUrl())); } $resp['value'] = $collections; echo json_encode($resp); return; } } } $app->response->setStatus(406); echo 'Unknown format for Service Doc: ' . $fmt; error_log($fmt); }
public function asXml() { $xml = new SimpleXmlElement("<blueprint></blueprint>"); $xml->addAttribute("key", $this->getKey()); $xml->addAttribute("type", "join"); foreach ($this->fields() as $field) { $f = $xml->addChild("field"); $f->addAttribute("key", $field->getKey()); $f->addChild("displayName", $field->getDisplayName()); $f->addChild("dataType", $field->getDataType()); if ($field->isRequired()) { $f->addChild("required", "true"); } else { $f->addChild("required", "false"); } $f->addChild("minimum", $field->getMin()); $f->addChild("maximum", $field->getMax()); if ($field->isUnique()) { $f->addChild("unique", "true"); } else { $f->addChild("unique", "false"); } $f->addChild("example", $field->getExample()); $f->addChild("foreignKey", $field->getForeignKey()); $f->addChild("foreignValue", $field->getForeignValue()); switch ($field->getDataType()) { case "string": $f->addChild("encType", $field->getEncType()); $f->addChild("regexp", $field->getRegexp()); break; case "decimal": $f->addChild("precision", $field->getPrecision()); break; case "enum": $e = $f->addChild("enumOptions"); foreach ($field->getEnumOptions() as $option) { $o = $e->addChild("option", $option); } break; case "text": case "binary": $f->addChild("mimeType", $field->getMimeType()); break; } } return $xml->asXml(); }
private static function returnXMLFormat($param) { $lError = $param[self::_ParamType()] == self::_typeERROR(); if ($lError) { $xml = new \SimpleXmlElement('<error/>'); } else { $xml = new \SimpleXmlElement('<result/>'); } $xml->addAttribute(self::_ParamCode(), $param[self::_ParamCode()]); $xml->addAttribute(self::_ParamMensagem(), $param[self::_ParamMensagem()]); $xml->addAttribute(self::_ParamStatus(), $param[self::_ParamStatus()]); $xml->addAttribute(self::_ParamType(), $param[self::_ParamType()]); if (!$lError) { $xml = Helpers\UtilsXMLHelper::arrayToXml($xml, $param[self::_ParamDados()]); } return $xml->asXML(); }
/** * afterScenario * * @param mixed $event */ public function afterScenario($event) { $this->testcaseTimer->stop(); $code = $event->getTestResult()->getResultCode(); $testResultString = array(TestResult::PASSED => 'passed', TestResult::SKIPPED => 'skipped', TestResult::PENDING => 'pending', TestResult::FAILED => 'failed'); $this->testsuiteStats[$code]++; $this->currentTestcase->addAttribute('time', \round($this->testcaseTimer->getTime(), 3)); $this->currentTestcase->addAttribute('status', $testResultString[$code]); }
/** * afterScenario * * @param mixed $event */ public function afterScenario(AfterScenarioTested $event) { $this->testcaseTimer->stop(); $code = $event->getTestResult()->getResultCode(); $testResultString = array(TestResult::PASSED => 'passed', TestResult::SKIPPED => 'skipped', TestResult::PENDING => 'pending', TestResult::FAILED => 'failed'); $this->testsuiteStats[$code]++; $this->currentTestcase->addAttribute('time', \round($this->testcaseTimer->getTime(), 3)); $this->currentTestcase->addAttribute('status', $testResultString[$code]); if ($this->lastStepFailure) { $failureNode = $this->currentTestcase->addChild('failure', $this->lastStepFailureException->getMessage()); $failureNode->addAttribute('message', $this->lastStepFailure); } }
/** * Constructs a InboundXML response. * * @param SimpleXmlElement|array $arg: * - the element to wrap * - attributes to add to the element * - if null, initialize an empty element named 'Response' */ public function __construct($arg = null) { switch (true) { case $arg instanceof SimpleXmlElement: $this->element = $arg; $this->_currentChild = strtolower($arg->getName()); break; case $arg === null: $this->element = new SimpleXmlElement('<Response/>'); $this->_currentChild = 'response'; break; case is_array($arg): $this->element = new SimpleXmlElement('<Response/>'); $this->_currentChild = 'response'; foreach ($arg as $name => $value) { $this->_validateAttribute($name, 'response'); $this->element->addAttribute($name, $value); } break; default: throw new TelApi_Exception('InboundXML Invalid construction argument'); } }
function parseUnformattedText($inputText, $bookName = "") { // Create book, clause, text nodes $book = new SimpleXmlElement("<book></book>"); $book->addAttribute("bookName", $bookName); $conj = $book->addChild("conj", "X"); $clause = $book->addChild("clause"); $trimmedText = $this->trimNewLines($inputText); $trimmedText = $this->trimCarriageReturns($trimmedText); $trimmedText = $this->trimSpaces($trimmedText); $text = $clause->addChild("text", $trimmedText); $this->addChapterVerse($text, "", ""); // Make list of pconj's for beginning of file $pconjs = $this->getPconjList(); // Convert the xml to string $xml = $book->asXml(); // Combine the list of pconj's and xml string $xml = "{$pconjs} \n {$xml}"; return $xml; }
/** * {@inheritDoc} * * Format: * * <Import_Add module="productimport"> * <Description>Test Import</Description> * <Delimiter>tab|comma|semicolon|space|other</Delimiter> <!-- If module format is delimited, these fields are required --> * <Delimiter_Other>value</Delimiter_Other> <!-- Required if Delimiter is "other" --> * * <Header/> * * <AutoMap/> * * <Map> <!-- Required if AutoMap is not present, not allowed if it is present --> * <Field id="field"/> <!-- One or more fields are required --> * </Map> * <Settings> * <!-- Module specific data --> * * <!-- categoryimport --> * <Categories>add|update|addupdate|replace|addreplace</Categories> <!-- Required --> * <CustomFields>retain|delete</CustomFields> <!-- Required --> * * <!-- productimport --> * <Products>add|update|addupdate|replace|addreplace</Products> <!-- Required --> * <CustomFields>retain|delete</CustomFields> <!-- Required --> * <AttributeTemplates>use|copy</AttributeTemplates> <!-- Required --> * * <!-- customerimport --> * <Customers>add|update|addupdate|replace|addreplace</Customers> <!-- Required --> * <CustomFields>retain|delete</CustomFields> <!-- Required --> * * <!-- provisioningimport --> * <Groups> <!-- Optional, default is no group restrictions --> * <Group name="x"/> * </Groups> * * <Tags> <!-- Optional, default is to allow all tags --> * <Tag element="x"/> * </Tags> * </Settings> * </Import_Add> * */ public function toXml() { $xmlObject = new \SimpleXmlElement('<Import_Add />'); $xmlObject->addAttribute('module', $this->getModule()); return $xmlObject; }
/** * Converts a single ClassMetadata instance to the exported format * and returns it * * @param ClassMetadataInfo $metadata * @return mixed $exported */ public function exportClassMetadata(ClassMetadataInfo $metadata) { $xml = new \SimpleXmlElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><doctrine-mapping/>"); $xml->addAttribute('xmlns', 'http://doctrine-project.org/schemas/orm/doctrine-mapping'); $xml->addAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); $xml->addAttribute('xsi:schemaLocation', 'http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd'); if ($metadata->isMappedSuperclass) { $root = $xml->addChild('mapped-superclass'); } else { $root = $xml->addChild('entity'); } if ($metadata->customRepositoryClassName) { $root->addAttribute('repository-class', $metadata->customRepositoryClassName); } $root->addAttribute('name', $metadata->name); if (isset($metadata->primaryTable['name'])) { $root->addAttribute('table', $metadata->primaryTable['name']); } if (isset($metadata->primaryTable['schema'])) { $root->addAttribute('schema', $metadata->primaryTable['schema']); } if (isset($metadata->primaryTable['inheritance-type'])) { $root->addAttribute('inheritance-type', $metadata->primaryTable['inheritance-type']); } if ($metadata->discriminatorColumn) { $discriminatorColumnXml = $root->addChild('discriminiator-column'); $discriminatorColumnXml->addAttribute('name', $metadata->discriminatorColumn['name']); $discriminatorColumnXml->addAttribute('type', $metadata->discriminatorColumn['type']); $discriminatorColumnXml->addAttribute('length', $metadata->discriminatorColumn['length']); } if ($metadata->discriminatorMap) { $discriminatorMapXml = $root->addChild('discriminator-map'); foreach ($metadata->discriminatorMap as $value => $className) { $discriminatorMappingXml = $discriminatorMapXml->addChild('discriminator-mapping'); $discriminatorMappingXml->addAttribute('value', $value); $discriminatorMappingXml->addAttribute('class', $className); } } $root->addChild('change-tracking-policy', $this->_getChangeTrackingPolicyString($metadata->changeTrackingPolicy)); if (isset($metadata->primaryTable['indexes'])) { $indexesXml = $root->addChild('indexes'); foreach ($metadata->primaryTable['indexes'] as $name => $index) { $indexXml = $indexesXml->addChild('index'); $indexXml->addAttribute('name', $name); $indexXml->addAttribute('columns', implode(',', $index['columns'])); } } if (isset($metadata->primaryTable['uniqueConstraints'])) { $uniqueConstraintsXml = $root->addChild('unique-constraints'); foreach ($metadata->primaryTable['uniqueConstraints'] as $unique) { $uniqueConstraintXml = $uniqueConstraintsXml->addChild('unique-constraint'); $uniqueConstraintXml->addAttribute('name', $name); $uniqueConstraintXml->addAttribute('columns', implode(',', $unique['columns'])); } } $fields = $metadata->fieldMappings; $id = array(); foreach ($fields as $name => $field) { if (isset($field['id']) && $field['id']) { $id[$name] = $field; unset($fields[$name]); } } if ($idGeneratorType = $this->_getIdGeneratorTypeString($metadata->generatorType)) { $id[$metadata->getSingleIdentifierFieldName()]['generator']['strategy'] = $idGeneratorType; } if ($fields) { foreach ($fields as $field) { $fieldXml = $root->addChild('field'); $fieldXml->addAttribute('name', $field['fieldName']); $fieldXml->addAttribute('type', $field['type']); if (isset($field['columnName'])) { $fieldXml->addAttribute('column', $field['columnName']); } if (isset($field['length'])) { $fieldXml->addAttribute('length', $field['length']); } if (isset($field['precision'])) { $fieldXml->addAttribute('precision', $field['precision']); } if (isset($field['scale'])) { $fieldXml->addAttribute('scale', $field['scale']); } if (isset($field['unique']) && $field['unique']) { $fieldXml->addAttribute('unique', $field['unique']); } if (isset($field['options'])) { $optionsXml = $fieldXml->addChild('options'); foreach ($field['options'] as $key => $value) { $optionsXml->addAttribute($key, $value); } } if (isset($field['version'])) { $fieldXml->addAttribute('version', $field['version']); } if (isset($field['columnDefinition'])) { $fieldXml->addAttribute('column-definition', $field['columnDefinition']); } } } if ($id) { foreach ($id as $field) { $idXml = $root->addChild('id'); $idXml->addAttribute('name', $field['fieldName']); $idXml->addAttribute('type', $field['type']); if (isset($field['columnName'])) { $idXml->addAttribute('column', $field['columnName']); } if ($idGeneratorType = $this->_getIdGeneratorTypeString($metadata->generatorType)) { $generatorXml = $idXml->addChild('generator'); $generatorXml->addAttribute('strategy', $idGeneratorType); } } } foreach ($metadata->associationMappings as $name => $associationMapping) { if ($associationMapping instanceof OneToOneMapping) { $associationMappingXml = $root->addChild('one-to-one'); } else { if ($associationMapping instanceof OneToManyMapping) { $associationMappingXml = $root->addChild('one-to-many'); } else { if ($associationMapping instanceof ManyToManyMapping) { $associationMappingXml = $root->addChild('many-to-many'); } } } $associationMappingXml->addAttribute('field', $associationMapping->sourceFieldName); $associationMappingXml->addAttribute('target-entity', $associationMapping->targetEntityName); if (isset($associationMapping->mappedBy)) { $associationMappingXml->addAttribute('mapped-by', $associationMapping->mappedBy); } if (isset($associationMapping->orphanRemoval)) { $associationMappingXml->addAttribute('orphan-removal', $associationMapping->orphanRemoval); } if (isset($associationMapping->joinTable) && $associationMapping->joinTable) { $joinTableXml = $associationMappingXml->addChild('join-table'); $joinTableXml->addAttribute('name', $associationMapping->joinTable['name']); $joinColumnsXml = $joinTableXml->addChild('join-columns'); foreach ($associationMapping->joinTable['joinColumns'] as $joinColumn) { $joinColumnXml = $joinColumnsXml->addChild('join-column'); $joinColumnXml->addAttribute('name', $joinColumn['name']); $joinColumnXml->addAttribute('referenced-column-name', $joinColumn['referencedColumnName']); if (isset($joinColumn['onDelete'])) { $joinColumnXml->addAttribute('on-delete', $joinColumn['onDelete']); } if (isset($joinColumn['onUpdate'])) { $joinColumnXml->addAttribute('on-update', $joinColumn['onUpdate']); } } $inverseJoinColumnsXml = $joinTableXml->addChild('inverse-join-columns'); foreach ($associationMapping->joinTable['inverseJoinColumns'] as $inverseJoinColumn) { $inverseJoinColumnXml = $inverseJoinColumnsXml->addChild('join-column'); $inverseJoinColumnXml->addAttribute('name', $inverseJoinColumn['name']); $inverseJoinColumnXml->addAttribute('referenced-column-name', $inverseJoinColumn['referencedColumnName']); if (isset($inverseJoinColumn['onDelete'])) { $inverseJoinColumnXml->addAttribute('on-delete', $inverseJoinColumn['onDelete']); } if (isset($inverseJoinColumn['onUpdate'])) { $inverseJoinColumnXml->addAttribute('on-update', $inverseJoinColumn['onUpdate']); } if (isset($inverseJoinColumn['columnDefinition'])) { $inverseJoinColumnXml->addAttribute('column-definition', $inverseJoinColumn['columnDefinition']); } if (isset($inverseJoinColumn['nullable'])) { $inverseJoinColumnXml->addAttribute('nullable', $inverseJoinColumn['nullable']); } if (isset($inverseJoinColumn['orderBy'])) { $inverseJoinColumnXml->addAttribute('order-by', $inverseJoinColumn['orderBy']); } } } if (isset($associationMapping->joinColumns)) { $joinColumnsXml = $associationMappingXml->addChild('join-columns'); foreach ($associationMapping->joinColumns as $joinColumn) { $joinColumnXml = $joinColumnsXml->addChild('join-column'); $joinColumnXml->addAttribute('name', $joinColumn['name']); $joinColumnXml->addAttribute('referenced-column-name', $joinColumn['referencedColumnName']); if (isset($joinColumn['onDelete'])) { $joinColumnXml->addAttribute('on-delete', $joinColumn['onDelete']); } if (isset($joinColumn['onUpdate'])) { $joinColumnXml->addAttribute('on-update', $joinColumn['onUpdate']); } if (isset($joinColumn['columnDefinition'])) { $joinColumnXml->addAttribute('column-definition', $joinColumn['columnDefinition']); } if (isset($joinColumn['nullable'])) { $joinColumnXml->addAttribute('nullable', $joinColumn['nullable']); } } } if (isset($associationMapping->orderBy)) { $orderByXml = $associationMappingXml->addChild('order-by'); foreach ($associationMapping->orderBy as $name => $direction) { $orderByFieldXml = $orderByXml->addChild('order-by-field'); $orderByFieldXml->addAttribute('name', $name); $orderByFieldXml->addAttribute('direction', $direction); } } $cascade = array(); if ($associationMapping->isCascadeRemove) { $cascade[] = 'remove'; } if ($associationMapping->isCascadePersist) { $cascade[] = 'persist'; } if ($associationMapping->isCascadeRefresh) { $cascade[] = 'refresh'; } if ($associationMapping->isCascadeMerge) { $cascade[] = 'merge'; } if ($associationMapping->isCascadeDetach) { $cascade[] = 'detach'; } if ($cascade) { $cascadeXml = $associationMappingXml->addChild('cascade'); foreach ($cascade as $type) { $cascadeXml->addChild($type); } } } if (isset($metadata->lifecycleCallbacks)) { $lifecycleCallbacksXml = $root->addChild('lifecycle-callbacks'); foreach ($metadata->lifecycleCallbacks as $name => $methods) { foreach ($methods as $method) { $lifecycleCallbackXml = $lifecycleCallbacksXml->addChild('lifecycle-callback'); $lifecycleCallbackXml->addAttribute('type', $name); $lifecycleCallbackXml->addAttribute('method', $method); } } } return $this->_asXml($xml); }
/** * function parse() * Gera um rss a partir de uma busca * @version * 0.1 03/06/2009 Método inicial * 1.0 16/05/2010 Método refatorado completamente, renomeado, trocados * seus parâmetros, etc. * * @param $model O model a ser feita a busca * @param $params Os parâmetros para a busca, será passado diretamente * para o Model::all() */ public function parse($model, $params = array()) { //fazendo a busca $this->results = Loader::instance('Model', $model)->all($params); //pegando somente os campos $this->fields = !empty($this->results) ? array_keys(reset($this->results)) : array(); //Limpando os campos "relations" que não existem em $this->allowedItems foreach ($this->config['relations'] as $key => $value) { if (!in_array($key, $this->allowedItems)) { unset($this->config['relations'][$key]); } } //Criando o cabeçalho $rss = new SimpleXmlElement('<?xml version="1.0" encoding="UTF-8" ?><rss xmlns:atom="http://www.w3.org/2005/Atom"></rss>'); $rss->addAttribute('version', '2.0'); $channel = $rss->addChild('channel'); //verificando pelas tags permitidas, evitará a //inclusão de tags inválidas e poupará vários IFs. foreach ($this->allowedHeaders as $header) { if (!empty($this->config['headers'][$header])) { $channel->addChild($header, $this->format($this->config['headers'][$header], $header)); } } //Procuro nos resultados foreach ($this->results as $row => $result) { $item = $channel->addChild("item"); foreach ($this->config['relations'] as $key => $field) { $item->addChild($key, $this->format(String::insert($field, $result), $key)); // $item->addChild($key, $this->format($this->extract($field, $row), $key)); } } return $rss->asXml(); }
/** * @param $root * @param $type * @param $href * @param $content * * @return mixed */ private function create_xml($root, $type, $href, $content) { global $client; $xml = new SimpleXmlElement('<' . $root . ' />'); $xml->addAttribute('Type', $type); $xml->addAttribute('xmlns', 'http://www.veeam.com/ent/v1.0'); $xml->addAttribute('xmlns:xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); $xml->addAttribute('Href', $this->client->getBaseUrl() . "{$href}"); $content = array_flip($content); array_walk_recursive($content, array($xml, 'addChild')); return $xml->asXml(); }
/** * {@inheritDoc} * * Format: * * <Product_Update code="existing_product_code"> * <Code>ale-gallon</Code> * <SKU>sku</SKU> * <Name><![CDATA[Ale, gallon jug]]></Name> * <Price>2.00</Price> * <Cost>1.50</Cost> * <Weight>8.00</Weight> * <Description><![CDATA[A gallon jug of quality ale.]]></Description> * <Taxable>Yes</Taxable> * <Active>Yes</Active> * <CanonicalCategoryCode>food</CanonicalCategoryCode> * <AlternateDisplayPage>PROD</AlternateDisplayPage> * <ThumbnailImage></ThumbnailImage> * <FullSizeImage></FullSizeImage> * </Product_Update> * */ public function toXml($version = Version::CURRENT, array $options = array()) { $xmlObject = new SimpleXmlElement('<Product_Update />'); $xmlObject->addAttribute('code', $this->getCode()); if ($this->getNewCode()) { $xmlObject->addChild('Code', $this->getNewCode()); } elseif ($this->getCode()) { $xmlObject->addChild('Code', $this->getCode()); } if ($this->getName()) { $xmlObject->addChild('Name', $this->getName())->addAttribute('method-call', 'addCDATA'); } if ($this->getPrice()) { $xmlObject->addChild('Price', $this->getPrice()); } if ($this->getTaxable() || $this->getTaxable() === false) { $xmlObject->addChild('Taxable', $this->getTaxable() ? 'Yes' : 'No'); } if ($this->getActive() || $this->getActive() === false) { $xmlObject->addChild('Active', $this->getActive() ? 'Yes' : 'No'); } if ($this->getSku()) { $xmlObject->addChild('SKU', $this->getSku()); } if ($this->getCost()) { $xmlObject->addChild('Cost', $this->getCost()); } if ($this->getWeight()) { $xmlObject->addChild('Weight', $this->getWeight()); } if ($this->getDescription()) { $xmlObject->addChild('Description', $this->getDescription())->addAttribute('method-call', 'addCDATA'); } if ($this->getCanonicalCategoryCode()) { $xmlObject->addChild('CanonicalCategoryCode', $this->getCanonicalCategoryCode()); } if ($this->getAlternateDisplayPage()) { $xmlObject->addChild('AlternateDisplayPage', $this->getAlternateDisplayPage()); } if ($this->getThumbnailImage()) { $xmlObject->addChild('ThumbnailImage', $this->getThumbnailImage()); } if ($this->getFullSizeImage()) { $xmlObject->addChild('FullSizeImage', $this->getFullSizeImage()); } return $xmlObject; }
/** * {@inheritDoc} * * Format: * * <Order_Add_Product order_id="1000" code="test"> (Required, order_id, code) * <Quantity>1</Quantity> * <Options> * <Option> * <AttributeCode>test</AttributeCode> * <Value>Yes</Value> * </Option> * <Option> * <AttributeCode>template</AttributeCode> * <AttributeTemplateAttributeCode>template_attr</AttributeTemplateAttributeCode> * <Value>v1</Value> * </Option> * </Options> * <Shipment> (Optional) * <Code>Ship_Code</Code> (Optional) * <Cost>1</Cost> (Optional) * <MarkAsShipped>Yes</MarkAsShipped> (Optional) * <TrackingNumber>1111111111</TrackingNumber> (Required) * <TrackingType>FedEx</TrackingType> (Required) * <ShipDate> (Optional) * <Day>7</Day> * <Month>9</Month> * <Year>2012</Year> * </ShipDate> * </Shipment> * <Shipment /> (Optional) * </Order_Add_Product> */ public function toXml() { $xmlObject = new SimpleXmlElement('<Order_Add_Product />'); $xmlObject->addAttribute('order_id', $this->getOrderId()); $xmlObject->addAttribute('code', $this->getCode()); $xmlObject->addChild('Quantity', $this->getQuantity()); return $xmlObject; }
/** * Based on image specification, write a very simple SVG file to disk. * Ignores the background spec because transparency is cool. :) * * @param array $spec Spec describing background and shapes to draw * @param string $format File format to write (which is obviously always svg here) * @param string $filename Filename to write to * * @throws Exception */ public function writeSvg($spec, $format, $filename) { $svg = new SimpleXmlElement('<svg/>'); $svg->addAttribute('xmlns', 'http://www.w3.org/2000/svg'); $svg->addAttribute('version', '1.1'); $svg->addAttribute('width', $spec['width']); $svg->addAttribute('height', $spec['height']); $g = $svg->addChild('g'); foreach ($spec['draws'] as $drawSpec) { $shape = $g->addChild('polygon'); $shape->addAttribute('fill', $drawSpec['fill']); $shape->addAttribute('points', self::shapePointsToString($drawSpec['shape'])); } if (!($fh = fopen($filename, 'w'))) { throw new Exception("couldn't open {$filename} for writing"); } fwrite($fh, $svg->asXML()); if (!fclose($fh)) { throw new Exception("couldn't close {$filename}"); } }
<?php $xml = new SimpleXmlElement("<img></img>"); $xml->addAttribute("src", "foo"); $xml->addAttribute("alt", ""); echo $xml->asXML(); ?> ===DONE===
public function testSearchAttributeValue() { $xml = new \SimpleXmlElement('<enclosure />'); $xml->addAttribute('href', 'http://localhost/'); $xml->addAttribute('type', 'audio/mpeg'); $xml->addAttribute('length', '456'); $this->assertNull($this->object->searchAttributeValue($xml, array('foo'))); $this->assertEquals('http://localhost/', $this->object->searchAttributeValue($xml, array('url', 'href'))); }
<?php require_once DIR_FS_INC . 'get_external_content.inc.php'; define('RSS_FEED_TITLE', 'Shophelfer Ankündigungen'); define('RSS_FEED_DESCRIPTION', 'Shophelfer - Forum - Ankündigungen'); define('RSS_FEED_LINK', 'http://www.shophelfer.com/index.php?action=forum'); define('RSS_FEED_ALTERNATIVE', 'Leider können die aktuellen Neuigkeiten nicht im RSS Feed dargestellt werden. Bitte besuchen sie unsere Community unter <a href="' . RSS_FEED_LINK . '">www.shophelfer.com</a> um wichtige Informationen für Shopbetreiber zu diesen Themen zu erfahren: <ul><li>Wichtige Updates und Fixes</li><li>Funktionserweiterungen</li><li>Rechtssprechungen</li><li>Neuigkeiten</li><li>Klatsch und Tratsch</li></ul>'); ?> <table border="0" width="98%" cellspacing="0" cellpadding="0"> <?php $feed = get_external_content('http://www.blog.shopbetreuung.com/feed/'); if ($feed && class_exists('SimpleXmlElement')) { $rss = new SimpleXmlElement($feed, LIBXML_NOCDATA); $rss->addAttribute('encoding', 'UTF-8'); ?> <div style="background:#F0F1F1;font-size:11px; border:1px solid #999; padding:5px; font-weight: 700" align="left"> <a target="_blank" href="<?php echo $rss->channel->link; ?> "><?php echo $rss->channel->title; ?> </a> <br/> <?php echo $rss->channel->description; ?> </div> <br/> <?php