November 7, 2012 at 11:42 am
I am very far from an expert when it comes to working with xml - but I have some exposure to it. I was recently given a project to take some data we have in a spreadsheet, get it into SQL server, create a new table for it (as per our new vendors spec) and export it do a certain format XML. So I am at a point now where I have all of the data in the database, moved into the new table. I am struggling getting it into the proper XML format.
Our vendor gave us an xml format to get the data into but I just cannot seem to get it to work.
In the xml spec that I have I see - urn:schemas-microsoft-com:rowset - and I did a little bit of digging on this. I can use the "FOR XML AUTO TYPE(urn:schemas-microsoft-com:rowset)" to put it in this type - but the data doesn't look how the the company is expecting it.
I even tried to create a new xml schema using the xml file that was provided to me but I couldn't get this to work either. I am sure this is because of me and nothing else.
How should I go about accomplishing this?
Thanks in advance
sb
November 7, 2012 at 1:01 pm
stephenmbell (11/7/2012)
I am very far from an expert when it comes to working with xml - but I have some exposure to it. I was recently given a project to take some data we have in a spreadsheet, get it into SQL server, create a new table for it (as per our new vendors spec) and export it do a certain format XML. So I am at a point now where I have all of the data in the database, moved into the new table. I am struggling getting it into the proper XML format.Our vendor gave us an xml format to get the data into but I just cannot seem to get it to work.
In the xml spec that I have I see - urn:schemas-microsoft-com:rowset - and I did a little bit of digging on this. I can use the "FOR XML AUTO TYPE(urn:schemas-microsoft-com:rowset)" to put it in this type - but the data doesn't look how the the company is expecting it.
I even tried to create a new xml schema using the xml file that was provided to me but I couldn't get this to work either. I am sure this is because of me and nothing else.
How should I go about accomplishing this?
Thanks in advance
sb
From what you posted it is impossible to provide much help. We don't know what the table or the desired xml format looks like. Take a look at the first link in my signature about best practices when posting quetions.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
November 7, 2012 at 1:17 pm
My apologies:
Here is the table that I have created, and I have populated with data--
CREATE TABLE [dbo].[MyTable](
[Candidate First Name] [nvarchar](50) NULL,
[Candidate Middle Name] [nvarchar](25) NULL,
[Candidate Last Name] [nvarchar](50) NULL,
[Candidate Name Prefix] [nvarchar](50) NULL,
[Candidate Name Suffix] [nvarchar](50) NULL,
[Candidate Email] [nvarchar](100) NOT NULL,
[Candidate Address Line 1] [nvarchar](50) NULL,
[Candidate Address Line 2] [nvarchar](50) NULL,
[Candidate City] [nvarchar](50) NULL,
[Candidate State/Province/Region] [nvarchar](100) NOT NULL,
[Candidate Postal Code] [nvarchar](50) NOT NULL,
[Candidate Country] [nvarchar](5) NOT NULL,
[Candidate Primary Phone] [nvarchar](50) NOT NULL,
[Candidate Secondary Phone] [nvarchar](50) NULL,
[Primary Contact Method] [int] NULL,
[Enter Date] [datetime] NULL,
[Original Source] [nvarchar](100) NULL,
[Desired Career Level] [int] NULL,
[Professional Certifications] [nvarchar](200) NULL,
[Candidate's Work Authorization] [nvarchar](3) NULL,
[Collegiate Majors] [nvarchar](50) NULL,
[Current Job Type] [int] NULL,
[Date Available] [datetime] NULL,
[Degree Level] [int] NULL,
[Desired Job Type] [int] NULL,
[Candidate's Disposition] [nvarchar](100) NULL,
[Password] [nvarchar](60) NULL,
[Willing to Relocate?] [nvarchar](10) NULL,
[Relocation Preferences] [nvarchar](255) NULL,
[Resume Body] [text] NULL,
[Salary Requirement] [nvarchar](255) NULL,
[Security Clearance?] [bit] NULL,
[Skill Set] [nvarchar](100) NULL,
[Contact Notes] [nvarchar](500) NULL,
[Comment] [nvarchar](500) NULL,
[Additional Countries] [nvarchar](75) NULL,
[Years of Experience] [int] NULL,
[Veteran Status] [varchar](75) NULL,
[Ethnicity Code] [int] NULL,
[Gender] [varchar](3) NULL,
[Disabled Status] [varchar](3) NULL,
[Job ID] [int] NULL,
[Stage Seq No] [int] NULL,
[Contact Info Custom Field 1 - 10] [varchar](500) NULL,
[Resume Custom Field 1- 10] [varchar](500) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
And the xml file that they sent me is:
<xml version="1.0" xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
xmlns:rs="urn:schemas-microsoft-com:rowset"
xmlns:z="#RowsetSchema">
<s:Schema id="RowsetSchema">
<s:ElementType name="row" content="eltOnly" rs:updatable="true">
<s:AttributeType name="action" rs:number="3" rs:nullable="true" rs:writeunknown="true" rs:basecatalog="Openhire"
rs:basetable="candidates" rs:basecolumn="action">
<s:datatype dt:type="ui1" dt:maxLength="1" rs:precision="3" rs:fixedlength="true"/>
</s:AttributeType>
<s:AttributeType name="column1" rs:number="4" rs:nullable="true" rs:writeunknown="true" rs:basecatalog="Openhire"
rs:basetable="candidates" rs:basecolumn="column1">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="100"/>
</s:AttributeType>
<s:AttributeType name="column2" rs:number="5" rs:nullable="true" rs:writeunknown="true" rs:basecatalog="Openhire"
rs:basetable="candidates" rs:basecolumn="column2">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="500"/>
</s:AttributeType>
<s:AttributeType name="column3" rs:number="6" rs:nullable="true" rs:writeunknown="true" rs:basecatalog="Openhire"
rs:basetable="candidates" rs:basecolumn="column3">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="500"/>
</s:AttributeType>
<s:AttributeType name="column4" rs:number="7" rs:nullable="true" rs:writeunknown="true" rs:basecatalog="Openhire"
rs:basetable="candidates" rs:basecolumn="column4">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="500"/>
</s:AttributeType>
<s:AttributeType name="column5" rs:number="8" rs:nullable="true" rs:writeunknown="true" rs:basecatalog="Openhire"
rs:basetable="candidates" rs:basecolumn="column5">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="500"/>
</s:AttributeType>
<s:AttributeType name="column6" rs:number="9" rs:nullable="true" rs:writeunknown="true" rs:basecatalog="Openhire"
rs:basetable="candidates" rs:basecolumn="column6">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="500"/>
</s:AttributeType>
<s:AttributeType name="column7" rs:number="10" rs:nullable="true" rs:writeunknown="true" rs:basecatalog="Openhire"
rs:basetable="candidates" rs:basecolumn="column7">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="500"/>
</s:AttributeType>
<s:AttributeType name="column8" rs:number="11" rs:nullable="true" rs:writeunknown="true" rs:basecatalog="Openhire"
rs:basetable="candidates" rs:basecolumn="column8">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="500"/>
</s:AttributeType>
<s:AttributeType name="column9" rs:number="12" rs:nullable="true" rs:writeunknown="true" rs:basecatalog="Openhire"
rs:basetable="candidates" rs:basecolumn="column9">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="500"/>
</s:AttributeType>
<s:AttributeType name="column10" rs:number="13" rs:nullable="true" rs:maydefer="true" rs:writeunknown="true"
rs:basecatalog="Openhire" rs:basetable="candidates" rs:basecolumn="column10">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="2147483647" rs:long="true"/>
</s:AttributeType>
<s:AttributeType name="column11" rs:number="14" rs:nullable="true" rs:maydefer="true" rs:writeunknown="true"
rs:basecatalog="Openhire" rs:basetable="candidates" rs:basecolumn="column11">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="2147483647" rs:long="true"/>
</s:AttributeType>
<s:AttributeType name="column12" rs:number="15" rs:nullable="true" rs:maydefer="true" rs:writeunknown="true"
rs:basecatalog="Openhire" rs:basetable="candidates" rs:basecolumn="column12">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="2147483647" rs:long="true"/>
</s:AttributeType>
<s:AttributeType name="column13" rs:number="16" rs:nullable="true" rs:maydefer="true" rs:writeunknown="true"
rs:basecatalog="Openhire" rs:basetable="candidates" rs:basecolumn="column13">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="2147483647" rs:long="true"/>
</s:AttributeType>
<s:AttributeType name="column14" rs:number="17" rs:nullable="true" rs:maydefer="true" rs:writeunknown="true"
rs:basecatalog="Openhire" rs:basetable="candidates" rs:basecolumn="column14">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="2147483647" rs:long="true"/>
</s:AttributeType>
<s:AttributeType name="column15" rs:number="18" rs:nullable="true" rs:maydefer="true" rs:writeunknown="true"
rs:basecatalog="Openhire" rs:basetable="candidates" rs:basecolumn="column15">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="2147483647" rs:long="true"/>
</s:AttributeType>
</s:ElementType>
</s:Schema>
<rs:data>
<z:row action="1" column1="Bill|S|Smith|Mr|II" column2="bill.smith@example.com|1 main street||" column3="Smithville|NJ|07748|US." column4="555-555-5555|732-555-5555|1" column6="|||" column7="|||" column8="|||" column10="||||||" column11="||||" column12="||||" column13="||||" column14="||||" column15="This is my Resume Body"/>
</rs:data>
</xml>
November 7, 2012 at 1:24 pm
Thanks for the ddl. Can you post at least a couple of rows of sample data, it does not need to be real data assuming it might be sensitive. Just a couple rows of reasonable content would be great.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
November 7, 2012 at 2:10 pm
Here is some data - modified to protect the innocent.
INSERT [dbo].[MyTable] ([Candidate First Name], [Candidate Middle Name], [Candidate Last Name], [Candidate Name Prefix],
[Candidate Name Suffix], [Candidate Email], [Candidate Address Line 1], [Candidate Address Line 2],
[Candidate City], [Candidate State/Province/Region], [Candidate Postal Code], [Candidate Country],
[Candidate Primary Phone], [Candidate Secondary Phone], [Primary Contact Method], [Enter Date], [Original Source],
[Desired Career Level], [Professional Certifications], [Candidate's Work Authorization], [Collegiate Majors],
[Current Job Type], [Date Available], [Degree Level], [Desired Job Type], [Candidate's Disposition], [Password],
[Willing to Relocate?], [Relocation Preferences], [Resume Body], [Salary Requirement], [Security Clearance?], [Skill Set],
[Contact Notes], [Comment], [Additional Countries], [Years of Experience], [Veteran Status], [Ethnicity Code],
[Gender], [Disabled Status], [Job ID], [Stage Seq No], [Contact Info Custom Field 1 - 10], [Resume Custom Field 1- 10])
VALUES(N'William', NULL, N'Johnson', NULL, NULL, N'', N'125 Lamplight Lane', NULL,
N'MyTown', N'NY', N'12121', N'USA', N'', NULL, NULL, CAST(0x00009F8100000000 AS DateTime),
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[MyTable] ([Candidate First Name], [Candidate Middle Name], [Candidate Last Name], [Candidate Name Prefix],
[Candidate Name Suffix], [Candidate Email], [Candidate Address Line 1], [Candidate Address Line 2],
[Candidate City], [Candidate State/Province/Region], [Candidate Postal Code], [Candidate Country],
[Candidate Primary Phone], [Candidate Secondary Phone], [Primary Contact Method], [Enter Date], [Original Source],
[Desired Career Level], [Professional Certifications], [Candidate's Work Authorization], [Collegiate Majors],
[Current Job Type], [Date Available], [Degree Level], [Desired Job Type], [Candidate's Disposition], [Password],
[Willing to Relocate?], [Relocation Preferences], [Resume Body], [Salary Requirement], [Security Clearance?], [Skill Set],
[Contact Notes], [Comment], [Additional Countries], [Years of Experience], [Veteran Status], [Ethnicity Code],
[Gender], [Disabled Status], [Job ID], [Stage Seq No], [Contact Info Custom Field 1 - 10], [Resume Custom Field 1- 10])
VALUES(N'John', NULL, N'Johnson', NULL, NULL, N'', N'2125 Flat Turnpike', NULL,
N'MyTown', N'NY', N'12121', N'USA', N'', NULL, NULL, CAST(0x00009F8100000000 AS DateTime),
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[MyTable] ([Candidate First Name], [Candidate Middle Name], [Candidate Last Name], [Candidate Name Prefix],
[Candidate Name Suffix], [Candidate Email], [Candidate Address Line 1], [Candidate Address Line 2],
[Candidate City], [Candidate State/Province/Region], [Candidate Postal Code], [Candidate Country],
[Candidate Primary Phone], [Candidate Secondary Phone], [Primary Contact Method], [Enter Date], [Original Source],
[Desired Career Level], [Professional Certifications], [Candidate's Work Authorization], [Collegiate Majors],
[Current Job Type], [Date Available], [Degree Level], [Desired Job Type], [Candidate's Disposition], [Password],
[Willing to Relocate?], [Relocation Preferences], [Resume Body], [Salary Requirement], [Security Clearance?], [Skill Set],
[Contact Notes], [Comment], [Additional Countries], [Years of Experience], [Veteran Status], [Ethnicity Code],
[Gender], [Disabled Status], [Job ID], [Stage Seq No], [Contact Info Custom Field 1 - 10], [Resume Custom Field 1- 10])
VALUES(N'Raymond', NULL, N'Fox', NULL, NULL, N'', N'111 Wall Street', NULL,
N'MyTown', N'NY', N'12121', N'USA', N'', NULL, NULL, CAST(0x00009F8100000000 AS DateTime),
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[MyTable] ([Candidate First Name], [Candidate Middle Name], [Candidate Last Name], [Candidate Name Prefix],
[Candidate Name Suffix], [Candidate Email], [Candidate Address Line 1], [Candidate Address Line 2],
[Candidate City], [Candidate State/Province/Region], [Candidate Postal Code], [Candidate Country],
[Candidate Primary Phone], [Candidate Secondary Phone], [Primary Contact Method], [Enter Date], [Original Source],
[Desired Career Level], [Professional Certifications], [Candidate's Work Authorization], [Collegiate Majors],
[Current Job Type], [Date Available], [Degree Level], [Desired Job Type], [Candidate's Disposition], [Password],
[Willing to Relocate?], [Relocation Preferences], [Resume Body], [Salary Requirement], [Security Clearance?], [Skill Set],
[Contact Notes], [Comment], [Additional Countries], [Years of Experience], [Veteran Status], [Ethnicity Code],
[Gender], [Disabled Status], [Job ID], [Stage Seq No], [Contact Info Custom Field 1 - 10], [Resume Custom Field 1- 10])
VALUES(N'Matthew', NULL, N'Foley', NULL, NULL, N'', N'884 First Ave', NULL,
N'MyTown', N'NY', N'12121', N'USA', N'', NULL, NULL, CAST(0x00009F8100000000 AS DateTime),
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[MyTable] ([Candidate First Name], [Candidate Middle Name], [Candidate Last Name], [Candidate Name Prefix],
[Candidate Name Suffix], [Candidate Email], [Candidate Address Line 1], [Candidate Address Line 2],
[Candidate City], [Candidate State/Province/Region], [Candidate Postal Code], [Candidate Country],
[Candidate Primary Phone], [Candidate Secondary Phone], [Primary Contact Method], [Enter Date], [Original Source],
[Desired Career Level], [Professional Certifications], [Candidate's Work Authorization], [Collegiate Majors],
[Current Job Type], [Date Available], [Degree Level], [Desired Job Type], [Candidate's Disposition], [Password],
[Willing to Relocate?], [Relocation Preferences], [Resume Body], [Salary Requirement], [Security Clearance?], [Skill Set],
[Contact Notes], [Comment], [Additional Countries], [Years of Experience], [Veteran Status], [Ethnicity Code],
[Gender], [Disabled Status], [Job ID], [Stage Seq No], [Contact Info Custom Field 1 - 10], [Resume Custom Field 1- 10])
VALUES(N'Robert', NULL, N'Jackson', NULL, NULL, N'', N'123 Main St', NULL,
N'MyTown', N'NY', N'12121', N'USA', N'', NULL, NULL, CAST(0x00009F8100000000 AS DateTime),
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[MyTable] ([Candidate First Name], [Candidate Middle Name], [Candidate Last Name], [Candidate Name Prefix],
[Candidate Name Suffix], [Candidate Email], [Candidate Address Line 1], [Candidate Address Line 2],
[Candidate City], [Candidate State/Province/Region], [Candidate Postal Code], [Candidate Country],
[Candidate Primary Phone], [Candidate Secondary Phone], [Primary Contact Method], [Enter Date], [Original Source],
[Desired Career Level], [Professional Certifications], [Candidate's Work Authorization], [Collegiate Majors],
[Current Job Type], [Date Available], [Degree Level], [Desired Job Type], [Candidate's Disposition], [Password],
[Willing to Relocate?], [Relocation Preferences], [Resume Body], [Salary Requirement], [Security Clearance?], [Skill Set],
[Contact Notes], [Comment], [Additional Countries], [Years of Experience], [Veteran Status], [Ethnicity Code],
[Gender], [Disabled Status], [Job ID], [Stage Seq No], [Contact Info Custom Field 1 - 10], [Resume Custom Field 1- 10])
VALUES(N'Thomas', NULL, N'Cody', NULL, NULL, N'', N'38 Glenn Aveue', NULL,
N'MyTown', N'NY', N'12121', N'USA', N'', NULL, NULL, CAST(0x00009F8100000000 AS DateTime),
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[MyTable] ([Candidate First Name], [Candidate Middle Name], [Candidate Last Name], [Candidate Name Prefix],
[Candidate Name Suffix], [Candidate Email], [Candidate Address Line 1], [Candidate Address Line 2],
[Candidate City], [Candidate State/Province/Region], [Candidate Postal Code], [Candidate Country],
[Candidate Primary Phone], [Candidate Secondary Phone], [Primary Contact Method], [Enter Date], [Original Source],
[Desired Career Level], [Professional Certifications], [Candidate's Work Authorization], [Collegiate Majors],
[Current Job Type], [Date Available], [Degree Level], [Desired Job Type], [Candidate's Disposition], [Password],
[Willing to Relocate?], [Relocation Preferences], [Resume Body], [Salary Requirement], [Security Clearance?], [Skill Set],
[Contact Notes], [Comment], [Additional Countries], [Years of Experience], [Veteran Status], [Ethnicity Code],
[Gender], [Disabled Status], [Job ID], [Stage Seq No], [Contact Info Custom Field 1 - 10], [Resume Custom Field 1- 10])
VALUES(N'David', NULL, N'Bell', NULL, NULL, N'', N'57 Long Rd. Apt. 2', NULL,
N'MyTown', N'NY', N'12121', N'USA', N'', NULL, NULL, CAST(0x00009F8100000000 AS DateTime),
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply