XML DOMDocument

Discussion in 'PHP' started by gosforth, Oct 11, 2009.

  1. #1
    Hi,

    I'm wondering is there is some way to reach directly node instead of using loop. My example is:
    =======================================================

    $doc = new DOMDocument();
    $doc->load('test.xml');

    $xp = new domxpath($doc);

    $titles = $xp->query("//Lines/Line/*");

    foreach ($titles as $node) {
    if($node->nodeName=="LineNumber")
    {
    $LineNumber = $node->nodeValue;
    }
    }
    =======================================================

    Instead of passing through each element can I call it directly in some way?
    Something like 'node->nodeName['lineNumber'].value'...

    If someone was playing with DOM and could help... thanks in advance.

    G.
     
    gosforth, Oct 11, 2009 IP
  2. ForumJoiner

    ForumJoiner Active Member

    Messages:
    762
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    83
    #2
    ForumJoiner, Oct 11, 2009 IP
  3. gosforth

    gosforth Guest

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Well, this is not the kind of help I was searching for....
     
    gosforth, Oct 13, 2009 IP
  4. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #4
    First of all, as far as I know you can selected needed node somekind like
    $titles = $xp->query("//Lines/Line/[5]");
    PHP:
    Or you can get like this
    
    $titles  = $xpath->query("//Lines/Line/"); 
    $titles->item(4)->nodeValue;
    
    PHP:
     
    AsHinE, Oct 13, 2009 IP
  5. gosforth

    gosforth Guest

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks a lot - I will try that.
     
    gosforth, Oct 13, 2009 IP