SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Outputting XML file

    I am trying to create an XML file using a PHP script. The XML File looks something like this:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <ConsumerDirectXML>
    <UserParams id="1" BrokerID="1"/>
    <LoanParams>
    <FirstLeinAmt>500000</FirstLeinAmt>
    <ChooseProductTypeID>1</ChooseProductTypeID>
    </LoanParams>
    </ConsumerDirectXML>

    The part that I don't understand is the following. I have a series of checkboxes with each box having a different value. If a user were to select 3 checkboxes I need to iterate through the array and write to the ChooseProductTypeID field in the XML file as such, <ChooseProductTypeID>1,5,7</ChooseProductTypeID>. I have been able to print out the array variable $num using the following foreach loop:

    foreach ($total as $num) {
    print("$num,"); }

    How would I get this string into the designated XML tag?

    Currently I am able to write to this XML file using textboxes and the following code for different XML tags in same file. How would I modify what I am currently using for textboxes to use for the checkboxes while utilitzing the foreach loop. Below is the method by which I am writting to my XML file:

    if ($node_name == "FirstLeinAmt") {
    if ($value == $firstlein) {
    // Do nothing
    } else {
    $fl_textnode = $child_obj->firstChild;
    $new_firstlein = $doc->createTextNode($firstlein);
    $child_obj->replaceChild($new_firstlein, $fl_textnode);
    }
    }
    foreach ($total as $num) {
    if ($node_name == "ChoosedProductTypeID") {
    if ($value == $num) {
    // Do nothing
    } else {
    $pt_textnode = $child_obj->firstChild;
    $new_num = $doc->createTextNode("$num,");
    $child_obj->replaceChild("$new_num", "$pt_textnode");
    }}
    ...


    Any help appreciated.

  2. #2
    SitePoint Zealot agoossens's Avatar
    Join Date
    Mar 2004
    Location
    Adelaide, Australia
    Posts
    124
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by chuy08
    How would I get this string into the designated XML tag?
    As you're writing that XML element, use implode() to concatenate the array of checkbox values together.

    Or am I not understanding what you're asking (very possible)?
    This space for rent.

  3. #3
    PHP Brainiac dg_den_golotyuk's Avatar
    Join Date
    Jul 2006
    Location
    Kiev, Ukraine
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can't understand too, where is your problem???
    DG [Den Golotyuk], Lead Developer
    Chestnut Software
    Avoid web outsourcing scams!
    Click here
    for a free downloadable report

  4. #4
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i think he didnt send any xml headers like: header('Content-type: text/xml');

  5. #5
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Let's see if I can clarify what I am trying to do

    I have designed a web form that is capturing various fields and when I click the submit button for the form I want it to create and XML file on the server. I am not trying to send it anywhere as of yet I am still trying to create the package.

  6. #6
    SitePoint Zealot agoossens's Avatar
    Join Date
    Mar 2004
    Location
    Adelaide, Australia
    Posts
    124
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Then you shoud do what I suggested earlier. As you write that element, insert the checkbox values before you write the end tag.

    What's the problem?
    This space for rent.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •