473,473 Members | 1,581 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to find non-existing nodes or nodes with no text.

SM
Ok, this must be simple but the more i search the more i don't find.
It's about SimpleXML and PHP.
How to find non-existing nodes or nodes with no text

My XML file looks a little bit like this:

i.e. 1
<discography>
<CD>
<title></title>
<year>1978</year>
</CD>
</discography>
i.e. 2:
<discography>
<CD>
<year>1978</year>
</CD>
</discography>
In i.e. 1, the tag <titleis empty. How do i test for empty tags in
PHP?
In i.e. 2, the tag <titledoesn't even exist. How do i test for non-
existing tags?
This is how i get the values from XML in PHP without validation
....
//set the XML file name as a PHP string
$cd_xml = "db/discography/cd.xml";

//load the XML file
$xml = @simplexml_load_file($cd_xml) or die ("Error: The XML file
can't open.") ;
....

//no validation if empty, creates empty <h1tags. Not good!
<h1><?php echo $xml->CD->title; ?></h1>
<h2><?php echo $xml->CD->year; ?></h2>

How to validate?
Any suggestions?

Thanks in advance
Marco
Jun 2 '08 #1
2 1445
SM wrote:
Ok, this must be simple but the more i search the more i don't find.
It's about SimpleXML and PHP.
How to find non-existing nodes or nodes with no text

My XML file looks a little bit like this:

i.e. 1
<discography>
<CD>
<title></title>
<year>1978</year>
</CD>
</discography>
i.e. 2:
<discography>
<CD>
<year>1978</year>
</CD>
</discography>
In i.e. 1, the tag <titleis empty. How do i test for empty tags in
PHP?
In i.e. 2, the tag <titledoesn't even exist. How do i test for non-
existing tags?
This is how i get the values from XML in PHP without validation
...
//set the XML file name as a PHP string
$cd_xml = "db/discography/cd.xml";

//load the XML file
$xml = @simplexml_load_file($cd_xml) or die ("Error: The XML file
can't open.") ;
...

//no validation if empty, creates empty <h1tags. Not good!
<h1><?php echo $xml->CD->title; ?></h1>
<h2><?php echo $xml->CD->year; ?></h2>

How to validate?
Any suggestions?

Thanks in advance
Marco
Have you tried RTFM? A string with no characters is just that - a
zero-length string.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 2 '08 #2
SM
On May 9, 8:54 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
SM wrote:
Ok, this must be simple but the more i search the more i don't find.
It's about SimpleXML and PHP.
How to find non-existing nodes or nodes with no text
My XML file looks a little bit like this:
i.e. 1
<discography>
<CD>
<title></title>
<year>1978</year>
</CD>
</discography>
i.e. 2:
<discography>
<CD>
<year>1978</year>
</CD>
</discography>
In i.e. 1, the tag <titleis empty. How do i test for empty tags in
PHP?
In i.e. 2, the tag <titledoesn't even exist. How do i test for non-
existing tags?
This is how i get the values from XML in PHP without validation
...
//set the XML file name as a PHP string
$cd_xml = "db/discography/cd.xml";
//load the XML file
$xml = @simplexml_load_file($cd_xml) or die ("Error: The XML file
can't open.") ;
...
//no validation if empty, creates empty <h1tags. Not good!
<h1><?php echo $xml->CD->title; ?></h1>
<h2><?php echo $xml->CD->year; ?></h2>
How to validate?
Any suggestions?
Thanks in advance
Marco

Have you tried RTFM? A string with no characters is just that - a
zero-length string.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
ok thanks FM, i will try the RTFM
Marco
Jun 2 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: simduss | last post by:
Hi, First of all, I'm a beginner with Unix. I have a "make" (Unix command) problem with a Pro*C sub-program since I installed Oracle8i (before I was at 7.3.4). I have a script builder that...
24
by: shafique | last post by:
Hello, Can anybody have idea as how to find it there exist consective one's in a word/dword using bitwise operatiors in C language. Obviously this can be done by shifting and looping one by...
6
by: Ravi | last post by:
Hi, I need to find the non-recursive algorithm to find the height of a Binary Tree. Regards, SunLight.
29
by: Ajay | last post by:
Hi all,Could anybody tell me the most efficient method to find a substr in a string.
2
by: tbh | last post by:
hi, hope this cross-post is OK. it's unclear to me whether this question belongs more under vstudio or dotnet... i'm using VS2005 pro and am one co-developer of a web solution that is getting to...
3
usafshah
by: usafshah | last post by:
C:\Documents and Settings\Link>nslookup *** Can't find server name for address 192.168.0.100: Non-existent domain Default Server: UnKnown Address: 192.168.0.100 > mypc *** UnKnown can't find...
0
by: Bryce | last post by:
I have an ObjectDataSource binding a GridView, with Delete enabled. The following is the declaration (with non-delete stuff left out to save space): <asp:ObjectDataSource...
18
by: Neehar | last post by:
Hello For one of the interviews I took recently, I was given an offline programming quiz. In 30 minutes I had to write code in C++ to counts the number of times each unique word appears in a...
0
by: Cirene | last post by:
Using Visual Studio I created a DataSet using the GUI (XSD file). Trying to use a tiered methodology I called the functions from my BLL. Namespace Zzz.BusinessLogicLayer #Region "DAL Access"...
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...
1
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.