Problem with domnode->next_sibling()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • KubixKiller@gmail.com

    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_fil e-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="Smakelij ke 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:"For k 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>Nutteloz e feiten</TITLE>
    <META NAME="robots" CONTENT="all">
    </HEAD>
    <BODY>
    <P CLASS="Intro">Z ie hier een lijst met veel nutteloze feiten.....</P>
    <?
    include('../../lib/xmlFunctions.li b');
    include('../../lib/htmlFunctions.l ib');

    $xml_doc = @domxml_open_fi le("nuttelozeFe iten.xml",
    DOMXML_LOAD_VAL IDATING ,&$xml_error) ;
    if (!isset($xml_do c)){
    echo "Error loading file ".$xml_erro r;
    die();
    }

    $xml_root = $xml_doc->document_eleme nt();
    $xml_general = GetFirstElement ByTagName($xml_ root,"General") ;
    $xml_subjects = GetFirstElement ByTagName($xml_ root,"Subjects" );
    $counter = 1;
    echo AddTag_Class("S PAN","SubjectLi st");
    echo "Onderwerpe n:";
    echo TerminateTag("S PAN");

    echo AddTag_Class("U L","SubjectList ");
    $subjCount = 0;
    foreach($xml_do c->get_elements_b y_tagname("Subj ect") as $subject){
    $title = $subject->get_attribute( "Name");
    echo AddTag_Class("L I","SubjectList ");
    echo "<A HREF='#SUBJ_".$ subjCount++."' CLASS='Subject' >";
    echo $title;
    echo TerminateTag("A ");
    echo TerminateTag("L I");
    }
    echo TerminateTag("U L");

    echo AddTag_SimpleCl ass("HR","Separ ator");

    # Cycle all subject-elements
    $subjCount = 0;
    foreach($xml_do c->get_elements_b y_tagname("Subj ect") as $subject){
    echo AddTag_Open("A" );
    echo AddAttrValue("N AME","SUBJ_".$s ubjCount++);
    echo TagClose();

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

    $item = GetFirstElement byTagName($subj ect,"Item");
    # Cycle all item-elements
    while ($item){

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

    if ($item->node_type() == XML_ELEMENT_NOD E) { # WHY
    ??????????????? ??????????
    $title = $item->get_attribute( "Title");
    echo AddTag_Closed(" H2");
    echo AddTag_Class("S PAN","ItemNumbe r");
    echo $counter;
    echo TerminateTag("S PAN");
    $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("H REF",$URL);
    echo AddAttrValue("T ITLE","Search Google!");
    echo AddAttrValue("C LASS","SearchKe ywords");
    echo AddAttrValue("T ARGET","_blank" );
    echo TagClose();
    echo " : ".$title;
    echo TerminateTag("A ");
    }
    else{
    echo " : ".$title;
    }
    echo TerminateTag("H 2");

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

    $counter++;
    }
    $item = $item->next_sibling() ; # FAULTY
    ??????????????? ??????????????? ??????
    }
    echo AddTag_SimpleCl ass("HR","EndSu bject");

    }//cycle all subjects

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

  • whiskey

    #2
    Re: Problem with domnode-&gt;next_siblin g()

    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_DON T_KEEP_BLANKS.
    By the way: why doesn't the domxml_open_fil e-function validate my XML against the mentioned DTD-file?
    Try calling the function with DOMXML_LOAD_VAL IDATING.

    See PHP manual on how to use flags/modes.

    Comment

    • KubixKiller@gmail.com

      #3
      Re: Problem with domnode-&gt;next_siblin g()

      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_DON T_KEEP_BLANKS.
      >
      By the way: why doesn't the domxml_open_fil e-function validate my XML against the mentioned DTD-file?
      Try calling the function with DOMXML_LOAD_VAL IDATING.
      >
      See PHP manual on how to use flags/modes.

      Comment

      Working...