Ejemplo n.º 1
0
 /**
  * Create a new parser for the specified path, which will be validated against the XSD before parsing
  * For better speed and memory usage, parsing page/custom attributes can be skipped if you don't need them
  *
  * @param $path
  * @param $skipAttributes
  * @throws XmlException
  */
 public function __construct($path, $skipAttributes = false)
 {
     // validate before opening with reader, since validation converts line breaks such as `</product>\n\n</product>`
     // to `</product>\n</product>` which avoids creating empty nodes or confusing `parse()` and skipping data :-o
     Xml::validate($path);
     $reader = new XMLReader();
     if (!$reader->open($path)) {
         throw new XmlException('Error opening ' . $path);
     }
     $this->skipAttributes = $skipAttributes;
     $this->parse($reader);
 }
Ejemplo n.º 2
0
 public function testValidateTaxonomySample()
 {
     $xmlPath = __DIR__ . '/fixtures/taxonomy-sample.xml';
     $this->assertTrue(Xml::validate($xmlPath));
 }
Ejemplo n.º 3
0
 /**
  * Save the document to a path, which must include the appropriate extension (likely .xml)
  *
  * @param $fileName
  * @throws XmlException
  */
 public function save($path)
 {
     $this->build();
     $results = $this->dom->save($path);
     Xml::validate($path);
     return $results > 0;
 }
Ejemplo n.º 4
0
 /**
  * @expectedException       \DemandwareXml\XmlException
  * @expectedExceptionRegExp /xmlParseEntityRef: no name/
  */
 public function testValidateInvalidXml()
 {
     $xmlPath = __DIR__ . '/fixtures/invalid_items.xml';
     $this->assertFalse(Xml::validate($xmlPath));
 }