473,396 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How to replace particular element's content in xml file using php?

Expand|Select|Wrap|Line Numbers
  1. <main_xml>
  2.  <tag1>
  3.   <![CDATA[
  4.     <div id=1>
  5.       Hello
  6.     </div>
  7.  
  8.     <div id=2>
  9.       Hi
  10.     </div>
  11.   ]]>
  12.  </tag1>
  13. </main_xml>
  14.  
I want to change Hi to How are You? What should be done. I want code for this replacement. Thanks in advance.
Feb 16 '11 #1
6 3735
Dormilich
8,658 Expert Mod 8TB
there are two possible ways.
- get the CDATA text and use str_replace()
- get the CDATA text, render it anew as XML, replace the textContent via DOM, import the output of the 2nd XML into the 1st XML

important: a CDATA section is its own node type and everything contained is text.
Feb 16 '11 #2
Thanks very much for your reply but if you provide coding for that, then it would be much easier to me.
Feb 16 '11 #3
Dormilich
8,658 Expert Mod 8TB
practically the same as in your other threads about this XML.
Feb 16 '11 #4
ok. Now can you tell me how to use getElementsById to identify a perticular tag & to echo that div's content. A small example please... Based on my xml file(I want to echo Hi based on id=2). In this how we can use getElementsById function?
Feb 17 '11 #5
Dormilich
8,658 Expert Mod 8TB
if I remember right you have to either parse that XML chunk as HTML or parse it with a DTD that defines id as ID type attribute.
Feb 17 '11 #6
You should read up on the PHP-class called SimpleXML. It's not really simple, but easier to understand and work with than creating your own way to parse your XML-files. http://php.net/manual/en/book.simplexml.php
Feb 17 '11 #7

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

Similar topics

2
by: Sam Kon via .NET 247 | last post by:
Can any one of you let me know, how can I replace a pattern in an html file using C#? I have the contents of the html file stored in a string. I just need to replace some of the elements which have...
0
by: ripal.soni | last post by:
Hi there I am .net developer ,right now working on a project in that i need to print pdf file using vb.net and i also have to pass printer name as argument ,file should be printed on a...
4
by: Bill Nguyen | last post by:
I wonder if I can write to an XML file using column structure (and column names) of an SQLserver table. for example: Table A: column1 int column2 char(30) column3 date XML output:
11
by: Grischa Brockhaus | last post by:
Hi, I'm trying to produce a div layout containing a header on the top with fixed height, a footer on the bottom using fixed height and a content layer using what's left of the browsers window. ...
6
by: gauravkhanna | last post by:
import java.io.*; class Automation1 implements Runnable { int iterationCount=0; Thread t; FileReader fr; //FileWriter fw; BufferedReader br; ...
3
by: SM | last post by:
Hello, Im trying to access elements in my XML file using the JavaScript DOM but i'm not sure how. I use AJAX to access the XML and then use the responseXML property to access the XML file data. I...
0
Fary4u
by: Fary4u | last post by:
Hi Guys i'm trying to upload a file, i've tried 3 different methods but still not work out i don't know how to over come this problem hidden file value, multiple form or popup uploading. 1-...
1
by: jai80 | last post by:
Hi Friends, Is it Possible to write the contents of a webpage to an XML file using c#.net. A sample code snippet will be of great help. Also, i want to know how to read only those contents,...
5
by: boss1 | last post by:
hello everyone, i need your help. i m using ajax to retrieve value from database and showing it within html form insise div tag .its working well.But now i need to show div id content(field value...
3
by: Dick Brouwers | last post by:
<body> <div id="myImages"></div> <! THIS IS THE DIV MY CONTENT NEEDS TO GO IN--> <div id="viewImage"></div> <script type="text/javascript"> //ajaxrequest var imageBankXhr = XHR(); ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.