Hey Everyone. I am trying to create a script that converts a SOAP protocol xml file into a readable table of information to be transferred to a pdf document. At the moment, I have three different types of records that need to be totaled and recorded. the SOAP format is as follows:
ns2:Instance>
ns2:MetricTypeft_html</ns2:MetricType>
ns2:Count0</ns2:Count>
</ns2:Instance>
-ns2:Instance
ns2:MetricTypeft_pdf</ns2:MetricType>
ns2:Count0</ns2:Count>
</ns2:Instance>
-ns2:Instance
ns2:MetricTypeft_total</ns2:MetricType>
ns2:Count0</ns2:Count>
</ns2:Instance>
What I am strying to do is retrieve the numbers between the count tags. I have currently made two arrays that store the character positions on the left and right sides of that value, but I am not sure of how to retrieve the character between those two positions. For now I am only working on the html Metric Type. The PHP code is below and any help is appreciated.
[php]
<?php $x=1; //Requestor Information $xml = simplexml_load_file("J1.xml"); $Info = $xml->children("soap", true)->Body-> children("ns3", true)->ReportResponse-> children()->Requestor; foreach ($Info as $info) { echo $info->ID, "" , $info->Name, "
", $info->Email, "
"; } //Vendor Info $Report = $xml->children("soap", true)->Body-> children("ns3", true)->ReportResponse->children("ns3", true)->Report-> children("ns2", true)->Report->children("ns2", true)->Vendor ->children("ns2",true)->ID; foreach ($Report as $report) { echo $report, "
", "
"; } //Meat and Potatoes $Items = $xml->children("soap", true)->Body-> children("ns3", true)->ReportResponse->children("ns3", true)->Report-> children("ns2", true)->Report->children("ns2", true)->Customer-> children("ns2", true)->ReportItems; echo "
---Name--- | "; echo "---Type--- | "; echo "---Begin--- | "; echo "---End--- | "; echo "---HTML--- | "; echo "---PDF--- | "; echo "---TOTAL--- |
---|---|---|---|---|---|---|
"; echo $items->children("ns2",true)->ItemName; echo " | "; echo $items->children("ns2",true)->ItemDataType; echo " | "; echo $items->children("ns2",true)->ItemPerformance->children("ns2",true)->Period->children("ns2",true)->Begin; echo " | "; echo $items->children("ns2",true)->ItemPerformance->children("ns2",true)->Period->children("ns2",true)->End; echo " | "; $Type=$items->children("ns2",true)->ItemPerformance->children("ns2",true)->Instance; foreach ($Type as $type) { echo $type->children("ns2",true)->Count; echo " | "; } echo " |
"; echo "Total Number of Items: ", $x, "
"; //Call functions for total count function strpos_recursive($haystack, $needle, $offset = 0, &$results = array()) { $offset = strpos($haystack, $needle, $offset); if($offset === false) { return $results; } else { $results[] = $offset; return strpos_recursive($haystack, $needle, ($offset + 1), $results); } } function strpos_recursive2($haystack, $needle2, $offset = 0, &$results = array()) { $offset = strpos($haystack, $needle2, $offset); if($offset === false) { return $results; } else { $results[] = $offset; return strpos_recursive($haystack, $needle2, ($offset + 1), $results); } } // HTML: Using Function for Beginning String Values $xml_str = file_get_contents('J1.xml'); $searchb = 'ft_html'; $foundb = strpos_recursive($xml_str, $searchb); if($foundb) { foreach($foundb as $posb) { $posb=$posb+33; //echo 'Found "'.$searchb.'" at position '.$posb.'
'; $html_begin[]=$posb; } } else { echo '"'.$searchb.'" not found in "'; } echo '
'; echo '
'; // HTML: Using Function for End String Values $xml_str = file_get_contents('J1.xml'); $searche = 'ft_pdf'; $founde = strpos_recursive2($xml_str, $searche); if($founde) { foreach($founde as $pose) { $pose=$pose-57; //echo 'Found "'.$searche.'" at position '.$pose.'
'; $html_end[]=$pose; } } else { echo '"'.$searche.'" not found in "'; } echo '
'; echo '
'; $html_total= array_diff($html_end,$html_begin); /*foreach ($html_total as $total) { echo $total. "
";*/ print_r($html_begin); [/php]