473,395 Members | 2,437 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,395 software developers and data experts.

How to skip reading of a content of a particular tag in xml file using php?

Suppose this is an XML file.
Expand|Select|Wrap|Line Numbers
  1. <subject>Inquiry</subject>
  2. <message>
  3.  <![CDATA[
  4.    <div>Hi</div>
  5.    <div>Hello</div>
  6.    <div>How Are You</div>
  7.  ]]>
  8. </message>
  9.  
My logic to read this xml file using php is...
Expand|Select|Wrap|Line Numbers
  1. $xml = simplexml_load_file("xml_mail_format2.xml");
  2. foreach($xml->children() as $child)
  3. {
  4.   if($child->getName() == "message")
  5.   {
  6.     foreach($child->children() as $children)
  7.     {
  8.       $message = $children;
  9.     }
  10.   }
  11. }
  12.  
Now the problem is, The whole message tag is being read by this. I want only "Hello" to be read. What should be done?
Feb 8 '11 #1
3 1618
Dormilich
8,658 Expert Mod 8TB
either don’t use CDATA or extract the CDATA text and parse that again.
Feb 8 '11 #2
I don't know how to do it because i am new to XML but can you write the things which exactly i want.(That to just read "Hello")instead of Hi Hello How are you. Please do something.
Feb 9 '11 #3
Dormilich
8,658 Expert Mod 8TB
you already have (and use) the tools you need, though it seems you need a better understanding of the DOM.

when your XML source code is read into the DOM, an object tree is constructed. in your case the tree (parts of it) looks like (omitting the attributes of the objects).

Expand|Select|Wrap|Line Numbers
  1. |-- (DOMElement) <subject>
  2. |     |-- (DOMText) "Inquiry"
  3. |
  4. |-- (DOMElement) <message>
  5.       |-- (DOMText) "\n "
  6.       |-- (DOMCharacterData) "\n   <div>Hi</div>\n   <div>Hello</div>\n   <div>How Are You</div>\n "
  7.       |-- (DOMText) "\n"
  8.  
what you need to do is extract the text which holds the "inline XML" and repeat XML parsing on that.
Feb 9 '11 #4

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

Similar topics

0
by: philip20060308 | last post by:
Hi all, Has anyone ever seen Python 2.4.1's httplib choke when reading chunked content? I'm using it via urrlib2, and I ran into a particular server that returns something that httplib doesn't...
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:
6
by: gauravkhanna | last post by:
import java.io.*; class Automation1 implements Runnable { int iterationCount=0; Thread t; FileReader fr; //FileWriter fw; BufferedReader br; ...
1
by: vjunkl | last post by:
Hello, I have a content text file in my project and I'd like to copy it to a folder at some point in the execution of the application(not during a build). If this is not possible, how about...
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...
1
by: leela mn | last post by:
Hi Guys, Is there anyway to extract the text content from an image file using c#?
3
by: Seenu828 | last post by:
Hi All, Is that possible to read parameters from .ini file using C#.NET. Could you give some idea or example. Pls advise me. Thanks Seenu
0
by: muaz111111 | last post by:
Huy, could anybody tell me how to read and write *.wmv file using C# regards
6
by: Jason | last post by:
I would like to build a windows app or service that would read a .txt file and than put the contents of that file in an email and send off the email. WOuld that be very difficult?...how could this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.