Jump to content

[SOLVED] SESSION VARIABLE


AnotherQuestion

Recommended Posts

Thanks for that I have tried the following code but not working as I mentioned earlier I am trying to read an xml file then set each of the tag names to a session variable and then set the data of the tags to the session name

 

eg  XML output

 

<VRM>AMS1</VRM>

 

would become: $_SESSION['VRM'] = "AMS1"

 

etc.

: (please see below for XML output

 

$data = file_get_contents("https://vrm.mamsoft.co.uk/vrmlookup/vrmlookup.asmx/Find?Username=NOSPAM&Password=NOSPAM&Vrm=".$_GET['RegNo']); 
$FileName = "Vrmdata.xml";
$VrmFile = fopen($FileName, 'w')or die("can't open file");
fwrite($VrmFile, $data); 
fclose($VrmFile); 


//Initialize the XML parser
$parser=xml_parser_create();

//Function to use at the start of an element
function start($parser,$element_name,$element_attrs)
  {
  switch($element_name)
    {

    }
  }

//Function to use at the end of an element
function stop($parser,$element_name)
  {
  
  }

//Function to use when finding character data
function char($parser,$data)
  {
  $_SESSION[$element_name] = $data;
  }

//Specify element handler
xml_set_element_handler($parser,"start","stop");

//Specify data handler
xml_set_character_data_handler($parser,"char");

//Open XML file
$fp=fopen("Vrmdata.xml","r");

//Read data
while ($data=fread($fp,4096))
  {
  xml_parse($parser,$data,feof($fp)) or 
  die (sprintf("XML Error: %s at line %d", 
  xml_error_string(xml_get_error_code($parser)),
  xml_get_current_line_number($parser)));
  }

//Free the XML parser
xml_parser_free($parser);

 

 

 

The output of the above file gives a result like:

 

<?xml version="1.0" encoding="utf-8"?>

<ReturnValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:type="Vehicle" xmlns="www.mamsoft.co.uk/VrmLookup">

  <Vrm></Vrm>

  <Vin></Vin>

  <EngineNo></EngineNo>

  <EngineSize></EngineSize>

  <EngineModel></EngineModel>

  <Fuel></Fuel>

  <Make></Make>

  <Model></Model>

  <Colour></Colour>

  <Transmission>C</Transmission>

  <TransmissionCode></TransmissionCode>

  <BodyPlan></BodyPlan>

  <Gears></Gears>

  <YearOfManufacture></YearOfManufacture>

  <DateRegistered></DateRegistered>

  <Scrapped></Scrapped>

  <Exported></Exported>

  <Imported></Imported>

  <DtpMakeCode></DtpMakeCode>

  <DtpModelCode></DtpModelCode>

</ReturnValue>

 

Link to comment
Share on other sites

I'm guessing the $_SESSION variable was from one of the other threads using the xml_parser_create(). The reason for it in that code was because the start() and char() callback functions are completely separate (unless you make that a class) and the easiest way of sharing information between the two functions was to use a $_SESSION variable, which is a global variable.

 

For the code you just posted, you can use any array variable you choose to make.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.