472,342 Members | 1,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,342 software developers and data experts.

How to replace a perticular tag's content of an xml file with < instead of &lt; ?

Expand|Select|Wrap|Line Numbers
  1. <contact_us_client_email>
  2.     <message>
  3.         &lt;![CDATA[&lt;link href=\"http:/www.blurbpoint.com/style1.css\" rel=\"stylesheet\" type=\"text/css\" /&gt;
  4. &lt;div style=\"width: 900px; margin-left: auto; margin-right: auto;\"&gt;
  5.     &lt;div style=\"width: 900px; height: 100px; float: left; margin: 0pt 0pt 0pt 0px;\"&gt;
  6.         &lt;img src=\"http://www.blurbpoint.com/images/header.gif\" /&gt;&lt;/div&gt;
  7.     &lt;div style=\"width: 898px; float: left; margin: 0pt 0pt 0pt 0px; border-left: 1px solid rgb(197, 197, 197); border-right: 1px solid rgb(197, 197, 197);\"&gt;
  8.         &lt;div style=\"width: 900px; float: left; margin: 15px 0pt 0pt 0px; padding: 0pt 0pt 0pt 0px;\"&gt;
  9.             &lt;div style=\"width: 840px; font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 12px; color: rgb(35, 35, 35); margin: 0pt 0pt 0pt 14px; line-height: 16px;\"&gt;
  10.                 We have Sucessfully Received Your Inquiry. We will contact you.&lt;/div&gt;
  11.         &lt;/div&gt;
  12.         &lt;div style=\"width: 868px; float: left; margin: 15px 0pt 0pt 15px;\"&gt;
  13.             &lt;div style=\"width: 868px; float: left; font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 25px; color: rgb(6, 91, 157);\"&gt;
  14.                 Customer Support&lt;/div&gt;
  15.             &lt;div style=\"border: 1px dashed rgb(140, 140, 140); width: 868px; float: left; margin: 5px 15px 0pt 0px;\"&gt;
  16.                 &lt;div style=\"width: 93px; float: left; margin: 15px 0pt 0pt 7px;\"&gt;
  17.                     &lt;img src=\"http://www.blurbpoint.com/images/customer_support_icon.gif\" /&gt;&lt;/div&gt;
  18.                 &lt;div style=\"width: 753px; float: left; margin: 15px 15px 10px 0px; font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 12px; color: rgb(40, 40, 40); text-decoration: none; line-height: 16px;\"&gt;
  19.                     Thanks a lot for visiting Blurbpoint.Our Customer Relationship Manager will be get back with top notch solutions soon. For any further queries contact support@blurbpoint.com&lt;/div&gt;
  20.             &lt;/div&gt;
  21.         &lt;/div&gt;
  22.         &lt;div style=\"width: 900px; border-top: 1px solid rgb(214, 214, 214); float: left; margin: 10px 0pt 10px 0px;\"&gt;
  23.             ]]&gt;
  24.     </message>
  25.  
  26.     <header>
  27.        <![CDATA[Content-Type: text/html;]]>From: support@blurbpoint.com
  28.     </header>
  29.  
  30. </contact_us_client_email>
  31.  
I am having problem that, after replacement, i did not get < in place of &lt; or > in place of &gt; because after the replacement output doesn't come in ckeditor where as source shows the code correctly but in that code <[CDATA[ comes like <--[CDATA[ So what should be done? My replacement file is like...

Expand|Select|Wrap|Line Numbers
  1. $doc = new DOMDocument;
  2. $doc->load('xml_mail_format2.xml');
  3. $playlist= $doc->documentElement;
  4.  
  5. $track = $playlist->getElementsByTagName("message")->item(0);
  6.  
  7. $newTrack = $doc->createElement('message',"<![CDATA[".$_POST['editor123']."]]>");
  8.  
  9. $oldtrack= $track->parentNode->replaceChild($newTrack,$track);
  10.  
  11. echo $doc->saveXML();
  12.  
  13. $doc->save("xml_mail_format2.xml");
  14.  
In this file $_POST['editor123'] contains the formatted design from ckeditor.
Feb 7 '11 #1

✓ answered by Dormilich

there might be issues with the variable naming, however, I got a compareable test case running:
Expand|Select|Wrap|Line Numbers
  1. $xml = <<<XML
  2. <root>
  3.     <child1/>
  4. </root>
  5. XML;
  6. $doc = new DOMDocument;
  7. $doc->loadXML($xml);
  8.  
  9. $newChild = $doc->createElement('child1');
  10. $newCDATA = $doc->createCDATASection("<track>song 1</track>");
  11. $newChild->appendChild($newCDATA);
  12.  
  13. $oldChild = $doc->getElementsByTagName("child1")->item(0);
  14. $oldChild->parentNode->replaceChild($newChild, $oldChild);
  15.  
  16. echo $doc->saveXML();
output:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <root>
  3.     <child1><![CDATA[<track>song 1</track>]]></child1>
  4. </root>

17 4071
Dormilich
8,658 Expert Mod 8TB
your intention is correct as you need to put the content in a CDATA section. however, a CDATA section is created differently (and because of that, your "CDATA section" is inserted as comment).
a CDATA section in XML is an own node type, therefore you have to create it explicitly: DOMDocument->createCDATASection($textContent);
Feb 7 '11 #2
Thank you very much for the reply. I just test it & then tell you that if it benefits me or not...will post reply soon for this.
Feb 7 '11 #3
Expand|Select|Wrap|Line Numbers
  1. $doc = new DOMDocument;
  2.  
  3. $doc->load('xml_mail_format2.xml');
  4.  
  5. $playlist= $doc->documentElement;
  6.  
  7. $track = $playlist->getElementsByTagName("message")->item(0);
  8.  
  9. $data = $doc->createCDATASection($data);
  10.  
  11. $newTrack = $doc->createElement('message',$data);
  12.  
  13. $oldtrack= $track->parentNode->replaceChild($newTrack,$track);
  14.  
  15. $doc->saveXML();
  16.  
  17. $doc->save("xml_mail_format2.xml");
  18.  
It is giving me 2 errors that :
1)Warning</b>: DOMDocument::createElement() expects parameter 2 to be string, object given

2)Argument 1 passed to DOMNode::replaceChild() must be an instance of DOMNode, null given
Feb 7 '11 #4
Dormilich
8,658 Expert Mod 8TB
the second error is a follow up of the first error.

you attach a CDATA node like any other node (itís not text, after all), by DOMNode->appendChild()
Feb 7 '11 #5
Should I send you the attachment of my xml & php file?
If you permit i send to you...I am waiting for your kind response. Thanks...
Feb 7 '11 #6
Dormilich
8,658 Expert Mod 8TB
why would you need to send me the files?
Feb 7 '11 #7
because i am not getting the thing done.I am still having errors so i asked to you. So if you permit then i will send you the 2 files.
Feb 7 '11 #8
Dormilich
8,658 Expert Mod 8TB
just post the php code (and the error messages) here.
Feb 7 '11 #9
Error Message :- DOMDocument::createElement() expects parameter 2 to be string, object given.
Expand|Select|Wrap|Line Numbers
  1. $data = $_POST['editor123'];
  2.  
  3. $doc = new DOMDocument;
  4.  
  5. $doc->load('xml_mail_format2.xml');
  6.  
  7. $playlist= $doc->documentElement;
  8.  
  9. $track = $playlist->getElementsByTagName("message")->item(0);
  10.  
  11. $data = $doc->createCDATASection($data);
  12.  
  13. $newTrack = $doc->createElement('message',$data);
  14.  
  15. $oldtrack= $track->parentNode->replaceChild($newTrack,$track);
  16.  
  17. $doc->saveXML();
  18.  
  19. $doc->save("xml_mail_format2.xml");
  20.  
Can you tell me what changes should be made in the above code.Thanks in advance.
Feb 7 '11 #10
Dormilich
8,658 Expert Mod 8TB
line #13 omit the second parameter, you do not have applicable text. line #14 append the CDATA node to the newly created <message> node.
Feb 7 '11 #11
Expand|Select|Wrap|Line Numbers
  1. $newTrack = $doc->createElement('message');
  2.  
  3. $newTrack = $newTrack->appendChild($data);
  4.  
  5. $oldtrack= $track->parentNode->replaceChild($newTrack,$track);
  6.  
Will it work?
Feb 7 '11 #12
Dormilich
8,658 Expert Mod 8TB
Will it work?
try it out!
Feb 7 '11 #13
It is not working. It gives error that:
Warning</b>: DOMNode::replaceChild() [<a href='domnode.replacechild'>domnode.replacechild</a>]: Couldn't fetch DOMCdataSection

Can you do something? It is a bit urgent, if you don't mind.
Feb 7 '11 #14
Dormilich
8,658 Expert Mod 8TB
there might be issues with the variable naming, however, I got a compareable test case running:
Expand|Select|Wrap|Line Numbers
  1. $xml = <<<XML
  2. <root>
  3.     <child1/>
  4. </root>
  5. XML;
  6. $doc = new DOMDocument;
  7. $doc->loadXML($xml);
  8.  
  9. $newChild = $doc->createElement('child1');
  10. $newCDATA = $doc->createCDATASection("<track>song 1</track>");
  11. $newChild->appendChild($newCDATA);
  12.  
  13. $oldChild = $doc->getElementsByTagName("child1")->item(0);
  14. $oldChild->parentNode->replaceChild($newChild, $oldChild);
  15.  
  16. echo $doc->saveXML();
output:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <root>
  3.     <child1><![CDATA[<track>song 1</track>]]></child1>
  4. </root>
Feb 7 '11 #15
Thanks very much, I am trying what you have suggested. If error comes i will post reply.Thank you very much for giving me your precious time.
Feb 7 '11 #16
Thank you, Thank you very much. You have solved my question.All praise to you. Thank you once again.
Feb 7 '11 #17
Dormilich
8,658 Expert Mod 8TB
and that only because Iím reasonably good with JavaScript Ö *gg*
Feb 7 '11 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: dpj5754 | last post by:
Is there a simple and determinist way to make the difference between the 2 sequences: <XX></XX> and <XX/> The EndElement callback does...
4
by: higabe | last post by:
Three questions 1) I have a string function that works perfectly but according to W3C.org web site is syntactically flawed because it contains...
0
by: Wolfgang Schwanke | last post by:
Dear usenet, I'm having the following small problem. I've been ask to add some Quicktime panoramas to a website. The author of the panoramas...
7
by: Rocky Moore | last post by:
I have a web site called HintsAndTips.com. On this site people post tips using a very simply webform with a multi line TextBox for inputing the tip...
2
by: Nicky | last post by:
hi, all I know we can do this by some jscript. But is there a way to do it in asp.net c# code? In our project, users could sumit a piece of html...
2
by: andrew007 | last post by:
I do xml / xslt transformation using asp.net but I found any value (w/xml format) in xml node html-encoded to &lt and &gt format if it's > or <...
14
by: Schraalhans Keukenmeester | last post by:
I am building a default sheet for my linux-related pages. Since many linux users still rely on/prefer viewing textmode and unstyled content I try...
6
by: tentstitcher | last post by:
Hi all: I have a source xml document with an element of type string. This element contains something like the following: <stringData> &lt;Header&gt;...
5
by: jhurrell | last post by:
I have been having some trouble getting my XSL style sheet to parse correctly. I have some XML outputted from an SQL-Server, that I then need to...
0
by: bingunginter | last post by:
I am using SQL 2005 server database. In my table I had fields that has chinese character (nvarchar type) and html tag <b></b>. I retrieve the table...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.