/** * * @param XmlElement $xml */ public function parseAttributes($xml) { $this->attributes = $xml->getAttributes(); foreach ($this->attributes as $name => $value) { $key = strtolower(trim($name)); $this->attributesMap[$key] = $name; } }
/** * @param XmlElement $toAppend * @param boolean $root * @return void */ public function appendChild($toAppend, $root = false) { if ($root) { $node = $this->addChild($toAppend->getName()); foreach ($toAppend->attributes() as $key => $value) { $node->addAttribute($key, $value); } $node->appendChild($toAppend); } else { foreach ($toAppend as $name => $tree) { $child = $this->addChild($name, $this->_fixContent(strval($tree))); foreach ($tree->attributes() as $attrKey => $attrValue) { $child->addAttribute($attrKey, $attrValue); } $child->appendChild($tree->children()); } } }
/** * Asserts that the supplied <tt>XML</tt> represents a valid * <tt>*lt;object></tt>. * @param XmlElement $xml * @throws \NullPointerException if the passed <tt>$xml</tt> is null. * @throws \InvalidArgumentException if the <tt>$xml</tt> is invalud. * @see \Rhapsody\SetupBundle\Parser\ObjectParser::assert() */ public function assert($xml) { if ($xml === null) { throw new \NullPointerException('Unable to parse: null.'); } if (!$xml instanceof XmlElement) { throw new \InvalidArgumentException('Invalid input. ' . get_class($this) . ' expects an XmlElement'); } $name = $xml->getName(); if (!in_array(strtolower($name), $this->elements)) { throw new \InvalidArgumentException('The element: ' . $name . ' was not a valid object-element and could not be parsed by ' . get_class($this) . '.'); } $className = $xml->getAttribute('class'); $ref = $xml->getAttribute('ref'); if (empty($className) && empty($ref)) { throw new \InvalidArgumentException('An object must have either the "class" or "ref" attributes specified. Could not find either attributes in XML: ' . strval($xml)); } }
public function testGetValueTextNode() { $xml = '<element>value</element>'; $element = new XmlElement($xml); $result = $element->getValue(); $this->assertNotNull($result); $this->assertEquals('value', $result); }
public function testGetEmptyArrayValue() { $file = $this->getResource(XmlDataSourceTest::TEST_DATA_FILE); $dataSource = new XmlDataSource($file, $this->getPopulator()); // ** Assert type derivation for array... $xml = '<property name="test"><array></array></property>'; $element = new XmlElement($xml); // ** Confirm that the first child is not null, and does in fact exist... $firstChild = $element->getFirstChild(); $this->assertNotNull($firstChild); $this->assertEquals('array', $firstChild->getName()); // ** Process value from populator's getValue() method.. $value = $dataSource->getValue($element); $this->assertEquals(array(), $value); }
/** * <p> * Parse all of the <tt><property></tt> elements from a the specified * <tt>XML</tt> <tt>$element</tt>, and return an array of * {@link Rhapsody\SetupBundle\Model\Property} objects. * </p> * * @param XmlElement $element the XML element fro which to parse properties. * @return array an array of <code>Property</code> objects. */ public function parseProperties(XmlElement $element) { $properties = array(); $elements = $element->get('property', false); foreach ($elements as $prop) { $property = $this->parseProperty($prop); array_push($properties, $property); } return $properties; }