using System; using System.IO; using System.Net; using System.Text; //$APIKey="???"; //$APIKey="???"; public static String http_get(String URL){ // used to build entire input StringBuilder sb = new StringBuilder(); // used on each read operation byte[] buf = new byte[8192]; // prepare the web page we will be asking for HttpWebRequest request = (HttpWebRequest) WebRequest.Create(URL); // execute the request HttpWebResponse response = (HttpWebResponse) request.GetResponse(); // we will read data via the response stream Stream resStream = response.GetResponseStream(); string tempString = null; int count = 0; do{ // fill the buffer with data count = resStream.Read(buf, 0, buf.Length); // make sure we read some data if (count != 0) { // translate from bytes to ASCII text tempString = Encoding.ASCII.GetString(buf, 0, count); // continue building the string sb.Append(tempString); } } while (count > 0); // any more data to read? return ToString(sb.ToString()); } $URL="http://www.craftlister.com/api/v0.1b/EventDetails.php?APIKey=$APIKey&EventNumber=1024261"; //print "getting URL: $URL
"; $xml=http_get($URL); //print "$xml"; //http://devresource.hp.com/drc/technical_articles/xmlprocess/index.jsp#pars //http://www.c-sharpcorner.com/Code/2005/April/SimpleXMLParser.asp //http://www.xml.com/lpt/a/932 //http://www.learnasp.com/freebook/learn/cs_xmlparser.aspx //http://www.destructor.de/xmlparser/index.htm $Results=xml2array($xml); function xml2array( $textXml ) { $regExElements = '/<(\w+)([^>]*)>(.*?)<\/\\1>/s'; $regExAttributes = '/(\w+)="([^"]*)"/'; preg_match_all( $regExElements, $textXml, $matchElements ); foreach ( $matchElements[1] as $keyElements=>$valElements ) { if ( $matchElements[2][$keyElements] ) { preg_match_all( $regExAttributes, $matchElements[2][$keyElements], $matchAttributes ); foreach ( $matchAttributes[0] as $keyAttributes=>$valAttributes ) { $arrayAttributes[ $valElements.' attributes' ][$matchAttributes[1][ $keyAttributes ] ] = $matchAttributes[2][ $keyAttributes ]; } } else { $arrayAttributes = null; } if ( preg_match( $regExElements, $matchElements[3][$keyElements]) ) { if ( $arrayAttributes ) { $arrayFinal[ $valElements ][ $valElements.' attributes' ] = $arrayAttributes[ $valElements.' attributes' ]; } $arrayFinal[ $valElements ][] = xml2array( $matchElements[3][$keyElements] ); } else { $arrayFinal[ $valElements ] = $matchElements[3][ $keyElements ]; $arrayFinal = array_merge( $arrayFinal, $arrayAttributes ); } } return $arrayFinal; } ?>