473,322 Members | 1,431 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,322 software developers and data experts.

Problem with domnode->next_sibling()

Hello,

I use the following XML-file to store some useless facts I want to
display using PHP. I wrote some PHP code to generate HTML, because I do
not have any knowledge of stylesheets etc etc. The problem arises that
the php-function next_sibling from the DOMXML library doesn't seem to
do what it should. See the code later in this message.

Look at the lines below the comment line : # Cycle all item-elements

Why is the next sibling of my Item-node, a text-node? I use PHP 4.3.10.

By the way: why doesn't the domxml_open_file-function validate my XML
against the mentioned DTD-file?

Any help would be greatly appreciated.

-------------------- XML FILE -----------------------

<?xml version="1.0"?>
<!DOCTYPE Lexicon SYSTEM "nutteloos.dtd">
<Lexicon>
<General>
<Date>30 okt 2006</Date>
<Version>1.0a</Version>
<Comment>Fun!</Comment>
</General>
<Subjects>
<Subject Name="Lekker">
<Item Title="Smakelijke geestelijke" Keywords="baker fiji fork
eat">
Op de Fiji-eilanden wordt met genoegen teruggedacht aan dominee
Baker.
In een museum aldaar koestert men een houten vork met als
bijschrift:"Fork used in Eating Reverend Baker".
De zielenherder stond in 1867 op het menu.
</Item>
<Item Title="Rijpe bananen" Keywords="">
Ook op de bovenwindse eilanden mocht men graag mensen eten. De
Dominicanen prefereerden blanken.'Ze smaken als rijpe bananen'
</Item>
</Subject>
<Subject Name="Test">
<Item Title="bla bla">
</Item>
</Subject>
</Subjects>
</Lexicon>

-------------------- END XML FILE -----------------------

------------------ PHP Script --------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML lang="NL">
<HEAD>
<LINK HREF="../../css/nutteloos.css" REL="stylesheet"
TYPE="text/css">
<TITLE>Nutteloze feiten</TITLE>
<META NAME="robots" CONTENT="all">
</HEAD>
<BODY>
<P CLASS="Intro">Zie hier een lijst met veel nutteloze feiten.....</P>
<?
include('../../lib/xmlFunctions.lib');
include('../../lib/htmlFunctions.lib');

$xml_doc = @domxml_open_file("nuttelozeFeiten.xml",
DOMXML_LOAD_VALIDATING ,&$xml_error);
if (!isset($xml_doc)){
echo "Error loading file ".$xml_error;
die();
}

$xml_root = $xml_doc->document_element();
$xml_general = GetFirstElementByTagName($xml_root,"General");
$xml_subjects = GetFirstElementByTagName($xml_root,"Subjects");
$counter = 1;
echo AddTag_Class("SPAN","SubjectList");
echo "Onderwerpen:";
echo TerminateTag("SPAN");

echo AddTag_Class("UL","SubjectList");
$subjCount = 0;
foreach($xml_doc->get_elements_by_tagname("Subject") as $subject){
$title = $subject->get_attribute("Name");
echo AddTag_Class("LI","SubjectList");
echo "<A HREF='#SUBJ_".$subjCount++."' CLASS='Subject'>";
echo $title;
echo TerminateTag("A");
echo TerminateTag("LI");
}
echo TerminateTag("UL");

echo AddTag_SimpleClass("HR","Separator");

# Cycle all subject-elements
$subjCount = 0;
foreach($xml_doc->get_elements_by_tagname("Subject") as $subject){
echo AddTag_Open("A");
echo AddAttrValue("NAME","SUBJ_".$subjCount++);
echo TagClose();

echo AddTag_Closed("H1");
echo "Onderwerp : " . $subject->get_attribute("Name");
echo TerminateTag("H1");

$item = GetFirstElementbyTagName($subject,"Item");
# Cycle all item-elements
while ($item){

var_dump($item); # DomElement
var_dump($item->next_sibling()); #Textnode???

if ($item->node_type() == XML_ELEMENT_NODE) { # WHY
?????????????????????????
$title = $item->get_attribute("Title");
echo AddTag_Closed("H2");
echo AddTag_Class("SPAN","ItemNumber");
echo $counter;
echo TerminateTag("SPAN");
$keywords = $item->get_attribute("Keywords");
if ($keywords){
$baseURL = "http://www.google.nl/search?hl=nl&q=";
$searchQuery = str_replace(" ","+",$keywords);
$URL = $baseURL . $searchQuery;
echo AddTag_Open("A");
echo AddAttrValue("HREF",$URL);
echo AddAttrValue("TITLE","Search Google!");
echo AddAttrValue("CLASS","SearchKeywords");
echo AddAttrValue("TARGET","_blank");
echo TagClose();
echo " : ".$title;
echo TerminateTag("A");
}
else{
echo " : ".$title;
}
echo TerminateTag("H2");

echo AddTag_Class("P","Contents");
echo $item->get_content();
echo TerminateTag("P");

$counter++;
}
$item = $item->next_sibling(); # FAULTY
????????????????????????????????????
}
echo AddTag_SimpleClass("HR","EndSubject");

}//cycle all subjects

?>
</BODY>
</HTML>
------------------ END PHP Script --------------

Oct 31 '06 #1
2 1434
Why is the next sibling of my Item-node, a text-node? I use PHP 4.3.10.
W/s are probably treates as anonymous text nodes. In this case, you'll
need to strip them. Try calling your function with
DOMXML_LOAD_DONT_KEEP_BLANKS.
By the way: why doesn't the domxml_open_file-function validate my XML against the mentioned DTD-file?
Try calling the function with DOMXML_LOAD_VALIDATING.

See PHP manual on how to use flags/modes.

Oct 31 '06 #2
Whiskey,

Great! That really worked for me (skipping blancs). Now I'll have a
look at the validating part. Many thanks on giving more insight in this
strange DOMXML behaviour.

Greets Martin

whiskey wrote
Why is the next sibling of my Item-node, a text-node? I use PHP 4.3.10.
W/s are probably treates as anonymous text nodes. In this case, you'll
need to strip them. Try calling your function with
DOMXML_LOAD_DONT_KEEP_BLANKS.
By the way: why doesn't the domxml_open_file-function validate my XML against the mentioned DTD-file?
Try calling the function with DOMXML_LOAD_VALIDATING.

See PHP manual on how to use flags/modes.
Oct 31 '06 #3

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

Similar topics

1
by: bizt | last post by:
Hi Please forgive the length of this post and bear with me. I am having trouble between two different servers and the same DOMXML code. Basically I am trying to run a script that will: 1)...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.