本文整理汇总了PHP中SimpleXmlElement::addAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP SimpleXmlElement::addAttribute方法的具体用法?PHP SimpleXmlElement::addAttribute怎么用?PHP SimpleXmlElement::addAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleXmlElement
的用法示例。
在下文中一共展示了SimpleXmlElement::addAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: toXml
/**
* {@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;
}
示例2: asXml
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();
}
示例3: serialize
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);
}
示例4: asXml
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();
}
示例5: returnXMLFormat
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();
}
示例6: afterScenario
/**
* 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]);
}
示例7: afterScenario
/**
* 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);
}
}
示例8: __construct
/**
* 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');
}
}
示例9: parseUnformattedText
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;
}
示例10: toXml
/**
* {@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;
}
示例11: exportClassMetadata
/**
* 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'])) {
//.........这里部分代码省略.........
示例12: parse
/**
* 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();
}
示例13: create_xml
/**
* @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();
}
示例14: toXml
/**
* {@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;
}
示例15: toXml
/**
* {@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;
}