本文整理匯總了PHP中DOMNode::setAttributeNodeNs方法的典型用法代碼示例。如果您正苦於以下問題:PHP DOMNode::setAttributeNodeNs方法的具體用法?PHP DOMNode::setAttributeNodeNs怎麽用?PHP DOMNode::setAttributeNodeNs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DOMNode
的用法示例。
在下文中一共展示了DOMNode::setAttributeNodeNs方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: encode
public function encode($variable, \DOMNode $node, Type $type)
{
if ($type instanceof AbstractComplexType) {
foreach ($type->getAttributes() as $attribute) {
$val = self::getValueFrom($variable, $attribute->getName());
if ($val !== null) {
if ($attribute->getQualification() == "qualified") {
$attributeNode = $node->ownerDocument->ocreateAttributeNS($attribute->getNs(), $node->getPrefixFor($attribute->getNs()) . ":" . $attribute->getName());
$node->setAttributeNodeNs($attributeNode);
} else {
$attributeNode = $node->ownerDocument->createAttribute($attribute->getName());
$node->setAttributeNode($attributeNode);
}
$this->convertSimplePhpXml($val, $attributeNode, $attribute->getType());
} elseif ($attribute->isRequred()) {
throw new \Exception("Type {$type}, attributo " . $attribute . " non deve essere vuoto");
}
}
if ($type->getBase()) {
$this->encode($variable, $node, $type->getBase());
}
if ($type instanceof ComplexType) {
foreach ($type->getElements() as $element) {
$elementQualified = $element->getQualification() == "qualified";
$newType = $element->getType();
if ($element->getMax() > 1 && ($val = self::tryGetValueFrom($variable, $element->getName())) && (is_array($val) || $val instanceof \Traversable)) {
foreach ($val as $nval) {
if ($elementQualified) {
$newNode = $node->addPrefixedChild($element->getNs(), $element->getName());
} else {
$newNode = $node->addChild($element->getName());
}
$this->encode($nval, $newNode, $newType);
}
} elseif ($element->getMax() > 1 && (is_array($variable) || $variable instanceof \Traversable)) {
foreach ($variable as $nval) {
if ($elementQualified) {
$newNode = $node->addPrefixedChild($element->getNs(), $element->getName());
} else {
$newNode = $node->addChild($element->getName());
}
$this->encode($nval, $newNode, $newType);
}
} else {
$val = self::getValueFrom($variable, $element->getName());
if ($val !== null || $element->isNillable()) {
if ($elementQualified) {
$newNode = $node->addPrefixedChild($element->getNs(), $element->getName());
} else {
$newNode = $node->addChild($element->getName());
}
if ($val === null) {
$newNode->setAttributeNS(self::NS_XSI, $newNode->getPrefixFor(self::NS_XSI) . ":nil", "true");
} else {
$this->encode($val, $newNode, $newType);
}
} elseif ($element->getMin() > 0) {
throw new \Exception($element . " non deve essere vuoto");
}
}
}
}
}
if ($type instanceof SimpleType) {
$this->convertSimplePhpXml($variable, $node, $type);
}
}