I have a big 88mb xml file that I tried importing with excel and it keeps crashing.

So I figured I can parse it with php, but dont know enough of how to pull it off.

<note id="need_this_value" random="1234" values="5678">
	<name>need_this_value</note>
	<fix><description>need_this_value</description></fix>
	<patch name="need_this_value" random="1234" values="5678"></patch>
	<ref><microsoft random="1234" values="5678">need_this_value</microsoft></ref>
	<codes><code random="1234" values="5678">need_this_value</code></codes>
</note>

Can someone show me how to get all my need_this_value.

Thank you soooooooooooo much in advance!

    Probably the easiest way is to use [man]SimpleXML[/man]. Just to give a quick taste, run this little script:

    <?php
    $text = <<<EOD
    <?xml version='1.0' ?>
    <data>
      <note id="need_this_value_1" random="1234" values="5678">
        <name>need_this_value</name>
        <fix><description>need_this_value</description></fix>
        <patch name="need_this_value" random="1234" values="5678"></patch>
        <ref><microsoft random="1234" values="5678">need_this_value</microsoft></ref>
        <codes><code random="1234" values="5678">need_this_value</code></codes>
      </note>
      <note id="need_this_value_1" random="1234" values="5678">
        <name>need_this_value</name>
        <fix><description>need_this_value</description></fix>
        <patch name="need_this_value" random="1234" values="5678"></patch>
        <ref><microsoft random="1234" values="5678">need_this_value</microsoft></ref>
        <codes><code random="1234" values="5678">need_this_value</code></codes>
      </note>
    </data>
    EOD;
    
    $xml = simplexml_load_string($text) or die('uh-oh!');
    foreach($xml->note as $note) {
       echo "<pre>".print_r($note, true)."</pre>";
    }
    

    (There's more work to do to extract each value and do whatever you want, but this should get you pointed in the right direction.)

      but wont that just spit out everything inside of note into <PRE>?

      I was hoping to understand how to get the values.

        I think I have figured it out

        <?php
        $text = <<<EOD
        <?xml version='1.0' ?>
        <data>
          <note id="need_this_value_1" random="1234" values="5678">
            <name>need_this_value1234</name>
            <fix><description>need_this_value</description></fix>
            <patch name="1234" random="1234" values="5678"></patch>
            <ref><microsoft random="1234" values="5678">need_this_value</microsoft></ref>
            <codes><code random="1234" values="5678">need_this_value</code></codes>
          </note>
          <note id="need_this_value_12" random="1234" values="5678">
            <name>need_this_value</name>
            <fix><description>need_this_value</description></fix>
            <patch name="need_this_value" random="1234" values="5678"></patch>
            <ref><microsoft random="1234" values="5678">need_this_value</microsoft></ref>
            <codes><code random="1234" values="5678">need_this_value</code></codes>
          </note>
        </data>
        EOD;
        
        $xml = simplexml_load_string($text) or die('uh-oh!');
        
        $att = 'name';
        
        $attribute = $xml->note[1]->patch->attributes()->$att;
        
        echo $attribute;
        
        $attribute2 = $xml->note[0]->children()->name;
        
        echo $attribute2;
        
        ?>
        
          $xml = simplexml_load_file('test.xml');
          $name = $xml->rth->children()->name; 
          

          Sometimes the children dont exist. and I get the "Warning: main() [function.main]: Node no longer exists"

          I have tried !=null, !="", isset, !empty

          How do i get it to not error?

          thanks again

            Try is_object($xml->rth->children()->name), if that doesn't work, try using count($xml->rth->children()) first to see if there are any children. The fact you are checking using other methods might be causing the warning.

            Also you shouldn't have to define $att = 'name', you should be able to do attributes()->name;

              if(is_object($xml->rth[$counter]->references->tests->children()->test)){
              $test = $xml->rth[$counter]->references->tests->children()->test; 
              echo "Test: " . $test . "<br>\n\r";
              }else{
              echo "blah";
              }
              

              this works, but still errors
              so i did this

              if(is_object(@$xml->rth->references->tests->children()->test)){
              

              still works and no errors

                Keep in mind that @ just suppresses the error in the output, you will still have the warning in your error log.

                Also I just had another thought. It could very well be that a node in the middle of the selector doesn't exist, and thus everything after it doesn't exist. So you may want to do a check on each node up to the last if you are uncertain if each step up in the selector will always exist.

                  I thought that was a problem too, tests didnt exist, so there was no way test could exist.

                  that you!!!!!!!!!!!!!

                    Write a Reply...