Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form --> xml --> remote server --> reply -->format in html/php

Status
Not open for further replies.

mattpark

Technical User
Apr 15, 2006
1
GB
Hey guys,

Having never played with xml before im after a piece of php coding to do the below:

HTML Form --> xml --> remote server --> reply -->format in html/php

Im collecting two pieces of user input, telephone and postcode.

Need to post to a remote server, telephone, postcode, username, password, and ID.

xml has to be posted in the following schema
Code:
  <?xml version="1.0" encoding="UTF-8" ?> 
- <xs:schema xmlns:xs="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema"[/URL] elementFormDefault="qualified" attributeFormDefault="unqualified">
- <xs:element name="check">
- <xs:annotation>
  <xs:documentation>example xml schema</xs:documentation> 
  </xs:annotation>
- <xs:complexType>
- <xs:all>
- <xs:element name="sp">
- <xs:complexType>
- <xs:all>
- <xs:element name="username">
- <xs:simpleType>
- <xs:restriction base="xs:string">
  <xs:maxLength value="50" /> 
  <xs:whiteSpace value="collapse" /> 
  </xs:restriction>
  </xs:simpleType>
  </xs:element>
- <xs:element name="password">
- <xs:simpleType>
- <xs:restriction base="xs:string">
  <xs:maxLength value="50" /> 
  <xs:whiteSpace value="collapse" /> 
  </xs:restriction>
  </xs:simpleType>
  </xs:element>
- <xs:element name="id">
- <xs:simpleType>
- <xs:restriction base="xs:string">
  <xs:length value="3" /> 
  </xs:restriction>
  </xs:simpleType>
  </xs:element>
  </xs:all>
  </xs:complexType>
  </xs:element>
- <xs:element name="check">
- <xs:complexType>
- <xs:all>
- <xs:element name="telephone">
- <xs:simpleType>
- <xs:restriction base="xs:string">
  <xs:maxLength value="12" /> 
  <xs:whiteSpace value="collapse" /> 
  </xs:restriction>
  </xs:simpleType>
  </xs:element>
- <xs:element name="postcode" minOccurs="0">
- <xs:simpleType>
- <xs:restriction base="xs:string">
  <xs:maxLength value="9" /> 
  <xs:whiteSpace value="preserve" /> 
  </xs:restriction>
  </xs:simpleType>
  </xs:element>
  </xs:all>
  </xs:complexType>
  </xs:element>
  </xs:all>
  </xs:complexType>
  </xs:element>
  </xs:schema>

Having posted the above to the remote server, i then want to format the reply in a nice fluffy userfriendly html/php formated page.

reply will be in the following format:

Code:
  <?xml version="1.0" encoding="UTF-8" ?> 

- <xs:schema xmlns:xs="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema"[/URL] elementFormDefault="qualified">
- <xs:element name="check">
- <xs:annotation>
  <xs:documentation>example results</xs:documentation> 
  </xs:annotation>
- <xs:complexType>
- <xs:sequence>
- <xs:element name="results">
- <xs:complexType>
- <xs:sequence>
- <xs:element name="info1">
  <xs:complexType /> 
  </xs:element>
- <xs:element name="info2">
  <xs:complexType /> 
  </xs:element>
- <xs:element name="info3">
  <xs:complexType /> 
  </xs:element>
- <xs:element name="info4">
  <xs:complexType /> 
  </xs:element>
- <xs:element name="info5">
  <xs:complexType /> 
  </xs:element>
- <xs:element name="info6">
  <xs:complexType /> 
  </xs:element>
- <xs:element name="info7">
  <xs:complexType /> 
  </xs:element>
- <xs:element name="info8">
  <xs:complexType /> 
  </xs:element>
- <xs:element name="info9">
  <xs:complexType /> 
  </xs:element>
  </xs:sequence>
  </xs:complexType>
  </xs:element>
- <xs:element name="error">
- <xs:complexType>
- <xs:sequence>
- <xs:element name="error_number">
  <xs:complexType /> 
  </xs:element>
- <xs:element name="error_desc">
  <xs:complexType /> 
  </xs:element>
  </xs:sequence>
  </xs:complexType>
  </xs:element>
  </xs:sequence>
  </xs:complexType>
  </xs:element>
  </xs:schema>


Would really appreciate any help, looking for a quick fix here!

Thanks

Matt :)
 
You PHP page will need to do the following:

1. Gather form variables

2. Tranform them to desired XML format:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<check>
  <sp>
    <username>String</username>
    <password>String</password>
    <id>Str</id>
  </sp>
  <check>
    <telephone>String</telephone>
    <postcode>String</postcode>
  </check>
</check>
3. Submit XML to remote server

4. Get response. Will be in form:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<check>
  <results>
    <info1/>
    <info2/>
    <info3/>
    <info4/>
    <info5/>
    <info6/>
    <info7/>
    <info8/>
    <info9/>
  </results>
  <error>
    <error_number/>
    <error_desc/>
  </error>
</check>

5. Transform the returned XML into HTML. Probably using XSL, although you could just use string manipulation.

6. Output HTML back to browser

Jon

"I don't regret this, but I both rue and lament it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top