Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New Coder
    Join Date
    Jun 2012
    Posts
    40
    Thanks
    11
    Thanked 0 Times in 0 Posts

    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?

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,197
    Thanks
    23
    Thanked 605 Times in 604 Posts
    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.

  • #3
    New Coder
    Join Date
    Jun 2012
    Posts
    40
    Thanks
    11
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,197
    Thanks
    23
    Thanked 605 Times in 604 Posts
    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.

  • #5
    New Coder
    Join Date
    Jun 2012
    Posts
    40
    Thanks
    11
    Thanked 0 Times in 0 Posts
    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...

  • #6
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,197
    Thanks
    23
    Thanked 605 Times in 604 Posts
    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

  • Users who have thanked sunfighter for this post:

    Rcoleman25 (02-10-2013)

  • #7
    New Coder
    Join Date
    Jun 2012
    Posts
    40
    Thanks
    11
    Thanked 0 Times in 0 Posts
    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.

  • #8
    Regular Coder jamesicus's Avatar
    Join Date
    Oct 2008
    Posts
    106
    Thanks
    0
    Thanked 11 Times in 10 Posts
    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.

  • #9
    New Coder
    Join Date
    Jun 2012
    Posts
    40
    Thanks
    11
    Thanked 0 Times in 0 Posts
    So I basically need to rebuild my entire page in XML? or I can have the XML elements inside the HTML?

  • #10
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,197
    Thanks
    23
    Thanked 605 Times in 604 Posts
    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.

  • #11
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    very informative discussion. i really like this discussion.

  • #12
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,640
    Thanks
    0
    Thanked 649 Times in 639 Posts
    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/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

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