How to convert XSD/XML TO HTML?

Last post 07-07-2009 3:18 AM by mstechnologysupport. 6 replies.

Sort Posts:

  • How to convert XSD/XML TO HTML?

    03-21-2009, 2:22 AM
    • Participant
      1,340 point Participant
    • My Crystal
    • Member since 06-08-2008, 2:09 PM
    • Guangzhou, China
    • Posts 334

    hi,all.
    I have serach this topic on google but can't find good solution.
    I want to do two things:
    1.convet  an xsd to a html segment that displays the schema.
    2.extract data from an xml that conforms to the xsd, then fill the html with the extracted data.

    For example,firstly convert the following xsd:
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
     <xs:element name="Customer">
      <xs:complexType>
       <xs:sequence>
        <xs:element name="Name" type="xs:string"/>
        <xs:element name="Address" type="xs:string"/>
        <xs:element name="Orders" type="Orders"/>
       </xs:sequence>
      </xs:complexType>
     </xs:element>
     <xs:complexType name="Orders">
      <xs:sequence>
       <xs:element name="Order" maxOccurs="unbounded">
        <xs:complexType>
         <xs:sequence>
          <xs:element name="OrderID" type="xs:int"/>
          <xs:element name="ShipCountry" type="xs:string"/>
         </xs:sequence>
        </xs:complexType>
       </xs:element>
      </xs:sequence>
     </xs:complexType>
    </xs:schema>

    to the following HTML:
        <div>
            <p>Name:<input type="text" id="name" /></p>
            <p>Address:<input type="text" id="address" /></p>
        </div>
        <table style="width: 100%;">
        <tr>
            <td>
                OrderID
            </td>
            <td>
                ShipCountry
            </td>
        </tr>
        <tr>
            <td>
            </td>
            <td>
            </td>
        </tr>
        <tr>
            <td>
            </td>
            <td>
            </td>
        </tr>
        </table>

    then, extract data from the following xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <Customer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Customers.xsd">
     <Name>yhq</Name>
     <Address>Guangzhou</Address>
     <Orders>
      <Order>
       <OrderID>1000</OrderID>
       <ShipCountry>China</ShipCountry>
      </Order>
      <Order>
       <OrderID>1001</OrderID>
       <ShipCountry>USA</ShipCountry>  
      </Order>
     </Orders>
    </Customer>

    so the final html is:

        <div>
            <p>Name:<input type="text" id="name" />yhq</p>
            <p>Address:<input type="text" id="address" />Guangzhou</p>
        </div>
        <table style="width: 100%;">
        <tr>
            <td>
                OrderID
            </td>
            <td>
                ShipCountry
            </td>
        </tr>
        <tr>
            <td>1000
            </td>
            <td>China
            </td>
        </tr>
        <tr>
            <td>1001
            </td>
            <td>USA
            </td>
        </tr>
        </table>

    The tough thing is that the convertor has to convert many xsd rather than just a specific xsd.
    Any suggestion is highly appreciated. Thank you.

    What really matters most is the chance to communicate with you, my friends, rather than marking my post as answer, though I would be really appreciated if you do so.

    ASP.NET 3.5 MCTS
  • Re: How to convert XSD/XML TO HTML?

    03-21-2009, 6:39 AM
    • All-Star
      36,316 point All-Star
    • rtpHarry
    • Member since 10-01-2006, 12:51 PM
    • Lincoln, England
    • Posts 5,847

     Hi,

    You can use XSLT to translate xml files to html.

     

    An XSD is just a special kind of xml file so I guess you could process this with an xslt file as well?

  • Re: How to convert XSD/XML TO HTML?

    03-21-2009, 8:57 AM
    • Participant
      1,340 point Participant
    • My Crystal
    • Member since 06-08-2008, 2:09 PM
    • Guangzhou, China
    • Posts 334

    hi, thanks for your reply.

    XSLT can convert XSD/XML to HTML. but I have to convert many XSDs, the Customers XSD in my example is just one of them. I want to create something like "intelligent XSD parser" that can convert every xsd to html so that i don't need to write a xslt for every xsd.

    What really matters most is the chance to communicate with you, my friends, rather than marking my post as answer, though I would be really appreciated if you do so.

    ASP.NET 3.5 MCTS
  • Re: How to convert XSD/XML TO HTML?

    03-22-2009, 7:40 PM
    • All-Star
      36,316 point All-Star
    • rtpHarry
    • Member since 10-01-2006, 12:51 PM
    • Lincoln, England
    • Posts 5,847

     Are you just trying to display the XSD rules in a browser as html?

    Or do you want it to process it in some way?

     

    If you are looking to display it in a web browser you just need to be replacing all < with &lt; and > with &gt; I think that should do it as the rest of the special characters will already be encoded to make it a valid xml based document.

  • Re: How to convert XSD/XML TO HTML?

    03-23-2009, 1:42 AM
    • Participant
      1,340 point Participant
    • My Crystal
    • Member since 06-08-2008, 2:09 PM
    • Guangzhou, China
    • Posts 334

    Sorry that i didn't describe what i want to do clearly.
    No, what I want to do isn't replacing all < with &lt; and > with &gt;.
    I want to display the xsd's "hiberarchy" rather than the "rules" in this way:
    start from the root element, for each of the child element & attribute:
    1.if the element's attribute't type or child element is xsd's built-in type such as int,string,bool, the attribute will be

    displyed as a text input(for int & string) html or radiobutton(for bool).
    2.if the element's child element's type is complex type, do step 1 until all element's type is xsd's built-in type.

    I want to implement this logic in a class's method so that whenever a xsd as the method's parameter is passed in, the method

    return a html segment that displys the hiberarchy of the xsd.
    what's more, I want the method to be something like "intelligent XSD parser" so that not only you can pass in a Customer xsd, you can also pass in a Product xsd, a Country xsd or other xsd, the method will return a corresponding html. So the following example is really just an example,

    For example,firstly convert the following xsd:
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
     <xs:element name="Customer">
      <xs:complexType>
       <xs:sequence>
        <xs:element name="Name" type="xs:string"/>
        <xs:element name="Address" type="xs:string"/>
        <xs:element name="Orders" type="Orders"/>
       </xs:sequence>
      </xs:complexType>
     </xs:element>
     <xs:complexType name="Orders">
      <xs:sequence>
       <xs:element name="Order" maxOccurs="unbounded">
        <xs:complexType>
         <xs:sequence>
          <xs:element name="OrderID" type="xs:int"/>
          <xs:element name="ShipCountry" type="xs:string"/>
         </xs:sequence>
        </xs:complexType>
       </xs:element>
      </xs:sequence>
     </xs:complexType>
    </xs:schema>

    to the following HTML:
        <div>
            <p>Name:<input type="text" id="name" /></p>
            <p>Address:<input type="text" id="address" /></p>
        </div>
        <table style="width: 100%;">
        <tr>
            <td>
                OrderID
            </td>
            <td>
                ShipCountry
            </td>
        </tr>
        <tr>
            <td>
            </td>
            <td>
            </td>
        </tr>
        <tr>
            <td>
            </td>
            <td>
            </td>
        </tr>
        </table>

     

    What really matters most is the chance to communicate with you, my friends, rather than marking my post as answer, though I would be really appreciated if you do so.

    ASP.NET 3.5 MCTS
  • Re: How to convert XSD/XML TO HTML?

    03-26-2009, 12:04 AM

    Hi,

    As previous post mentioned, XSD is an XML file in a special format, and in your scenario,  you can try to parse these special XML file manually with XML handling practice which provided by C#. And export to an html file, save it on your hard disk. As you mentioned that you have lots of XSD file for you to handle, you may build a batch process application, seek for all XSD files in one of your folder, process the files, output the html file and save it in another folder you defined.

    Thanks.

    Michael Jin.
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: How to convert XSD/XML TO HTML?

    07-07-2009, 3:18 AM

    Hi, i am trying to find solution for a XML/XSD  to HTML conversion for data entry.  Were you able to work through a solution for your question, if so please could you share.

    Thanks in advance.

Page 1 of 1 (7 items)