473,498 Members | 891 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Not new to xml generating but am new to really complex parsing...help.

nine72
21 New Member
Ok, I am at a complete loss on this and have finally come to the XML Parsing Gods (and perhaps a PHP minor deity) for guidance…

I will try my best to describe what I have going on…

1) I have 15 form pages, well over 500 potential fields, which are written in PHP. While most pages are one time entry forms, there are 5 that can be “recycled” as many times as needed. An example would be the Contacts Form. A user can give me 1 contact and move on OR they can “Save” the contact and add another. They may add as many contacts as they wish (up to 50).
2) I am saving the input to the forms in a temp mySql db and at the point of submission, generating a massive XML string and sending to a middle ware app written by someone else in-house. (all easy enough so far)
3) Previously the middle ware sent me a response XML string that was very simple.

Expand|Select|Wrap|Line Numbers
  1.     <Response>
  2.                    <insert_status>Accepted</insert_status>
  3.     </Response>.
  4.  
And I would return the user to a "Complete" or "Insert Faild" page based on the <insert_status>.

Now the requirements have changed and the response string will consist of EVERY value sent to the middleware and its conversion state i.e. a shortened name to meet the field or format requirements of the db (Example: John Smith would return as JOHN-SM001 etc.). Now I will need to parse, reorganize, pass the information into a PHP $_SESSION array and present the information back to the user on the Insert Complete page.

The issue is this, using contacts as the example, if I am returned the following string part..


Expand|Select|Wrap|Line Numbers
  1. <Contacts>
  2. <Contact>
  3.  <contact_id>833</contact_id>
  4.  <contact_type>ACCOUNTING</contact_type>
  5.  <first_name>NATALIE</first_name>
  6.  <last_name>GEWN</last_name>
  7.  <middle_i>M</middle_i>
  8.  <address1>147 OCEAN DR</address1>
  9.  <address2></address2>
  10.  <state_cd>MA</state_cd>
  11.  <city>RIVERMORE</city>
  12.  <zip>01556</zip>
  13.  <cntry_cd>840</cntry_cd>
  14.  <telephone>9879879877</telephone>
  15.  <mobile></mobile>
  16.  <email_id>NGEWN@MYCO.COM</email_id>
  17.  <department></department>
  18.  <title></title>
  19.  <fax>3213213211</fax>
  20.  <url></url>
  21.  <country>UNITED STATES OF AMERICA</country>
  22.  <state>MASSACHUSETTS</state>
  23.  <customer_care_phone>9879879877</customer_care_phone>
  24. </Contact>
  25. </Contacts>
  26.  
50 times how would I be able make each Contact and its sub set of tags unique so that I could store them in the PHP $_SESSION array where I can pull the distinct values to populate a response page giving back the information as it is returned to me. One reason that I would need to put it to a session is that some returned response would be meaningless to the user such as <billing_value>00MER90</billing_value>. I would have to search 00MER90 and print to the page its corresponding friendly name such as “Mileage Earned Revenue”


Right now I can return the string and print the array in a multidimensional array using this class.
[PHP]
<?PHP

class XmlToArray
{

var $xml='';

/**
* Default Constructor
* @param $xml = xml data
* @return none
*/

function XmlToArray($xml)
{
$this->xml = $xml;
}

/**
* _struct_to_array($values, &$i)
*
* This adds the contents of the return xml into the array for easier processing.
* Recursive, Static
*
* @access private
* @param array $values this is the xml data in an array
* @param int $i this is the current location in the array
* @return Array
*/

function _struct_to_array($values, &$i)
{
$child = array();
if (isset($values[$i]['value'])) array_push($child, $values[$i]['value']);

while ($i++ < count($values)) {
switch ($values[$i]['type']) {
case 'cdata':
array_push($child, $values[$i]['value']);
break;

case 'complete':
$name = $values[$i]['tag'];
if(!empty($name)){
$child[$name]= ($values[$i]['value'])?($values[$i]['value']):'';
if(isset($values[$i]['attributes'])) {
$child[$name] = $values[$i]['attributes'];
}
}
break;

case 'open':
$name = $values[$i]['tag'];
$size = isset($child[$name]) ? sizeof($child[$name]) : 0;
$child[$name][$size] = $this->_struct_to_array($values, $i);
break;

case 'close':
return $child;
break;
}
}
return $child;
}//_struct_to_array

/**
* createArray($data)
*
* This is adds the contents of the return xml into the array for easier processing.
*
* @access public
* @param string $data this is the string of the xml data
* @return Array
*/
function createArray()
{
$xml = $this->xml;
$values = array();
$index = array();
$array = array();
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parse_into_struct($parser, $xml, $values, $index);
xml_parser_free($parser);
$i = 0;
$name = $values[$i]['tag'];
$array[$name] = isset($values[$i]['attributes']) ? $values[$i]['attributes'] : '';
$array[$name] = $this->_struct_to_array($values, $i);
return $array;

}//createArray


}//XmlToArray

?>
[/PHP]

However, this is just way too deep (I think) once completed for it to be usable for this project.

(did any of that make sense?)

I would be more than willing to provide a full sample return xml string via email if some one needs to see just how it is being sent to me…

Thank you for your time.
Oct 22 '08 #1
1 2184
Dormilich
8,658 Recognized Expert Moderator Expert
Ok, I am at a complete loss on this and have finally come to the XML Parsing Gods (and perhaps a PHP minor deity) for guidance….
Deity bless you.

now back to "business". if I understand it right (it was quite some text to read) you look for an easy way to transform the middle-ware xml into a session saveable array? (correct me if I'm completely on the wrong track...)

(*evil grin* ahem) as fortune plays I do something similar (but admittedly not that large), I convert a control xml into page specific objects. my solution is to convert it into an xml serialized string that is then deserialized into my desired object.

like that:
[PHP]$xml = "control.xml"; // $xml = $xmlInputString;
$xsl = "ControlToWDDX.xsl";
$result = XSLTransform->process($xml, $xsl); // php5 xslt processing
$array = wddx_deserialize($result);
// do whatever is to be done with $array[/PHP]
advantage, when doing xslt you can convert 00MER90 to Mileage Earned Revenue while you're at it, or crop/trim/replace/alter/add information, as you desire.

regards
Oct 22 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
1635
by: Richard Shea | last post by:
Hi - I've writing a Python script which has a query which looks like this ... select * from T where C1 not in (1,2,3) .... C1 is a numeric column so elements of (1,2,3) must not be quoted...
11
2074
by: Sven Neuberg | last post by:
Hi, I have been handed the task of updating and maintaining a web application, written in ASP and Javascript, that takes complex user inputs in HTML form and submits them to server-side ASP...
3
3481
by: Pir8 | last post by:
I have a complex xml file, which contains stories within a magazine. The structure of the xml file is as follows: <?xml version="1.0" encoding="ISO-8859-1" ?> <magazine> <story>...
3
1917
by: Sky Sigal | last post by:
I coming unglued... really need some help. 3 days chasing my tail all over MSDN's documentation ...and I'm getting nowhere. I have a problem with TypeConverters and storage of expandableobjects...
1
2839
by: louis_la_brocante | last post by:
Dear all, I am having trouble generating a client proxy for a webservice whose methods return a "complex" type. The type is complex in that it is a class whose members are a mix of primitive...
3
3262
by: Rav | last post by:
hi, i need a function, preferably a program for parsing the complex declarations in C. Can anyone help me in this regard...i appreciate. i work on Turbo C++ 3.0 in windows environment. Also, plz...
8
2445
by: matt | last post by:
hello, can anyone speak to some of the common or preferred methods for building Excel .XLS files, programmatically thru the .NET framework? i have an intranet app that needs to generate &...
28
1562
by: Nutkin | last post by:
Basicly i have to make a program that calculates the distance between x and y points in 2d space. the code basicly goes like this 1. User says how many points they have (max of 10) 2. User...
7
3902
by: horacius.rex | last post by:
Hi, I want to profile a C program I am writting, so I compile it with -pg options and use gprof to obtain information about call graphs, which I am really interested in. I look at the text files...
0
6998
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7163
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5460
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4904
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4586
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3090
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
651
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.