66 $document =
new DOMDocument();
68 $oldLibXmlErrors = libxml_use_internal_errors(
true );
70 $oldDisable = @libxml_disable_entity_loader(
true );
71 $ok = $document->loadXML( $xml, LIBXML_NONET );
74 $errors = libxml_get_errors();
75 libxml_use_internal_errors( $oldLibXmlErrors );
77 @libxml_disable_entity_loader( $oldDisable );
79 foreach ( $errors as $error ) {
81 throw new InvalidArgumentException(
82 'Malformed XML: ' . $error->message .
' in line ' . $error->line
86 throw new InvalidArgumentException(
'Malformed XML!' );
89 libxml_use_internal_errors( $oldLibXmlErrors );
91 @libxml_disable_entity_loader( $oldDisable );
92 $sites = $this->makeSiteList( $document->documentElement );
93 $this->store->saveSites( $sites );
139 public function makeSite( DOMElement $siteElement ) {
140 if ( $siteElement->tagName !==
'site' ) {
141 throw new InvalidArgumentException(
'Expected <site> tag, found ' . $siteElement->tagName );
145 $site = $this->siteSanitizer->newSiteForType( $type );
147 $site->setGlobalId( $this->getChildText( $siteElement,
'globalid' ) );
148 $site->setGroup( $this->getChildText( $siteElement,
'group',
Site::GROUP_NONE ) );
149 $site->setLanguageCode( $this->getChildText( $siteElement,
'language',
null ) );
151 $pathTags = $siteElement->getElementsByTagName(
'path' );
152 for ( $i = 0; $i < $pathTags->length; $i++ ) {
153 $pathElement = $pathTags->item( $i );
154 '@phan-var DOMElement $pathElement';
155 $pathType = $this->getAttributeValue( $pathElement,
'type' );
156 $path = $pathElement->textContent;
158 $site->setPath( $pathType,
$path );
161 $idTags = $siteElement->getElementsByTagName(
'localid' );
162 for ( $i = 0; $i < $idTags->length; $i++ ) {
163 $idElement = $idTags->item( $i );
164 '@phan-var DOMElement $idElement';
165 $idType = $this->getAttributeValue( $idElement,
'type' );
166 $id = $idElement->textContent;
168 $site->addLocalId( $idType, $id );
174 $this->siteSanitizer->sanitizeSite( $site );