Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
Hi i have been struggling to create a web app that has a
dropdown list which contains a few xml files, when selecting one it should display that xml file in a control. it also needs to have a button to update that xml file and save it.



My code:
C#
DirectoryInfo dirInfo = new DirectoryInfo(Server.MapPath("/ZoneScripts"));
                FileInfo[] fileList = dirInfo.GetFiles();
                foreach (FileInfo fileInfo in fileList)
                {
                    dropdownlist.Items.Add(new ListItem(fileInfo.Name, fileInfo.Name)); // this loads the xml files into the dropdown list
                }


This is the load script method // loading the scrip from file
C#
public void LoadScript()
{
string scriptpath = Server.MapPath("/ZoneScripts/" + dropdownlist.SelectedValue.ToString());
            ZoneScript myscript = new ZoneScript(scriptpath);
            myscript = myscript.LoadFile();

if ( myScript.greeting != null ) //greeting to be displayed from xml file
                      // how do i populate the script in a control (eg. textbox)

 if ( myScript.idVerification != null ) // idverification to be displayed from xml file
                 // how do i populate the script in a control (eg. textbox)
   if ( myScript.delivery != null ) //delivery t be displayed from xml file

and so on displaying the xml file in a control..
}


I then have a button DisplayScripts()// when i click the button the xml script that is selected from the dropdown will be displayed in the textboxes
C#
protected void btnDisplayScript_Click( object sender, EventArgs e )
		{
                  Loadscript();
                  }


below is an example of one of my xml files


XML
<ZoneScript xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <greeting>
    <data>Good Day my name is (var)operationsuser.firstName(/var) (var)operationsuser.surname(/var).May I please speak to (var)deliveryconsolidation.ConsigneeName(/var)?</data>
    <data>I am calling to confirm your order( (var)customercardproducttype.descriptions(/var) card ) </data>
    <data></data>
  </greeting>
  <idVerification>
    <data>(var)DeliveryConsolidation.consigneename(/var), before we proceed with the delivery arrangements, could you please confirm your initials in your id book as it has to correspond to what we received from the bank.</data>
    <data></data>
    <fullIdCheck>
      <data>(var)DeliveryConsolidation.consigneename(/var) for security purposes would you please confirm your identity number.</data>
      <data></data>
    </fullIdCheck>
    <defaultIdCheck>
      <data>(var)DeliveryConsolidation.consigneename(/var) for security purposes would you please confirm your date of birth.</data>
      <data></data>
    </defaultIdCheck>

  </idVerification>
  <delivery>
    <data>I would like to arrange the delivery of your order either tomorrow or on a date convenient to you.</data>
    <data></data>
  </delivery>
  <ficaRequired>
    <Title>Documents Required</Title>
    <data>(var)DeliveryConsolidation.consigneename(/var) can you please have the following documents ready for the driver upon delivery.</data>
    <data></data>
    <ficaTypes>
      <ficaType ficaName="original ID and Copy Of ID" banks="ALL">
        <data>(var)DeliveryConsolidation.consigneename(/var) please make sure that your eyes, nose, mouth and chin are clearly visible</data>
        <data></data>
      </ficaType>
      <ficaType ficaName="Proof Of Residence not older than 3 months" banks="MGSA STDC BARC FNBC NEDC ABSA VMSA BCSA">
        <data>(var)DeliveryConsolidation.consigneename(/var), please ensure that the initials on your proof of residence correspond with the initials in your id document and that it has the same street name, suburb and postal code you provided to the bank, or we will not be able to deliver your credit card.</data>
        <data>All proof of residence posted to a P.O.Box will not be accepted.</data>
        <data>IF:</data>
        <data>Co-Habitant:(var)DeliveryConsolidation.consigneename(/var) could you please get a written affidavit from the OWNER signed in front of a commissioner of oath? (Owner must also give proof of residence, relationship must be stated in affidavit and your id number and owner's id number must appear in the affidavit.)</data>
        <data>Where Client supplies 'Lease/Rental Agreement': Must be the entire agreement, initialled on every page by the client and stamped and signed by the driver.</data>
        <data></data>
      </ficaType>
      <ficaType ficaName="Copy of Proof Of Income not older than 3 months" banks="MGSA ABSA VMSA BCSA">
        <data>(var)DeliveryConsolidation.consigneename(/var) are you a commission earner?</data>
        <data>YES: (var)DeliveryConsolidation.consigneename(/var), could you please prepare copies of the last 3 months bankstatements/payslips or 1 payslip indicating the progressive taxable income( not older than 3 months), with your name and surname on it?</data>
        <data>NO: (var)DeliveryConsolidation.consigneename(/var), could you please prepare copies of the last 3 months bankstatements or a copy of your payslip, not older than 3 months, with your name and surname on it?</data>
        <data></data>
      </ficaType>
    </ficaTypes>
  </ficaRequired>
  <title>Zone Control Guide</title>
  <ficaExample>
    <ficaTypes>
      <ficaType ficaName="Examples of Proof Of Residence" banks="ALL">
        <data>(Bankstatements from another bank less than 3 months old )</data>
        <data>(Municipal rates and taxes invoice less than 3 months old )</data>
        <data>(Telkom or cell phone account less than 3 months old )</data>
        <data>(Offical SARS document less than 1 year old )</data>
        <data>(Recent/long term insurance policy documents )</data>
      </ficaType>
    </ficaTypes>
  </ficaExample>
  <ending>
    <data>
      (var)DeliveryConsolidation.consigneename(/var), if you are unsure about any of the FICA requirements for your (var)customercardproducttype.descriptions(/var) card, you can contact ABSA on the following number for clarification, 012-317-3323.
    </data>
    <data></data>
    <data>(var)DeliveryConsolidation.consigneename(/var) my driver will give you a call half an hour before delivering the card to you. Which number would you like him to call you on?</data>
    <finalEndings>
      <string>(var)DeliveryConsolidation.consigneeContact(/var) thank you for your time. Good day.</string>
    </finalEndings>
    <Title>Confirm All Special Instructions</Title>
  </ending>
</ZoneScript>
Posted
Updated 31-Mar-15 1:01am
v3
Comments
Sinisa Hajnal 31-Mar-15 5:06am    
So, what is the problem? Loading the file? Editing it? Where is the code that doesn't work? You have to show what you're tried...or restate your question to make it clearer.

Use Improve question link. Thank you.
Member 10353114 31-Mar-15 5:24am    
hi, i have my program saved of what i did. is it possible for me to email it to you? I am having a problem loading it into a control and editing it.
Sinisa Hajnal 31-Mar-15 6:42am    
No, don't mail it...I would have to set up the project and work from there - and I cannot do that from work. Instead, use Improve question, copy ONLY RELEVANT code (that is, one that shows what you're doing and which part doesn't work) and explain which part doesn't work as you expect (see my previous comment and answer the questions there)
Member 10353114 31-Mar-15 7:04am    
i updated the question. please see if its clear enough
Sinisa Hajnal 31-Mar-15 10:54am    
It is, I just don't understand the part "how do I display the greeting"...you have the textbox for the greeting, right? So textbox.Text = myScript.greeting should be fairly obvious. Same for any other value or control. You might vary .Text with InnerText or InnerHtml for labels or panels, but that should be it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900