2014-05-13 2 views
1

xml doc에 네임 스페이스 특성 'xmlns'를 저장하려고합니다. 다음은 내가 시도한 내용입니다 ..xmlns 속성을 XML 파일에 추가하십시오.

$xml = new DOMDocument(); 
$xml_index = $xml->createElement("urlset"); 
$root->appendChild(
$xml->createAttribute('xmlns'))->appendChild(
$xml->createTextNode('http://www.sitemaps.org/schemas/sitemap/0.9')); 
for ($i = 0; $i < $count; $i++) { 
    $xml_sitemap = $xml->createElement("url"); 
    $xml_loc = $xml->createElement("loc", 'http://test.com/sitemaps/'.$link[$i]); 
    $xml_index->appendChild($xml_sitemap); 
    $xml_sitemap->appendChild($xml_loc); 
} 
$xml_index->appendChild($xml_sitemap); 
$xml_sitemap->appendChild($xml_loc); 
$xml->appendChild($xml_index); 
$xml->save('\tmp\test.xml'); 

누군가 나를 도울 수 있습니까? 내가의 xmlns 특성이없는입니다 얻을 출력

<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> 
    <sitemap> 
      <loc>http://test.com/sitemaps/urlset_start10000.xml</loc> 
    </sitemap> 
    <sitemap> 
      <loc>http://test.com/sitemaps/urlset_start20000.xml</loc> 
    </sitemap> 
</sitemapindex> 

아래 내가 원하는 형식입니다.

답변

0

documentation 같은 상태의에는 createElementNS는 작업을

$dom = new DOMDocument('1.0', 'utf-8'); 
$element = $dom->createElementNS('http://www.example.com/XFoo', 'xfoo:test', 'This is the root element!'); 
$dom->appendChild($element); 
+0

감사를해야한다. 그러나 이것은 그녀가 원하는 것이 아닙니다. 그녀는 xmlns 속성을 값이 아닌 노드에 추가하려고합니다. – atpatil11

관련 문제