0

I've saved javascript code in xml file. but when I get it show as empty xml tag.

The XML Code

<ad>
  <Name> Ad 1 </Name>
  <place> 1 </place>
  <Type> code </Type>
  <content>
     <script type="text/javascript">
      <!--
        google_ad_client = "pub-*********";
        /* 160x600, 28/08/09 */
        google_ad_slot = "*********";
        google_ad_width = 160;
        google_ad_height = 600;
      //-->
     </script>
     <script type="text/javascript"
      src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
     </script>
  </content>
</ad>

When I get the tag content by using PHP DOMDocument I find it empty, and when I checked the page source code, I find it empty no javascript exists. Although when I bring the value of another tag like Name,Type, displays without problems. I have no doubt in PHP code.

hakre
  • 193,403
  • 52
  • 435
  • 836
Lion King
  • 32,851
  • 25
  • 81
  • 143

2 Answers2

0

Your XML is invalid.

Quotes must be &quot; and so on, in your JavaScript. If you don't want to do that, it must be wrapped in a CDATA block.

<script>
<![CDATA[
    ...code...
]]>
</script>

https://stackoverflow.com/a/66900/362536

Community
  • 1
  • 1
Brad
  • 159,648
  • 54
  • 349
  • 530
  • Thanks, I find in the page source code this part of code only `` But the rest of the code does not appear – Lion King Oct 03 '12 at 19:29
  • @LionKing, I don't know what you are asking at this point. You said you had trouble parsing XML. I explained why. – Brad Oct 03 '12 at 19:33
0

The Solution is we must add <![CDATA[ before all javascript and ]]> after all javascript like the following:

<![CDATA[
    <script type="text/javascript">
     <!--
     google_ad_client = "pub-***********";
     /* 160x600, 28/08/09 */
     google_ad_slot = "-***********"";
     google_ad_width = 160;
     google_ad_height = 600;
     //-->          
   </script>
   <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
   </script>
]]>

The final form is as the following:

<ad>
  <Name> Ad 1 </Name>
  <place> 1 </place>
  <Type> code </Type>
  <content>
   <![CDATA[
     <script type="text/javascript">
      <!--
        google_ad_client = "pub-*********";
        /* 160x600, 28/08/09 */
        google_ad_slot = "*********";
        google_ad_width = 160;
        google_ad_height = 600;
      //-->
     </script>
     <script type="text/javascript"
      src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
     </script>
    ]]>
  </content>
</ad>
Lion King
  • 32,851
  • 25
  • 81
  • 143