473,624 Members | 2,217 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 multidimensiona l 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_arra y($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_arra y($values, &$i)
{
$child = array();
if (isset($values[$i]['value'])) array_push($chi ld, $values[$i]['value']);

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

case 'complete':
$name = $values[$i]['tag'];
if(!empty($name )){
$child[$name]= ($values[$i]['value'])?($values[$i]['value']):'';
if(isset($value s[$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_arr ay($values, $i);
break;

case 'close':
return $child;
break;
}
}
return $child;
}//_struct_to_arra y

/**
* createArray($da ta)
*
* 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_crea te();
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_arr ay($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 2200
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.xm l"; // $xml = $xmlInputString ;
$xsl = "ControlToWDDX. xsl";
$result = XSLTransform->process($xml , $xsl); // php5 xslt processing
$array = wddx_deserializ e($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
1641
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 like this ('1','2','3') and of course they must not be quoted like this ('1,2,3'). I'm using 'scanf' style substitution into the SQL, eg ...
11
2094
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 pages for processing. The problem is, the user inputs can become very complex, and the way this application was developed, the inputs are all concatenated into monstrously long strings of text that are then submited as <hidden> inputs in HTML forms...
3
3491
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> <story_id>112233</story_id> <pub_name>Puleen's Publication</pub_name> <pub_code>PP</pub_code> <edition_date>20031201</edition_date>
3
1929
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 to attributes in tags (think Style tag -> Style object). The problem that I am chasing is: Html side:
1
2857
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 types and of more elaborate classes implementing IXmlSerializable. The resulting WSDL file for the webservice has two separate schemas in its <types> sections, and the client proxy (generated with wsdl.exe) is missing the definitions of the...
3
3278
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 explain the meaning and use of cdecl. thnx in advance.
8
2454
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 & email .xls files for users. these are not reports, but rather more like forms. its a pretty simple doc, two worksheets -- the first is basic info common to all recepients. the second is a simple data table that, depending on the recepient, contains...
28
1586
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 enters points 3. Using sqrt( (x2-x1)^2 + (y2-y1)^2) ) It calculates the distance
7
3912
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 but when I have a large number of functions, it looks really embarrasing. So somebody recommended me about graphviz. My problem was to find something to convert between gprof format and graphviz .dot format. I finally found gprof2dot.py and ...
0
8170
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8675
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8619
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8334
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8474
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7158
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5561
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4078
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.