Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / June 2007

Tip: Looking for answers? Try searching our database.

How can I create an XSD document based on an XML file content?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bill Nguyen - 05 Jun 2007 00:28 GMT
Is it possible to create your won XSD to use with .NET based on an XML
content?
For example the one below:

<?xml version="1.0"?>
<pcats:FuelsDoc
xmlns="http://www.naxml.org/Retail-EDI/Vocabulary/2003-10-16"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="NAXML-FuelPrice15.xsd">
<pcats:TransmissionHeader>
<pcats:TransmissionId>200706040938</pcats:TransmissionId>
<pcats:TransmissionDate>2007-06-04</pcats:TransmissionDate>
<pcats:TransmissionTime>09:38:19-06:00</pcats:TransmissionTime>
<pcats:TransmissionStatus>original</pcats:TransmissionStatus>
<pcats:TransmissionSender>Apex Oil</pcats:TransmissionSender>
<pcats:TransmissionAgency>DTN Integrated
Services/dtnDataConnect</pcats:TransmissionAgency>
</pcats:TransmissionHeader>
<pcats:FuelPriceInfo>
<pcats:Terminal>
<pcats:Name identType="PlantNumber" ident="1070">
<pcats:NamePrefix>Frsn KMEP</pcats:NamePrefix>
</pcats:Name>
<pcats:City>Fresno</pcats:City>
<pcats:State>CA</pcats:State>
<pcats:FuelProduct><pcats:EffectiveDate>2007-06-04</pcats:EffectiveDate>
<pcats:EffectiveTime>10:00:00</pcats:EffectiveTime>
<pcats:FuelProductId identType="Ultra Low Sulfur CARB
#2">0402</pcats:FuelProductId>
<pcats:Price>2.240000</pcats:Price>
<pcats:NetChange>.040000</pcats:NetChange>
</pcats:FuelProduct>
</pcats:Terminal>
</pcats:FuelPriceInfo>
</pcats:FuelsDoc>

Thanks

Bill
Jerry N - 05 Jun 2007 00:55 GMT
I've used this XSD generator and like the output:
http://www.xmlforasp.net/codebank/system_data/XsdSchemaGenerator.aspx

Here's the output (after I made some minor changes to make it a valid XML
message):

<?xml version="1.0" encoding="utf-16"?>
<xs:schema id="FuelsDoc"
targetNamespace="http://www.naxml.org/Retail-EDI/Vocabulary/2003-10-16"
xmlns:mstns="http://www.naxml.org/Retail-EDI/Vocabulary/2003-10-16"
xmlns="http://www.naxml.org/Retail-EDI/Vocabulary/2003-10-16"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
attributeFormDefault="qualified" elementFormDefault="qualified">
 <xs:element name="FuelsDoc" msdata:IsDataSet="true"
msdata:UseCurrentLocale="true">
   <xs:complexType>
     <xs:choice minOccurs="0" maxOccurs="unbounded">
       <xs:element name="TransmissionHeader">
         <xs:complexType>
           <xs:sequence>
             <xs:element name="TransmissionId" type="xs:string"
minOccurs="0" />
             <xs:element name="TransmissionDate" type="xs:string"
minOccurs="0" />
             <xs:element name="TransmissionTime" type="xs:string"
minOccurs="0" />
             <xs:element name="TransmissionStatus" type="xs:string"
minOccurs="0" />
             <xs:element name="TransmissionSender" type="xs:string"
minOccurs="0" />
             <xs:element name="TransmissionAgency" type="xs:string"
minOccurs="0" />
           </xs:sequence>
         </xs:complexType>
       </xs:element>
       <xs:element name="FuelPriceInfo">
         <xs:complexType>
           <xs:sequence>
             <xs:element name="Terminal" minOccurs="0"
maxOccurs="unbounded">
               <xs:complexType>
                 <xs:sequence>
                   <xs:element name="City" type="xs:string" minOccurs="0"
/>
                   <xs:element name="State" type="xs:string" minOccurs="0"
/>
                   <xs:element name="Name" minOccurs="0"
maxOccurs="unbounded">
                     <xs:complexType>
                       <xs:sequence>
                         <xs:element name="NamePrefix" type="xs:string"
minOccurs="0" msdata:Ordinal="0" />
                       </xs:sequence>
                       <xs:attribute name="identType" form="unqualified"
type="xs:string" />
                       <xs:attribute name="ident" form="unqualified"
type="xs:string" />
                     </xs:complexType>
                   </xs:element>
                   <xs:element name="FuelProduct" minOccurs="0"
maxOccurs="unbounded">
                     <xs:complexType>
                       <xs:sequence>
                         <xs:element name="EffectiveDate" type="xs:string"
minOccurs="0" />
                         <xs:element name="EffectiveTime" type="xs:string"
minOccurs="0" />
                         <xs:element name="Price" type="xs:string"
minOccurs="0" />
                         <xs:element name="NetChange" type="xs:string"
minOccurs="0" />
                         <xs:element name="FuelProductId" nillable="true"
minOccurs="0" maxOccurs="unbounded">
                           <xs:complexType>
                             <xs:simpleContent
msdata:ColumnName="FuelProductId_Text" msdata:Ordinal="1">
                               <xs:extension base="xs:string">
                                 <xs:attribute name="identType"
form="unqualified" type="xs:string" />
                               </xs:extension>
                             </xs:simpleContent>
                           </xs:complexType>
                         </xs:element>
                       </xs:sequence>
                     </xs:complexType>
                   </xs:element>
                 </xs:sequence>
               </xs:complexType>
             </xs:element>
           </xs:sequence>
         </xs:complexType>
       </xs:element>
     </xs:choice>
   </xs:complexType>
 </xs:element>
</xs:schema>

> Is it possible to create your won XSD to use with .NET based on an XML
> content?
[quoted text clipped - 35 lines]
>
> Bill
Bill Nguyen - 05 Jun 2007 17:44 GMT
Jerry;
I don't know how you did it, but I got Invalid XML file message when trying
to generate an XSD!

Bill

> I've used this XSD generator and like the output:
> http://www.xmlforasp.net/codebank/system_data/XsdSchemaGenerator.aspx
[quoted text clipped - 133 lines]
>>
>> Bill
Bill Nguyen - 05 Jun 2007 17:53 GMT
Jerry;
I got an error message regarding 'pcats' namespace is undeclared. It seems
to me that 'pcats' was removed from the xsd file you generated!

Thanks

Bill
> I've used this XSD generator and like the output:
> http://www.xmlforasp.net/codebank/system_data/XsdSchemaGenerator.aspx
[quoted text clipped - 133 lines]
>>
>> Bill
Jerry N - 05 Jun 2007 18:39 GMT
Yes, I removed the 'pcats' prefix to get it to work.  I forgot to include it
in my original reply.  When you add the namespace declaration, I hope this
web page works better.

Jerry

> Jerry;
> I got an error message regarding 'pcats' namespace is undeclared. It seems
[quoted text clipped - 140 lines]
>>>
>>> Bill
Bill Nguyen - 05 Jun 2007 19:11 GMT
Jerry;
Where do I need to add the 'pcats' namespace declaration?
THanks
Bill
> Yes, I removed the 'pcats' prefix to get it to work.  I forgot to include
> it in my original reply.  When you add the namespace declaration, I hope
[quoted text clipped - 146 lines]
>>>>
>>>> Bill
Jerry N - 05 Jun 2007 19:26 GMT
Martin Honnen had an example buried in his message.  I added it to the
FuelsDoc declarations as shown below.  I also tested it on the web page
(http://www.xmlforasp.net/codebank/system_data/XsdSchemaGenerator.aspx).

<?xml version="1.0"?>
<pcats:FuelsDoc
xmlns="http://www.naxml.org/Retail-EDI/Vocabulary/2003-10-16"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:pcats="http://example.com/ns1"
xsi:schemaLocation="NAXML-FuelPrice15.xsd">
<pcats:TransmissionHeader>
<pcats:TransmissionId>200706040938</pcats:TransmissionId>
<pcats:TransmissionDate>2007-06-04</pcats:TransmissionDate>
<pcats:TransmissionTime>09:38:19-06:00</pcats:TransmissionTime>
<pcats:TransmissionStatus>original</pcats:TransmissionStatus>
<pcats:TransmissionSender>Apex Oil</pcats:TransmissionSender>
<pcats:TransmissionAgency>DTN Integrated
Services/dtnDataConnect</pcats:TransmissionAgency>
</pcats:TransmissionHeader>
<pcats:FuelPriceInfo>
<pcats:Terminal>
<pcats:Name identType="PlantNumber" ident="1070">
<pcats:NamePrefix>Frsn KMEP</pcats:NamePrefix>
</pcats:Name>
<pcats:City>Fresno</pcats:City>
<pcats:State>CA</pcats:State>
<pcats:FuelProduct><pcats:EffectiveDate>2007-06-04</pcats:EffectiveDate>
<pcats:EffectiveTime>10:00:00</pcats:EffectiveTime>
<pcats:FuelProductId identType="Ultra Low Sulfur CARB
#2">0402</pcats:FuelProductId>
<pcats:Price>2.240000</pcats:Price>
<pcats:NetChange>.040000</pcats:NetChange>
</pcats:FuelProduct>
</pcats:Terminal>
</pcats:FuelPriceInfo>
</pcats:FuelsDoc>

> Jerry;
> Where do I need to add the 'pcats' namespace declaration?
[quoted text clipped - 150 lines]
>>>>>
>>>>> Bill
Bill Nguyen - 06 Jun 2007 15:41 GMT
Jerry;
You're correct.
I played with the new xsd and it seemed to work , but only for the 1st table
<transmissionHeader> in the dataset.
When I tried to read the <fuelPriceInfo> record, I got error since
<terminal> and <fuelproduct> are nested.
Can you please help with the .readxml syntax for nested items?

Thanks

Bill

> Martin Honnen had an example buried in his message.  I added it to the
> FuelsDoc declarations as shown below.  I also tested it on the web page
[quoted text clipped - 15 lines]
> Services/dtnDataConnect</pcats:TransmissionAgency>
> </pcats:TransmissionHeader>

> <pcats:FuelPriceInfo>

> <pcats:Terminal>

> <pcats:Name identType="PlantNumber" ident="1070">
> <pcats:NamePrefix>Frsn KMEP</pcats:NamePrefix>
> </pcats:Name>

> <pcats:City>Fresno</pcats:City>
> <pcats:State>CA</pcats:State>

> <pcats:FuelProduct><pcats:EffectiveDate>2007-06-04</pcats:EffectiveDate>
> <pcats:EffectiveTime>10:00:00</pcats:EffectiveTime>
[quoted text clipped - 3 lines]
> <pcats:NetChange>.040000</pcats:NetChange>
> </pcats:FuelProduct>

> </pcats:Terminal>

> </pcats:FuelPriceInfo>

> </pcats:FuelsDoc>
>
[quoted text clipped - 152 lines]
>>>>>>
>>>>>> Bill
Jerry N - 06 Jun 2007 16:47 GMT
I loaded the generated schema into VS.NET 2005 and it displayed good
diagram.  It looks like you're trying to take the next step and load
relational tables into a dataset from an XML file.  I would take a look at
"Typed DataSets" and create a separate typed dataset so you can examine the
code that gets generated.  You'll need to find out how to create the
ForeignKeyConstraints, etc.

I would also recommend a book "Pragmatic ADO.NET" by Shawn Wildermuth since
it has several chapters on DataSets, Typed DataSets, etc.

Jerry

> Jerry;
> You're correct.
[quoted text clipped - 207 lines]
>>>>>>>
>>>>>>> Bill
Martin Honnen - 05 Jun 2007 12:09 GMT
> Is it possible to create your won XSD to use with .NET based on an XML
> content?

The .NET framework SDK has a tool named xsd.exe which can do that.

And the .NET framework (2.0 and later) has a class XmlSchemaInference
which has a method InferSchema:
<http://msdn2.microsoft.com/en-us/library/system.xml.schema.xmlschemainference.aspx>

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

Bill Nguyen - 05 Jun 2007 18:09 GMT
Martin;
I used the same XML file and got the same error:

'pcats' is an undeclare namespace. Line 2, position 2.
'pcats' is all over in the XML file.

What Am I missing here?

Thanks

Private Sub SchemaReference()

Dim dPath = "\\nasserver\archive$\FTP\DTN\DTN_PCATS\"

Dim reader As XmlReader = XmlReader.Create(dPath & "testnaxml.xml")

Dim schemaSet As XmlSchemaSet = New XmlSchemaSet()

Dim schema As XmlSchemaInference = New XmlSchemaInference()

schemaSet = schema.InferSchema(reader)

For Each s As XmlSchema In schemaSet.Schemas()

s.Write(Console.Out)

Next

End Sub

--- TESTNAXML.XML --------

<?xml version="1.0"?>
<pcats:NAXML-FuelsDoc
xmlns="http://www.naxml.org/Retail-EDI/Vocabulary/2003-10-16"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="NAXML-FuelPrice15.xsd">
<pcats:TransmissionHeader>
<pcats:TransmissionId>200706040938</pcats:TransmissionId>
<pcats:TransmissionDate>2007-06-04</pcats:TransmissionDate>
<pcats:TransmissionTime>09:38:19-06:00</pcats:TransmissionTime>
<pcats:TransmissionStatus>original</pcats:TransmissionStatus>
<pcats:TransmissionSender>Apex Oil</pcats:TransmissionSender>
<pcats:TransmissionAgency>DTN Integrated
Services/dtnDataConnect</pcats:TransmissionAgency>
</pcats:TransmissionHeader>
<pcats:FuelPriceInfo>
<pcats:Terminal>
<pcats:Name identType="PlantNumber" ident="1070">
<pcats:NamePrefix>Frsn KMEP</pcats:NamePrefix>
</pcats:Name>
<pcats:City>Fresno</pcats:City>
<pcats:State>CA</pcats:State>
<pcats:FuelProduct><pcats:EffectiveDate>2007-06-04</pcats:EffectiveDate>
<pcats:EffectiveTime>10:00:00</pcats:EffectiveTime>
<pcats:FuelProductId identType="Ultra Low Sulfur CARB
#2">0402</pcats:FuelProductId>
<pcats:Price>2.240000</pcats:Price>
<pcats:NetChange>.040000</pcats:NetChange>
</pcats:FuelProduct>
</pcats:Terminal>
</pcats:FuelPriceInfo>
</pcats:NAXML-FuelsDoc>

>> Is it possible to create your won XSD to use with .NET based on an XML
>> content?
[quoted text clipped - 4 lines]
> which has a method InferSchema:
> <http://msdn2.microsoft.com/en-us/library/system.xml.schema.xmlschemainference.aspx>
Martin Honnen - 05 Jun 2007 18:17 GMT
> I used the same XML file and got the same error:
>
> 'pcats' is an undeclare namespace. Line 2, position 2.
> 'pcats' is all over in the XML file.

So your XML sample is not well-formed:

> <pcats:FuelsDoc
> xmlns="http://www.naxml.org/Retail-EDI/Vocabulary/2003-10-16"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="NAXML-FuelPrice15.xsd">

it needs a namespace declaration for the prefix pcats e.g.

> <pcats:FuelsDoc
> xmlns="http://www.naxml.org/Retail-EDI/Vocabulary/2003-10-16"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:pcats="http://example.com/ns1"
> xsi:schemaLocation="NAXML-FuelPrice15.xsd">

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

Stan Kitsis [MSFT] - 07 Jun 2007 19:30 GMT
You can also load your xml file into VS2005 and click "Create Schema" button
(or access it from the XML menu).
When you load the file into VS, it will also list all the errors you have in
it.

Signature

Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

> Is it possible to create your won XSD to use with .NET based on an XML
> content?
[quoted text clipped - 35 lines]
>
> Bill
edujygzkmf - 22 Jun 2007 00:08 GMT
Hello! Good Site! Thanks you! cxdgkijybd

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.