php - Creating attribute in domdocument -


मुझे इस प्रकार का एक्सएमएल बनाना है: -

  & lt;? Xml संस्करण = "1.0" एन्कोडिंग = "यूटीएफ -8"? & Gt; & lt; urlset xmlns = "http://www.sitemaps.org/schemas/sitemap/0.9" & gt; & LT; यूआरएल & gt; & Lt; loc & gt; http: //www.example.com/< / loc & gt; & LT; lastmod & gt; 2005-01-01 & lt; / lastmod & gt; & LT; changefreq & gt; मासिक & lt; / changefreq & gt; & LT; प्राथमिकता & gt; 0.8 & lt; / प्राथमिकता & gt; & Lt; / यूआरएल & gt; & LT; यूआरएल & gt; & Lt; loc & gt; http: //www.example.com/catalog आइटम = 12 & amp; amp; desc = vacation_hawaii & lt; / loc & gt; & LT; changefreq & gt; साप्ताहिक & lt; / changefreq & gt; & Lt; / यूआरएल & gt; & Lt; / urlset & gt;   

जिसके लिए मैंने यह कोड लिखा है,

  $ dom = new domDocument ('1.0', 'utf-8'); $ dom- & gt; formatOutput = true; $ रूट एलेमेंट = $ dom- & gt; बनाएँ एलेमेंटएन ('http://www.sitemaps.org/schemas/sitemap/0.9', 'urlset'); $ Sxe = simplexml_import_dom ($ dom); $ urlMain = $ sxe- & gt; जोड़ें चाल्ड ("url"); $ Loc = $ urlMain- & gt; जोड़ें चाल्ड ("loc", "http://www.example.com"); $ आखिरी मिनट = $ urlMain- & gt; जोड़ें चाल्ड ("आखिरी मिनट", "$ तारीख"); $ Changefreq = $ url मैन- & gt; जोड़ें चाल्ड ("changefreq", "दैनिक"); $ प्राथमिकता = $ urlMain- & gt; जोड़ें चाल्ड ("प्राथमिकता", "1");   

सबकुछ पूरी तरह से ठीक है, लेकिन कुछ कारणों से xmlns urlset के लिए जोड़ा नहीं जा रहा है। यहाँ क्या गलत हो सकता है? कोई भी सुझाव सहायक हो सकता है।

आपको simplexml के रूपांतरण से पहले दस्तावेज में मूल तत्व जोड़ना होगा : <पूर्व> $ rootElement = $ dom- & gt; बनाएँ ElementNS ('http://www.sitemaps.org/schemas/sitemap/0.9', 'urlset'); $ Dom- & gt; appendChild ($ rootElement); $ sxe = simplexml_import_dom ($ dom);

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

php - How can I cram 6+31 numeric characters into 22 alphanumeric characters? -

mysql - where clause in inner join query -