Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7993509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:52:06+00:00 2026-06-04T13:52:06+00:00

I am creating my first XSD, as I have a 4MB XML file I

  • 0

I am creating my first XSD, as I have a 4MB XML file I need to parse into SQL, and processing something that big takes far too long using untyped XML (I gave up and cancelled the query after an hour).

The XML file I have is in the following format (there are more elements for each product, but I shortened it and created a test XML file until I get it right):

 <ITEMS>
    <CREATED value="Wed May 2 9:40:38 BST 2012">
        <PRODUCT ITEM="0001">
            <MODEL>MODELNO1</MODEL>
            <BARCODE>5550204425</BARCODE>
            <TITLE>Item 1 Title</TITLE>
        </PRODUCT>
        <PRODUCT ITEM="0002">
            <MODEL>MODELNO2</MODEL>
            <BARCODE>52614343433</BARCODE>
            <TITLE>Item 2 Title</TITLE>         
        </PRODUCT>
        <PRODUCT ITEM="0003">
            <MODEL>MODELNO3</MODEL>
            <BARCODE>32563533</BARCODE>
            <TITLE>Item 3 Title</TITLE>         
        </PRODUCT>
        <PRODUCT ITEM="0004">
            <MODEL>MODELNO4</MODEL>
            <BARCODE>65135647582</BARCODE>
            <TITLE>Item 4 Title</TITLE>         
        </PRODUCT>
        <PRODUCT ITEM="0005">
            <MODEL>MODELNO5</MODEL>
            <BARCODE>65874112</BARCODE>
            <TITLE>Item 4 Title</TITLE>         
        </PRODUCT>
    </CREATED>
   </ITEMS>

This XML file is auto-generated by an external supplier system, and I have no choice but to work with it in its current format.

I created this schema for it:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="ITEMS">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="CREATED">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="PRODUCT" maxOccurs="unbounded">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element name="MODEL" type="xs:string" maxOccurs="unbounded" />
                                        <xs:element name="BARCODE" type="xs:string" maxOccurs="unbounded" />
                                        <xs:element name="TITLE" type="xs:string" maxOccurs="unbounded" />
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

In SQL, I first created a schema collection, like so:

IF EXISTS ( SELECT * FROM sys.xml_schema_collections where [name] = 'MyXmlSchema')
DROP XML SCHEMA COLLECTION [MyXmlSchema]
GO

DECLARE @MySchema XML
SET @MySchema = 
(
    SELECT * FROM OPENROWSET
    (
        BULK 'C:\test\schema2.xsd', SINGLE_CLOB 
    ) AS xmlData
)

CREATE XML SCHEMA COLLECTION [MyXmlSchema] AS @MySchema 
GO

I then created a table based on the schema:

CREATE TABLE [dbo].[XMLProds] (
    [MODEL] xml(CONTENT dbo.[MyXmlSchema]) NOT NULL,
    [EAN] xml(CONTENT dbo.[MyXmlSchema]) NOT NULL,
    [NAME] xml(CONTENT dbo.[MyXmlSchema]) NOT NULL
)

And finally, validated the XML:

DECLARE @x2 XML ([MyXmlSchema])
SELECT @x2 = '<copied the code from the test XML file and pasted here>'

The validation didn’t like the date value in the ‘CREATED’ field, which I can live without as it’s only declared once and can be easily deleted. But it also didn’t like the ‘ITEM’ value in each of the product fields, which is problem no. 2. This can’t be ignored as it appears in every single item (all 2-3 thousand of them). Is there a way to get around this?

Just to crack on, I deleted the unwanted values from the test XML and the validation passed. I then executed this statement in an attempt to populate the table:

INSERT INTO XMLProds (MODEL, BARCODE, TITLE)

    SELECT X.product.query('MODEL').value('.', 'VARCHAR(20)'),
           X.product.query('BARCODE').value('.', 'VARCHAR(50)'),
           X.product.query('TITLE').value('.', 'VARCHAR(150)')

FROM (
    SELECT CAST(x AS XML)
    FROM OPENROWSET(BULK 'C:\test\Products2test.xml', SINGLE_BLOB) AS T(x)) AS T(x)
    CROSS APPLY x.nodes('/ITEMS/CREATED/PRODUCT') AS X(product);

..but was met with the following error:

Msg 6909, Level 16, State 1, Line 21 XML Validation: Text node is not
allowed at this location, the type was defined with element only
content or with simple content. Location: /

Any help with where I’m going wrong here would be greatly appreciated! Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T13:52:08+00:00Added an answer on June 4, 2026 at 1:52 pm

    I would start with a valid XSD. You’re missing the attributes, which is why you’re having troubles with the unwanted content.

    <?xml version="1.0" encoding="utf-8"?>
    <!--XML Schema generated by QTAssistant/XML Schema Refactoring (XSR) Module (http://www.paschidev.com)-->
    <xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <xsd:element name="ITEMS">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="CREATED">
              <xsd:complexType>
                <xsd:sequence>
                  <xsd:element maxOccurs="unbounded" name="PRODUCT">
                    <xsd:complexType>
                      <xsd:sequence>
                        <xsd:element name="MODEL" type="xsd:string" />
                        <xsd:element name="BARCODE" type="xsd:unsignedLong" />
                        <xsd:element name="TITLE" type="xsd:string" />
                      </xsd:sequence>
                      <xsd:attribute name="ITEM" type="xsd:unsignedByte" use="required" />
                    </xsd:complexType>
                  </xsd:element>
                </xsd:sequence>
                <xsd:attribute name="value" type="xsd:string" use="required" />
              </xsd:complexType>
            </xsd:element>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
    </xsd:schema>
    

    If it still doesn’t work, let me know.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating my first (!) database, and I have run into an issue
I am creating my first plugin and have a single function that controls the
I am creating my first wordpress plugin. one of the questions i have is
I'm creating my first application and I have a window consisting of multiple subclasses
I have created two wsdl files with shared types imported from xsd schema file.
I'm creating my first Python application (PyGTK) and will use a conf file. In
I'm creating my first non-console game in Visual C#. I have a player which
Just creating my first IntelliJ web application that runs on tomcat. The project ran
I have everything set up and I'm to the point of creating my first
Im creating my first app for Windows 8 and i have a question. In

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.