473,799 Members | 3,197 Online
Bytes | Software Development & Data Engineering Community
+ 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 1476
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*******@attgl obal.net
=============== ===

Jun 2 '08 #2
SM
On May 9, 8:54 pm, Jerry Stuckle <jstuck...@attg lobal.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...@attgl obal.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
8460
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 generate a makefile (that include env_precomp.mk) and launch this makefile after. So, I receive this error: make: 1254-002 Cannot find a rule to create target /u02/apps_r/dev/ben/lib/fcfz02.a from dependencies.
24
2227
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 one; but there must be some faster way of doing it. The thing I want is to define some masks and macros and find if there are consective ones on a word/dword. e.g. 0000b has no consective
6
11211
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
51756
by: Ajay | last post by:
Hi all,Could anybody tell me the most efficient method to find a substr in a string.
2
1487
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 be at least medium sized. (about 60k lines of C# in the solution itself and perhaps another 20k lines in libraries we've developed.) finding classes we've built can be challenging at times and in theory the object browser should be my friend.
3
26125
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 mypc: Non-existent domain ------------------------------------------------------------------
0
1516
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 ID="CatalogItemsListDataSource" runat="server" DeleteMethod="DeleteCatalogItem" InsertMethod="InsertCatalogItem" OldValuesParameterFormatString="original_{0}" SelectMethod="GetCatalogItemsList" TypeName="CatalogItemManager" UpdateMethod="UpdateCatalogItem">...
18
3874
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 given file. I tried my level best even after the quiz to come up with a solution but cudnt find an efficient one. :( This is what I did.
0
1581
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" Public Class States Public Sub New() End Sub
0
9538
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10470
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10247
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10023
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9067
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6803
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5459
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5583
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3751
muto222
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.