Go Back   CodingForums.com > :: Client side development > XML

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-08-2013, 01:14 AM   PM User | #1
Rcoleman25
New Coder

 
Join Date: Jun 2012
Posts: 18
Thanks: 8
Thanked 0 Times in 0 Posts
Rcoleman25 is an unknown quantity at this point
Making HTML page work with XML?

Hello,

I am building a database which will integrate with the database of another company, they will essentially push information from their database to mine. My question has to do with XML. The database will identify different truck types that users will be able to search for when they check a box. A flatbed truck will look like this

Code:
<h1>Equipment Types</h1>
<span><input type="checkbox" name="equipment" value="flatbed">
Flatbed</span>
.......
<h1>Equipment Specifications</h1>
<label><input type="checkbox" name="specs" value="btrain">B-Train Flatbed</label>
<label><input type="checkbox" name="specs" value="sides">
With Sides</label>
So basically when the user checks the box they will select the flatbed truck and will have the choice of selecting additional specifications, however... here is an example of the xml schema for the other company that I will integrate with

Code:
<xs:element name="equipment">
<xs:complexType>
<xs:choice minOccurs="1" maxOccurs="unbounded">
<xs:element name="f"> <!-- Flatbed -->
<xs:complexType>
<xs:attribute name="b-train" type="xs:boolean" default="false"/> <!-- B-train -->
<xs:attribute name="sides" type="xs:boolean" default="false"/> <!-- with Sides -->
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
Essentially, the elements are the vehicle types and the attributes are the additional specifications. Now how do I integrate that with my HTML so that when a user checks a box it selects the element and attribute to work with the database?
Rcoleman25 is offline   Reply With Quote
Old 02-08-2013, 02:50 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,383
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
What you have is not an xml file, it is an XML Schema, a file that describes the structure of an XML document. It is used to write the xml.
From w3schools:
A xml file:
Code:
<?xml version="1.0"?>
<note>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>
The following example is an XML Schema file called "note.xsd" that defines the elements of the XML document above ("note.xml"):
Code:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">

<xs:element name="note">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="to" type="xs:string"/>
      <xs:element name="from" type="xs:string"/>
      <xs:element name="heading" type="xs:string"/>
      <xs:element name="body" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

</xs:schema>
If your getting from another site either ask them for the xml not the xsd or ask them to generate one for you.
sunfighter is offline   Reply With Quote
Old 02-08-2013, 04:55 PM   PM User | #3
Rcoleman25
New Coder

 
Join Date: Jun 2012
Posts: 18
Thanks: 8
Thanked 0 Times in 0 Posts
Rcoleman25 is an unknown quantity at this point
Quote:
Originally Posted by sunfighter View Post
What you have is not an xml file, it is an XML Schema, a file that describes the structure of an XML document. It is used to write the xml.
From w3schools:
A xml file:
Code:
<?xml version="1.0"?>
<note>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>
The following example is an XML Schema file called "note.xsd" that defines the elements of the XML document above ("note.xml"):
Code:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">

<xs:element name="note">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="to" type="xs:string"/>
      <xs:element name="from" type="xs:string"/>
      <xs:element name="heading" type="xs:string"/>
      <xs:element name="body" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

</xs:schema>
If your getting from another site either ask them for the xml not the xsd or ask them to generate one for you.
Yes... the XML schema basically shows how the XML should be layed out in my file. My question is how do I lay out/embed the XML in my HTML file.
Rcoleman25 is offline   Reply With Quote
Old 02-09-2013, 02:29 AM   PM User | #4
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,383
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
Excuse these old eyes, especially early in the morning (at lest for me); you did state that this was an XML schema.

We need an xml file to read into the html not a XML schema.

Your example with the checkboxs looks for what? You don't say. Or are you trying to make the section with the checkboxes from the xml file?

I really do not know what you want. And most importantly to work with an xml file we need that xml file.

Last edited by sunfighter; 02-09-2013 at 10:09 PM..
sunfighter is offline   Reply With Quote
Old 02-10-2013, 06:17 PM   PM User | #5
Rcoleman25
New Coder

 
Join Date: Jun 2012
Posts: 18
Thanks: 8
Thanked 0 Times in 0 Posts
Rcoleman25 is an unknown quantity at this point
Quote:
Originally Posted by sunfighter View Post
Excuse these old eyes, especially early in the morning (at lest for me); you did state that this was an XML schema.

We need an xml file to read into the html not a XML schema.

Your example with the checkboxs looks for what? You don't say. Or are you trying to make the section with the checkboxes from the xml file?

I really do not know what you want. And most importantly to work with an xml file we need that xml file.
Yes... that is what I'm trying to build... This is the situation. I am building a load board which looks for certain trucks such as reefer, van, flatbed, etc. with certain specifications(attributes) such as sides, removable gooseneck, etc. I am working with another website which will push the information from their server to my server and allow my members to search for the specified critera, their XML schema shows how the equipment is mapped...
Rcoleman25 is offline   Reply With Quote
Old 02-10-2013, 08:09 PM   PM User | #6
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,383
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
The XML schema you were given is not well-formed. I checked it in XML Copy Editor. To get things right the schema S/B:
Code:
<?xml version="1.0"?>
<xs:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="test.xml">

<xs:element name="equipment">
<xs:complexType>
<xs:choice minOccurs="1" maxOccurs="unbounded">
<xs:element name="f"> <!-- Flatbed -->
<xs:complexType>
<xs:attribute name="b-train" type="xs:boolean" default="false"></xs:attribute> <!-- B-train -->
<xs:attribute name="sides" type="xs:boolean" default="false"></xs:attribute> <!-- with Sides -->
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
Next type="xs:boolean" gives problems because we need to write things out in html "xs:string" would be a lot nicer.

Here is a fast transfer from xml to html in php, but I do not understand how your going to do a look up with the info you have supplied.
Code:
<?php
$xmlString = <<<XML
<?xml version="1.0" encoding="utf-8"?>
<equipment>
  <choice>
    <f b-train="true" sides="true">Flatbed</f>
  </choice>
</equipment>
XML;

$xmldata = simplexml_load_string($xmlString);

foreach($xmldata->choice as $item)
{
	echo "<h1>Equipment Types</h1>";
	echo '<span><input type="checkbox" name="equipment" value="flatbed">'.$item->f.'</span>';
	echo "<br />.......";
	echo "<h1>Equipment Specifications</h1>";
	if($item->f["b-train"] == "true"){
		echo '<label><input type="checkbox" name="specs" value="btrain">B-Train Flatbed</label><br>';
	}else{
		echo "No b-trains<br>";
	}

	if($item->f["sides"] == "true"){
		echo '<label><input type="checkbox" name="specs" value="sides">With Sides</label>';
	}else{
		echo "No sides<br>";
	}
}
?>
$xmlString is the xml based on the schema
sunfighter is offline   Reply With Quote
Users who have thanked sunfighter for this post:
Rcoleman25 (02-10-2013)
Old 02-10-2013, 11:39 PM   PM User | #7
Rcoleman25
New Coder

 
Join Date: Jun 2012
Posts: 18
Thanks: 8
Thanked 0 Times in 0 Posts
Rcoleman25 is an unknown quantity at this point
Here is the whole XML schema... it just provided a snippet of it... my fault!

Code:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="equipment">
  <xs:complexType>
    <xs:choice minOccurs="1" maxOccurs="unbounded">
      <xs:element name="ac"></xs:element> <!-- Auto Carrier -->
      <xs:element name="dd"></xs:element> <!-- Double Drop -->
      <xs:element name="dt"></xs:element> <!-- Dump Trailer -->
      <xs:element name="f"> <!-- Flatbed -->
        <xs:complexType>
          <xs:attribute name="b-train" type="xs:boolean" default="false"/> <!-- B-train -->
          <xs:attribute name="sides" type="xs:boolean" default="false"/> <!-- with Sides -->
          <xs:attribute name="tarps" type="xs:boolean" default="false"/> <!-- with Tarps -->
          <xs:attribute name="palletexchange" type="xs:boolean" default="false"/> <!-- with Pallet Exchange -->
          <xs:attribute name="hazmat" type="xs:boolean" default="false"/> <!-- Hazmat -->
          <xs:attribute name="maxi" type="xs:boolean" default="false"/> <!-- Maxi -->
          <xs:attribute name="team" type="xs:boolean" default="false"/> <!-- Team -->
          <xs:attribute name="hotshot" type="xs:boolean" default="false"/> <!-- Hotshot -->
        </xs:complexType>
      </xs:element>
      <xs:element name="hb"></xs:element> <!-- Hopper Bottom -->
      <xs:element name="lb"></xs:element> <!-- Low Boy -->
      <xs:element name="po"></xs:element> <!-- Power Only -->
      <xs:element name="r"> <!-- Reefer -->
        <xs:complexType>
          <xs:attribute name="palletexchange" type="xs:boolean" default="false"/> <!-- Pallet Exchange -->
          <xs:attribute name="hazmat" type="xs:boolean" default="false"/> <!-- Hazmat -->
	</xs:complexType>
      </xs:element>
      <xs:element name="sd"> <!-- Step Deck -->
        <xs:complexType>
          <xs:attribute name="removablegooseneck" type="xs:boolean" default="false"/> <!-- Removeable Goosneck -->
	</xs:complexType>
      </xs:element>
      <xs:element name="t"></xs:element> <!-- Tanker -->
      <xs:element name="v"> <!-- Van -->
        <xs:complexType>
          <xs:attribute name="airride" type="xs:boolean" default="false"/> <!-- Air Ride -->
          <xs:attribute name="curtains" type="xs:boolean" default="false"/> <!-- with Curtains -->
          <xs:attribute name="hazmat" type="xs:boolean" default="false"/> <!-- Hazmat -->
          <xs:attribute name="palletexchange" type="xs:boolean" default="false"/> <!-- Pallet Exchange -->
          <xs:attribute name="team" type="xs:boolean" default="false"/> <!-- Team -->
          <xs:attribute name="vented" type="xs:boolean" default="false"/> <!-- Vented -->
          <xs:attribute name="walkingfloor" type="xs:boolean" default="false"/> <!-- Walking Floor -->
	</xs:complexType>
      </xs:element>
    </xs:choice>
  </xs:complexType>
</xs:element>

</xs:schema>
I'm going to divide the actual HTML into Equipment Types and Equipment Specs... two seperate checklists to reduce data redundancy. For example, the specs will consist of such attributes as 'pallet exchange' and 'hazmat' because multiple types of equipment can have those features and there is no point in having a dropdown for the same types of features under multiple types of equipment when I can just have them includes in equipment specs.
Rcoleman25 is offline   Reply With Quote
Old 02-13-2013, 05:44 PM   PM User | #8
jamesicus
Regular Coder

 
jamesicus's Avatar
 
Join Date: Oct 2008
Posts: 106
Thanks: 0
Thanked 11 Times in 10 Posts
jamesicus is an unknown quantity at this point
It sounds like you are ready to venture into RDFa ..........

The Semantic Web

James
__________________
Web Developer Tool Kit - for creating Standards compliant and Interoperable web pages
W3C Markup Validation Service - validate HTML code for reliable rendering in all Browsers
WAVE accessibility evaluation tool - check page structure, image alt text, form labels, etc.
jamesicus is offline   Reply With Quote
Old 02-13-2013, 06:59 PM   PM User | #9
Rcoleman25
New Coder

 
Join Date: Jun 2012
Posts: 18
Thanks: 8
Thanked 0 Times in 0 Posts
Rcoleman25 is an unknown quantity at this point
So I basically need to rebuild my entire page in XML? or I can have the XML elements inside the HTML?
Rcoleman25 is offline   Reply With Quote
Old 02-22-2013, 02:49 PM   PM User | #10
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,383
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
R coleman, You use javascript or a server side program (like php) to read the xml file and place the information into the html.

I am having trouble trying to visualize the html page. Could you give us a link or post the code here? Would also like to see the xml you came up with.
sunfighter is offline   Reply With Quote
Old 03-05-2013, 06:27 AM   PM User | #11
Lisbon
New to the CF scene

 
Join Date: Sep 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Lisbon is an unknown quantity at this point
very informative discussion. i really like this discussion.
Lisbon is offline   Reply With Quote
Old 03-05-2013, 08:30 AM   PM User | #12
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,454
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Quote:
Originally Posted by Rcoleman25 View Post
So I basically need to rebuild my entire page in XML? or I can have the XML elements inside the HTML?
XHTML is a subset of XML so if you use XHTML 1.0 instead of HTML 4.01 (or XHTML 5 instead of HTML 5) then you can combine it with other XML simply by including the correct references at the top of the file to identify what rules the different tags are supposed to follow.

Note that Internet Explorer 8 doesn't support XHTML and offers XHTML files for download instead of displaying them.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is online now   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:04 AM.


Advertisement
Log in to turn off these ads.