82 $document =
new DOMDocument();
84 $oldLibXmlErrors = libxml_use_internal_errors(
true );
85 $oldDisable = libxml_disable_entity_loader(
true );
86 $ok = $document->loadXML( $xml, LIBXML_NONET );
89 $errors = libxml_get_errors();
90 libxml_use_internal_errors( $oldLibXmlErrors );
91 libxml_disable_entity_loader( $oldDisable );
93 foreach ( $errors as $error ) {
95 throw new InvalidArgumentException(
96 'Malformed XML: ' . $error->message .
' in line ' . $error->line
100 throw new InvalidArgumentException(
'Malformed XML!' );
103 libxml_use_internal_errors( $oldLibXmlErrors );
104 libxml_disable_entity_loader( $oldDisable );
126 $oldSites = $this->store->getSites();
128 $current = $root->firstChild;
130 if ( $current instanceof DOMElement && $current->tagName ===
'site' ) {
132 $site = $this->
makeSite( $current );
133 $key = $site->getGlobalId();
135 if ( $oldSites->hasSite( $key ) ) {
136 $oldSite = $oldSites->getSite( $key );
137 $site->setInternalId( $oldSite->getInternalId() );
140 $sites[$key] = $site;
141 }
catch ( Exception $ex ) {
146 $current = $current->nextSibling;
158 public function makeSite( DOMElement $siteElement ) {
159 if ( $siteElement->tagName !==
'site' ) {
160 throw new InvalidArgumentException(
'Expected <site> tag, found ' . $siteElement->tagName );
166 $site->setForward( $this->
hasChild( $siteElement,
'forward' ) );
167 $site->setGlobalId( $this->
getChildText( $siteElement,
'globalid' ) );
171 $pathTags = $siteElement->getElementsByTagName(
'path' );
172 for ( $i = 0; $i < $pathTags->length; $i++ ) {
173 $pathElement = $pathTags->item( $i );
175 $path = $pathElement->textContent;
177 $site->setPath( $pathType, $path );
180 $idTags = $siteElement->getElementsByTagName(
'localid' );
181 for ( $i = 0; $i < $idTags->length; $i++ ) {
182 $idElement = $idTags->item( $i );
184 $id = $idElement->textContent;
186 $site->addLocalId( $idType, $id );
227 private function getChildText( DOMElement $element, $name, $default =
false ) {
228 $elements = $element->getElementsByTagName( $name );
230 if ( $elements->length < 1 ) {
231 if ( $default !==
false ) {
235 'Required <' . $name .
'> tag not found inside <' . $element->tagName .
'> tag'
240 $node = $elements->item( 0 );
241 return $node->textContent;