Problem with domnode->next_sibling()

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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">
    <Date>30 okt 2006</Date>
    <Subject Name="Lekker">
      <Item Title="Smakelijke geestelijke" Keywords="baker fiji fork
        Op de Fiji-eilanden wordt met genoegen teruggedacht aan dominee
        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 Title="Rijpe bananen" Keywords="">
        Ook op de bovenwindse eilanden mocht men graag mensen eten. De
Dominicanen prefereerden blanken.'Ze smaken als rijpe bananen'
    <Subject Name="Test">
      <Item Title="bla bla">

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

------------------ PHP Script --------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
" ">
<HTML lang="NL">
  <LINK HREF="../../css/nutteloos.css" REL="stylesheet"
  <TITLE>Nutteloze feiten</TITLE>
  <META  NAME="robots"  CONTENT="all">
<P CLASS="Intro">Zie hier een lijst met veel nutteloze feiten.....</P>

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

  $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 = " =";
          $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");
          echo " : ".$title;
        echo TerminateTag("H2");

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

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

  }//cycle all subjects

------------------ END PHP Script --------------

Re: Problem with domnode->next_sibling()

Quoted text here. Click to load it
W/s are probably treates as anonymous text nodes. In this case, you'll
need to strip them. Try calling your function with

Quoted text here. Click to load it
Try calling the function with DOMXML_LOAD_VALIDATING.

See PHP manual on how to use flags/modes.

Re: Problem with domnode->next_sibling()


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

Quoted text here. Click to load it

Site Timeline