本文整理汇总了PHP中DomDocument::createAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP DomDocument::createAttribute方法的具体用法?PHP DomDocument::createAttribute怎么用?PHP DomDocument::createAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DomDocument
的用法示例。
在下文中一共展示了DomDocument::createAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _toHtml
public function _toHtml()
{
$this->_checkRequired();
$info = $this->getInfo();
$certain = $info['certain'];
$dom = new DomDocument();
$dom->preserveWhitespace = false;
$block = $dom->createElement('block');
$attr = $dom->createAttribute('type');
$attr->value = $this->getAlias();
$block->appendChild($attr);
$dom->appendChild($block);
$output = simplexml_load_string('<block />');
foreach ($certain as $method) {
$block->appendChild($dom->createComment("\n " . $this->_getDocumentation($method) . "\n "));
$dom_action = $dom->createElement('action');
$block->appendChild($dom_action);
$dom_attr = $dom->createAttribute('method');
$dom_attr->value = $method->getName();
$dom_action->appendChild($dom_attr);
$this->addParamsToDomActionNodeFromReflectionMethod($dom, $dom_action, $method);
//$action = $this->addParamsToActionNodeFromReflectionMethod($action, $method);
}
$dom->formatOutput = true;
return $this->_extraXmlFormatting($dom->saveXml());
}
示例2: makeXml
function makeXml($dbObject)
{
header("Content-Type: application/xml");
$doc = new DomDocument('1.0', 'UTF-8');
$uid = $doc->createElement('uid');
for ($i = 0; $i < $dbObject->rowCount(); $i++) {
$result = $dbObject->fetch();
if ($i === 0) {
$id = $doc->createAttribute('id');
$id->value = $result['usernum'];
$uid->appendChild($id);
$doc->appendChild($uid);
}
$prefix = array($result['num'], $result['in_out'], $result['type'], $result['amount'], $result['time'], $result['detail']);
list($tnum, $inout, $type, $amount, $time, $detail) = $prefix;
$trade_num = $doc->createElement('tnum');
$tr_att = $doc->createAttribute('nu');
$tr_att->value = $tnum;
$trade_num->appendChild($tr_att);
$trade_num->appendChild($doc->createElement('inout', $inout));
$trade_num->appendChild($doc->createElement('type', $type));
$trade_num->appendChild($doc->createElement('amount', $amount));
$trade_num->appendChild($doc->createElement('time', $time));
$trade_num->appendChild($doc->createElement('detail', $detail));
$uid->appendChild($trade_num);
}
$xml = $doc->saveXML();
print $xml;
}
示例3: manipulate
/**
* General manipulate wrapper method.
*
* @param string $input The XML fragment to be manipulated. We are only
* interested in the <extension><CSVData> fragment added in the
* MIK mappings file.
*
* @return string
* One of the manipulated XML fragment, the original input XML if the
* input is not the fragment we are interested in, or an empty string,
* which as the effect of removing the empty <extension><CSVData>
* fragement from our MODS (if there was an error, for example, we don't
* want empty extension elements in our MODS documents).
*/
public function manipulate($input)
{
$dom = new \DomDocument();
$dom->loadxml($input, LIBXML_NSCLEAN);
// Test to see if the current fragment is <extension><CSVData>.
$xpath = new \DOMXPath($dom);
$csvdatas = $xpath->query("//extension/CSVData");
// There should only be one <CSVData> fragment in the incoming
// XML. If there is 0 or more than 1, return the original.
if ($csvdatas->length === 1) {
$csvdata = $csvdatas->item(0);
$csvid = $dom->createElement('id_in_csv', $this->record_key);
$csvdata->appendChild($csvid);
$timestamp = date("Y-m-d H:i:s");
// Add the <CSVRecord> element.
$csvrecord = $dom->createElement('CSVRecord');
$now = $dom->createAttribute('timestamp');
$now->value = $timestamp;
$csvrecord->appendChild($now);
$mimetype = $dom->createAttribute('mimetype');
$mimetype->value = 'application/json';
$csvrecord->appendChild($mimetype);
try {
$metadata_path = $this->settings['FETCHER']['temp_directory'] . DIRECTORY_SEPARATOR . $this->record_key . '.metadata';
$metadata_contents = file_get_contents($metadata_path);
$metadata_contents = unserialize($metadata_contents);
$metadata_contents = json_encode($metadata_contents);
} catch (Exception $e) {
$message = "Problem creating <CSVRecord> element for object " . $this->record_key . ":" . $e->getMessage();
$this->log->addInfo("AddCsvData", array('CSV metadata warning' => $message));
return '';
}
// If the metadata contains the CDATA end delimiter, log and return.
if (preg_match('/\\]\\]>/', $metadata_contents)) {
$message = "CSV metadata for object " . $this->record_key . ' contains the CDATA end delimiter ]]>';
$this->log->addInfo("AddCsvData", array('CSV metadata warning' => $message));
return '';
}
// If we've made it this far, add the metadata to <CcvData> as
// CDATA and return the modified XML fragment.
if (strlen($metadata_contents)) {
$cdata = $dom->createCDATASection($metadata_contents);
$csvrecord->appendChild($cdata);
$csvdata->appendChild($csvrecord);
}
return $dom->saveXML($dom->documentElement);
} else {
// If current fragment is not <extension><CSVData>, return it
// unmodified.
return $input;
}
}
示例4: buildXml
/**
* Build the validate address request
* @return string
* @throws \SimpleUPS\Api\MissingParameterException
*/
public function buildXml()
{
if (serialize($this->getAddress()) == serialize(new Address())) {
throw new MissingParameterException('Address requires a Country code, Postal code, and either a City or State\\Province code');
}
if ($this->getAddress()->getCountryCode() === null) {
throw new MissingParameterException('Address requires a Country code');
}
if ($this->getAddress()->getPostalCode() === null) {
throw new MissingParameterException('Address requires a Postal code');
}
$dom = new \DomDocument('1.0');
$dom->formatOutput = $this->getDebug();
$dom->appendChild($addressRequest = $dom->createElement('AddressValidationRequest'));
$addressRequestLang = $dom->createAttribute('xml:lang');
$addressRequestLang->value = parent::getXmlLang();
$addressRequest->appendChild($request = $dom->createElement('Request'));
$request->appendChild($transactionReference = $dom->createElement('TransactionReference'));
$transactionReference->appendChild($dom->createElement('CustomerContext', $this->getCustomerContext()));
$transactionReference->appendChild($dom->createElement('XpciVersion', $this->getXpciVersion()));
$request->appendChild($dom->createElement('RequestAction', 'AV'));
$addressRequest->appendChild($address = $dom->createElement('Address'));
if ($this->getAddress()->getCity() != null) {
$address->appendChild($dom->createElement('City', $this->getAddress()->getCity()));
}
if ($this->getAddress()->getStateProvinceCode() != null) {
$address->appendChild($dom->createElement('StateProvinceCode', $this->getAddress()->getStateProvinceCode()));
}
if ($this->getAddress()->getPostalCode() != null) {
$address->appendChild($dom->createElement('PostalCode', $this->getAddress()->getPostalCode()));
}
$address->appendChild($dom->createElement('CountryCode', $this->getAddress()->getCountryCode()));
$xml = parent::buildAuthenticationXml() . $dom->saveXML();
return $xml;
}
示例5: buildXml
/**
* Build the validate address request
* @internal
* @return string
* @throws \SimpleUPS\Api\MissingParameterException
*/
public function buildXml()
{
if ($this->getShipment()->getDestination() == null) {
throw new MissingParameterException('Shipment destination is missing');
}
$dom = new \DomDocument('1.0');
$dom->formatOutput = $this->getDebug();
$dom->appendChild($ratingRequest = $dom->createElement('RatingServiceSelectionRequest'));
$addressRequestLang = $dom->createAttribute('xml:lang');
$addressRequestLang->value = parent::getXmlLang();
$ratingRequest->appendChild($request = $dom->createElement('Request'));
$request->appendChild($transactionReference = $dom->createElement('TransactionReference'));
$transactionReference->appendChild($dom->createElement('CustomerContext', $this->getCustomerContext()));
$request->appendChild($dom->createElement('RequestAction', 'Rate'));
$request->appendChild($dom->createElement('RequestOption', 'Shop'));
//@todo test with "Rate" as setting to determine difference
$ratingRequest->appendChild($pickupType = $dom->createElement('PickupType'));
$pickupType->appendChild($shipmentType = $dom->createElement('Code', $this->getPickupType()));
if ($this->getRateType() != null) {
$ratingRequest->appendChild($customerClassification = $dom->createElement('CustomerClassification'));
$customerClassification->appendChild($dom->createElement('Code', $this->getRateType()));
}
// Shipment
$shipment = $this->getShipment();
$shipment->setShipper(UPS::getShipper());
$ratingRequest->appendChild($shipment->toXml($dom));
$xml = parent::buildAuthenticationXml() . $dom->saveXML();
return $xml;
}
示例6: createFiles
public function createFiles($fileName = '', $startTag = '')
{
$filePath = SITEMAP_PATH . $fileName;
if (!file_exists($filePath)) {
fopen($filePath, 'w');
$objDom = new DomDocument('1.0');
$objDom->preserveWhiteSpace = true;
$objDom->formatOutput = true;
$xml = file_get_contents($filePath);
if ($xml != '') {
$objDom->loadXML($xml, LIBXML_NOBLANKS);
}
$objDom->encoding = 'UTF-8';
$objDom->formatOutput = true;
$objDom->preserveWhiteSpace = false;
$root = $objDom->createElement($startTag);
$objDom->appendChild($root);
$root_attr = $objDom->createAttribute("xmlns");
$root->appendChild($root_attr);
$root_attr_text = $objDom->createTextNode("http://www.sitemaps.org/schemas/sitemap/0.9");
$root_attr->appendChild($root_attr_text);
file_put_contents($filePath, $objDom->saveXML());
return true;
}
}
示例7: create
public static function create($vastVersion = '2.0')
{
$xml = new \DomDocument('1.0', 'UTF-8');
// root
$root = $xml->createElement('VAST');
$xml->appendChild($root);
// version
$vastVersionAttribute = $xml->createAttribute('version');
$vastVersionAttribute->value = $vastVersion;
$root->appendChild($vastVersionAttribute);
// return
return new self($xml);
}
示例8: addComment
function addComment($CommentFile, $date_value, $author_value, $subject_value, $msg_value, $ip)
{
$xml = new DomDocument('1.0', 'utf-8');
if (file_exists($CommentFile)) {
$xml->load($CommentFile);
$root = $xml->firstChild;
} else {
$root = $xml->appendChild($xml->createElement("comments"));
}
$comment = $xml->createElement("comment");
$root->appendChild($comment);
// Add date attribute
$attr_date = $xml->createAttribute("timestamp");
$comment->appendChild($attr_date);
$value = $xml->createTextNode($date_value);
$attr_date->appendChild($value);
// Add author attribute
$attr_author = $xml->createAttribute("author");
$comment->appendChild($attr_author);
$value = $xml->createTextNode($author_value);
$attr_author->appendChild($value);
// Add author ip address
$attr_ip = $xml->createAttribute("ip");
$comment->appendChild($attr_ip);
$value = $xml->createTextNode($ip);
$attr_ip->appendChild($value);
// add subject child node
$subject = $xml->createElement("subject");
$comment->appendChild($subject);
$value = $xml->createTextNode($subject_value);
$subject->appendChild($value);
// add message child node
$msg = $xml->createElement("message");
$comment->appendChild($msg);
$value = $xml->createTextNode($msg_value);
$msg->appendChild($value);
$xml->save($CommentFile);
return $xml->getElementsByTagName("comment")->length;
}
示例9: displayXmlError
/**
*
* @param DomNode $node
* @param array $error
*/
public function displayXmlError($node, $error)
{
$a = $this->errors->createAttribute("line");
$t = $this->errors->createAttribute("code");
$m = $this->errors->createTextNode(trim($error->message));
$node->appendChild($a);
$node->appendChild($t);
$node->appendChild($m);
$node->setAttribute("line", $error->line);
switch ($error->level) {
case LIBXML_ERR_WARNING:
$node->setAttribute("code", $error->code);
break;
case LIBXML_ERR_ERROR:
$node->setAttribute("code", $error->code);
break;
case LIBXML_ERR_FATAL:
$node->setAttribute("code", $error->code);
break;
}
}
示例10: update_dom_xml
function update_dom_xml()
{
global $DBCstruct, $DBCfmt;
foreach ($DBCfmt as $name => $format) {
$struct = $DBCstruct[$name];
$xml = new DomDocument('1.0', 'utf-8');
$file = $xml->createElement('file');
$xname = $xml->createAttribute('name');
$value = $xname->appendChild($xml->createTextNode($name));
$xformat = $xml->createAttribute('format');
$value = $xformat->appendChild($xml->createTextNode($format));
for ($i = 0; $i < strlen($format); $i++) {
$field = $xml->createElement('field');
$sid = $xml->createAttribute('id');
$value = $sid->appendChild($xml->createTextNode($i));
$count = @is_array($struct[$i]) ? $struct[$i][1] : 1;
$scount = $xml->createAttribute('count');
$value = $scount->appendChild($xml->createTextNode($count > 1 ? $count : 1));
$key = @(is_array($struct[$i]) && $struct[$i][1] == INDEX_PRIMORY_KEY) ? 1 : 0;
$skey = $xml->createAttribute('key');
$value = $skey->appendChild($xml->createTextNode($key));
$type = get_type($format[$i]);
$stype = $xml->createAttribute('type');
$value = $stype->appendChild($xml->createTextNode($type));
$text_name = "unk{$i}";
if (isset($struct[$i]) && $struct[$i] != '') {
$text_name = is_array($struct[$i]) ? $struct[$i][0] : $struct[$i];
}
$sname = $xml->createAttribute('name');
$value = $sname->appendChild($xml->createTextNode($text_name));
$field->appendChild($sid);
$field->appendChild($scount);
$field->appendChild($sname);
$field->appendChild($stype);
$field->appendChild($skey);
$file->appendChild($field);
if ($count > 1) {
$i += $count - 1;
}
}
$file->appendChild($xname);
$file->appendChild($xformat);
$xml->appendChild($file);
$xml->formatOutput = true;
$xml->save('xml/' . $name . '.xml');
}
}
示例11: addImportToSchema
/**
* Add xsd:import tag to XML schema before any childs added
*
* @param string $namespace Namespace URI
* @param string $code Shortcut for namespace, fx, ns0. Returned by getNsCode()
*
* @return void
*/
private function addImportToSchema($namespace, $code)
{
if (array_key_exists($namespace, $this->docNamespaces)) {
if (in_array($namespace, $this->importedNamespaces)) {
return;
}
//$dom = $this->wsdl->toDomDocument();
//print_r($namespace);
$this->dom->createAttributeNs($namespace, $code . ":definitions");
$importEl = $this->dom->createElement($this->xmlSchemaPreffix . ":import");
$nsAttr = $this->dom->createAttribute("namespace");
$txtNode = $this->dom->createTextNode($namespace);
$nsAttr->appendChild($txtNode);
$nsAttr2 = $this->dom->createAttribute("schemaLocation");
$schemaLocation = $this->getSchemaLocation($namespace);
$publicSchema = $this->copyToPublic($schemaLocation, true);
$publicSchema = $this->copyToPublic($schemaLocation, true);
$schemaUrl = $this->importsToAbsUrl($publicSchema, $this->getSchemasPath());
$txtNode2 = $this->dom->createTextNode($schemaUrl);
$nsAttr2->appendChild($txtNode2);
$importEl->appendChild($nsAttr);
$importEl->appendChild($nsAttr2);
//$this->wsdl->getSchema();
//$xpath = new \DOMXPath($this->dom);
//$query = "//*[local-name()='types']/child::*/*";
//$firstElement = $xpath->query($query);
//if (!is_object($firstElement->item(0))) {
// $query = "//*[local-name()='types']/child::*";
// $schema = $xpath->query($query);
// $schema->item(0)->appendChild($importEl);
//} else {
// $this->wsdl->getSchema()->insertBefore($importEl, $firstElement->item(0));
//}
//$this->xmlSchemaImports
//$this->wsXmlSchema->appendChild();
array_push($this->xmlSchemaImports, $importEl);
array_push($this->importedNamespaces, $namespace);
}
}
示例12: buildXml
/**
* Build the validate address request
* @return string
* @throws \SimpleUPS\Api\MissingParameterException
*/
public function buildXml()
{
if ($this->getTrackingNumber() === null) {
throw new MissingParameterException('Tracking lookup requires either a tracking number');
}
$dom = new \DomDocument('1.0');
$dom->formatOutput = $this->getDebug();
$dom->appendChild($trackingRequest = $dom->createElement('TrackRequest'));
$addressRequestLang = $dom->createAttribute('xml:lang');
$addressRequestLang->value = parent::getXmlLang();
$trackingRequest->appendChild($request = $dom->createElement('Request'));
$request->appendChild($transactionReference = $dom->createElement('TransactionReference'));
$transactionReference->appendChild($dom->createElement('CustomerContext', $this->getCustomerContext()));
$request->appendChild($dom->createElement('RequestAction', 'Track'));
$request->appendChild($dom->createElement('RequestOption', '1'));
$trackingRequest->appendChild($shipmentType = $dom->createElement('ShipmentType'));
$shipmentType->appendChild($shipmentType = $dom->createElement('Code', \SimpleUPS\Track\Request::TYPE_SMALL_PACKAGE));
if ($this->getTrackingNumber() !== null) {
$trackingRequest->appendChild($dom->createElement('TrackingNumber', $this->getTrackingNumber()));
}
$xml = parent::buildAuthenticationXml() . $dom->saveXML();
return $xml;
}
示例13: addG
function addG($nom, $UID)
{
$xmldoc = new DomDocument('1.0');
$xmldoc->preserveWhiteSpace = false;
$xmldoc->formatOutput = true;
if ($xml = file_get_contents('../Ressources/Groupes.xml')) {
$xmldoc->loadXML($xml, LIBXML_NOBLANKS);
// find the headercontent tag
$root = $xmldoc->getElementsByTagName('Groupes')->item(0);
// create the <product> tag
$categ = $xmldoc->createElement('Groupe');
$numAttribute = $xmldoc->createAttribute("id");
$numAttribute->value = maxId("Groupes");
$categ->appendChild($numAttribute);
// add the product tag before the first element in the <headercontent> tag
$root->insertBefore($categ, $root->firstChild);
// create other elements and add it to the <product> tag.
$nameElement = $xmldoc->createElement('nom');
$categ->appendChild($nameElement);
$nameText = $xmldoc->createTextNode($nom);
$nameElement->appendChild($nameText);
$nameElement = $xmldoc->createElement('GID');
$categ->appendChild($nameElement);
$nameText = $xmldoc->createTextNode("");
$nameElement->appendChild($nameText);
$nameElement = $xmldoc->createElement('UID');
$categ->appendChild($nameElement);
$nameText = $xmldoc->createTextNode($UID);
$nameElement->appendChild($nameText);
$xmldoc->save('../Ressources/Groupes.xml');
}
}
示例14: count
function write_resource_on_xml_element(DomDocument $dom, $uri, DomElement $el, $parentUris)
{
/* resource ID */
if ($this->node_is_blank($uri)) {
$idAttr = $dom->createAttribute('id');
} else {
$idAttr = $dom->createAttribute('href');
}
$idAttr->appendChild($dom->createTextNode($uri));
if (!empty($uri)) {
$el->appendChild($idAttr);
}
$index = $this->get_index();
$isPrimaryTopicSameAsResult = ($el->tagName == 'primaryTopic' and count($parentUris) == 1);
if (!in_array($uri, $parentUris) || $isPrimaryTopicSameAsResult) {
$resourceProperties = array(FOAF . 'primaryTopic', FOAF . 'isPrimaryTopicOf', API . 'definition', DCT . 'hasFormat', DCT . 'hasVersion');
$parentUris[] = $uri;
$properties = $this->get_subject_properties($uri);
arsort($properties);
//producing predictable output
foreach ($properties as $property) {
if (!$isPrimaryTopicSameAsResult || !in_array($property, $resourceProperties)) {
$propertyName = $this->get_short_name_for_uri($property);
$propEl = $dom->createElement($propertyName);
$propValues = $index[$uri][$property];
if (count($propValues) > 1 || $this->propertyIsMultiValued($property)) {
foreach ($propValues as $val) {
$item = $dom->createElement('item');
$item = $this->write_rdf_value_to_xml_element($dom, $val, $item, $uri, $property, $parentUris);
$propEl->appendChild($item);
}
} else {
if (count($propValues) == 1) {
$val = $propValues[0];
$propEl = $this->write_rdf_value_to_xml_element($dom, $val, $propEl, $uri, $property, $parentUris);
}
}
$el->appendChild($propEl);
}
}
}
return $el;
}
示例15:
}
if ($header == 'mobile_03') {
$mobile_03 = $row[$i];
}
if ($header == 'fax_03') {
$fax_03 = $row[$i];
}
if ($header == 'other_03') {
$other_03 = $row[$i];
}
}
//Begin building XML
$UR = $root->appendChild($xmlDoc->createElement('user'));
// Parent Element
$rectypeATTR = $UR->appendChild($xmlDoc->createElement("record_type", "PUBLIC"));
$x = $xmlDoc->createAttribute('desc');
$x->value = "Public";
$rectypeATTR->appendChild($x);
$UR->appendChild($rectypeATTR);
if (isset($primary_id) && $primary_id != "NULL") {
$UR->appendChild($xmlDoc->createElement("primary_id", $primary_id));
}
if (isset($first_name) && $first_name != "NULL") {
$UR->appendChild($xmlDoc->createElement("first_name", $first_name));
$full_name = $first_name;
}
if (isset($middle_name) && $middle_name != "NULL") {
$UR->appendChild($xmlDoc->createElement("middle_name", $middle_name));
if (isset($full_name)) {
$full_name .= " {$middle_name}";
} else {