|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Today @ 12:54 AM
Points: 42,
Visits: 148
|
|
Hi,
I Successfully Imported the Following XML File ... Again I Want to Export (Generate) the Same XML File Format... Using The Output Data (Table Value ).... How To Generate XML File... pls Any one Help me....
-------------------------------------------------------------------------------------
DECLARE @idoc int DECLARE @doc xml DECLARE @xmldata Table (FirstName varchar(110), LastName varchar(210), Email varchar(110), Phone varchar(110), Position varchar(110), Branch varchar(110), Address varchar(110)) SET @doc ='<Root> <Node FirstName="Andrew" LastName="Fuller" Email="afuller@contoso.com" Phone="(205) 555 - 9898" Position="CEO" Branch="TopManagement" Address="London, 120 Hanover Sq."> <Node FirstName="Jeremy" LastName="Boather" Email="jboather@contoso.com" Phone="(205) 555 - 9888" Position="President QA" Branch="QA" Address="London, 120 Hanover Sq."> <Node FirstName="Anne" LastName="Dodsworth" Email="adodsworth@contoso.com" Phone="(205) 555 - 9887" Position="VP QA" Branch="QA" Address="London, 120 Hanover Sq."> <Node FirstName="Alexander" LastName="Tuckings" Email="atuckings@contoso.com" Phone="(205) 555 - 9886" Position="Team Lead Team1" Branch="QA" Address="London, 120 Hanover Sq."> <Node FirstName="Brenda" LastName="Smith" Email="bsmith@contoso.com" Phone="(205) 555 - 9885" Position="Senior QA" Branch="QA" Address="London, 120 Hanover Sq."/> </Node> <Node FirstName="Mary" LastName="Bird" Email="mbird@contoso.com" Phone="(205) 555 - 9885" Position="Team Lead Team2" Branch="QA" Address="London, 120 Hanover Sq."/> </Node> </Node> <Node FirstName="Steven" LastName="Buchanan" Email="sbuchanan@contoso.com" Phone="(205) 555 - 9897" Position="President Dev Dept." Branch="Development" Address="London, 120 Hanover Sq."> <Node FirstName="Robert" LastName="King" Email="rking@contoso.com" Phone="(205) 555 - 9896" Position="VP Dev Dept." Branch="Development" Address="London, 120 Hanover Sq."> <Node FirstName="Laura" LastName="Callahan" Email="lcallahan@contoso.com" Phone="(205) 555 - 9892" Position="Team Lead Team1" Branch="Development" Address="London, 120 Hanover Sq."> <Node FirstName="Jason" LastName="Roland" Email="jroland@contoso.com" Phone="(205) 555 - 9872" Position="Senior Dev" Branch="Development" Address="London, 120 Hanover Sq."> </Node> </Node> <Node FirstName="Eric" LastName="Danstin" Email="edanstin@contoso.com" Phone="(205) 555 - 9882" Position="Team Lead Team2" Branch="Development" Address="London, 120 Hanover Sq."> <Node FirstName="Elizabeth" LastName="Lincoln" Email="elincoln@contoso.com" Phone="(205) 555 - 9862" Position="Senior Dev" Branch="Development" Address="London, 120 Hanover Sq."> </Node> <Node FirstName="Margaret" LastName="Peacock" Email="mpeacock@contoso.com" Phone="(205) 555 - 9852" Position="Senior Dev" Branch="Development" Address="London, 120 Hanover Sq."> </Node> </Node> </Node> </Node> </Node> </Root>' EXEC sp_xml_preparedocument @idoc OUTPUT, @doc
Insert @xmldata SELECT * FROM OPENXML (@idoc,'//Node',1) WITH (FirstName varchar(110), LastName varchar(210), Email varchar(110), Phone varchar(110), Position varchar(110), Branch varchar(110), Address varchar(110)) select * from @xmldata
Regards, Saravanan.K.D
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Yesterday @ 6:41 PM
Points: 11,648,
Visits: 27,760
|
|
great job providing sample data!
edit because another post by a different user posted the Identical xml, I've removed my post because it looks like homework http://www.sqlservercentral.com/Forums/Topic1394445-392-1.aspx
And Another Edit: oops ok since it was actually the same user, but he changed his login between the accidental post and this one, I assumed two different users.,
I guess that's ok, so *poof* here is is back again:
i played with this, and it looks like this gets you what you are after, but it's missing the <Root> tag...not sure how to get that yet, but will pot it if I get it to work: select * from @xmldata FOR XML RAW('Node')
the complete test set i was playing with...very helpful to look at some of the other formats to familiarize yourself: DECLARE @idoc int DECLARE @doc xml DECLARE @xmldata Table (FirstName varchar(110), LastName varchar(210), Email varchar(110), Phone varchar(110), Position varchar(110), Branch varchar(110), Address varchar(110)) SET @doc ='<Root> <Node FirstName="Andrew" LastName="Fuller" Email="afuller@contoso.com" Phone="(205) 555 - 9898" Position="CEO" Branch="TopManagement" Address="London, 120 Hanover Sq."> <Node FirstName="Jeremy" LastName="Boather" Email="jboather@contoso.com" Phone="(205) 555 - 9888" Position="President QA" Branch="QA" Address="London, 120 Hanover Sq."> <Node FirstName="Anne" LastName="Dodsworth" Email="adodsworth@contoso.com" Phone="(205) 555 - 9887" Position="VP QA" Branch="QA" Address="London, 120 Hanover Sq."> <Node FirstName="Alexander" LastName="Tuckings" Email="atuckings@contoso.com" Phone="(205) 555 - 9886" Position="Team Lead Team1" Branch="QA" Address="London, 120 Hanover Sq."> <Node FirstName="Brenda" LastName="Smith" Email="bsmith@contoso.com" Phone="(205) 555 - 9885" Position="Senior QA" Branch="QA" Address="London, 120 Hanover Sq."/> </Node> <Node FirstName="Mary" LastName="Bird" Email="mbird@contoso.com" Phone="(205) 555 - 9885" Position="Team Lead Team2" Branch="QA" Address="London, 120 Hanover Sq."/> </Node> </Node> <Node FirstName="Steven" LastName="Buchanan" Email="sbuchanan@contoso.com" Phone="(205) 555 - 9897" Position="President Dev Dept." Branch="Development" Address="London, 120 Hanover Sq."> <Node FirstName="Robert" LastName="King" Email="rking@contoso.com" Phone="(205) 555 - 9896" Position="VP Dev Dept." Branch="Development" Address="London, 120 Hanover Sq."> <Node FirstName="Laura" LastName="Callahan" Email="lcallahan@contoso.com" Phone="(205) 555 - 9892" Position="Team Lead Team1" Branch="Development" Address="London, 120 Hanover Sq."> <Node FirstName="Jason" LastName="Roland" Email="jroland@contoso.com" Phone="(205) 555 - 9872" Position="Senior Dev" Branch="Development" Address="London, 120 Hanover Sq."> </Node> </Node> <Node FirstName="Eric" LastName="Danstin" Email="edanstin@contoso.com" Phone="(205) 555 - 9882" Position="Team Lead Team2" Branch="Development" Address="London, 120 Hanover Sq."> <Node FirstName="Elizabeth" LastName="Lincoln" Email="elincoln@contoso.com" Phone="(205) 555 - 9862" Position="Senior Dev" Branch="Development" Address="London, 120 Hanover Sq."> </Node> <Node FirstName="Margaret" LastName="Peacock" Email="mpeacock@contoso.com" Phone="(205) 555 - 9852" Position="Senior Dev" Branch="Development" Address="London, 120 Hanover Sq."> </Node> </Node> </Node> </Node> </Node> </Root>' EXEC sp_xml_preparedocument @idoc OUTPUT, @doc
Insert @xmldata SELECT * FROM OPENXML (@idoc,'//Node',1) WITH (FirstName varchar(110), LastName varchar(210), Email varchar(110), Phone varchar(110), Position varchar(110), Branch varchar(110), Address varchar(110)) select * from @xmldata
select * from @xmldata FOR XML RAW('Node') --('Root') --RAW,AUTO,EXPLICIT,PATH select * from @xmldata FOR XML AUTO --select * from @xmldata FOR XML EXPLICIT select * from @xmldata FOR XML PATH('Root')
select * from @xmldata FOR XML RAW('Root') ,ELEMENTS --('Root') --RAW,AUTO,EXPLICIT,PATH select * from @xmldata FOR XML AUTO ,ELEMENTS --select * from @xmldata FOR XML EXPLICIT select * from @xmldata FOR XML PATH('Root') ,ELEMENTS
Lowell
--There is no spoon, and there's no default ORDER BY in sql server either. Actually, Common Sense is so rare, it should be considered a Superpower. --my son
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 9:16 AM
Points: 2,236,
Visits: 6,486
|
|
Your first post about this Your second post about this Your third post about this Your fourth post about this
So this one makes five posts. . . Can I offer a suggestion? One post is all that is required, if you post in multiple places like you have this time, you'll fragment any posts that are attempting to answer you.
Not a DBA, just trying to learn
For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/ For better, quicker answers on SQL Server performance related questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
If you litter your database queries with nolock query hints, are you aware of the side effects? Try reading a few of these links... (*) Missing rows with nolock (*) Allocation order scans with nolock (*) Consistency issues with nolock (*) Transient Corruption Errors in SQL Server error log caused by nolock (*) Dirty reads, read errors, reading rows twice and missing rows with nolock
LinkedIn | Blog coming soon (for sufficiently large values of "soon" )!
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Today @ 12:54 AM
Points: 42,
Visits: 148
|
|
hi Lowell,
thanks 4 ur work... but i need the same xml file Generation.... Here i have Mentioned Required File Structure....
<Root> <Node FirstName="Andrew" LastName="Fuller" Email="afuller@contoso.com" Phone="(205) 555 - 9898" Position="CEO" Branch="TopManagement" Address="London, 120 Hanover Sq."> <Node FirstName="Jeremy" LastName="Boather" Email="jboather@contoso.com" Phone="(205) 555 - 9888" Position="President QA" Branch="QA" Address="London, 120 Hanover Sq."> <Node FirstName="Anne" LastName="Dodsworth" Email="adodsworth@contoso.com" Phone="(205) 555 - 9887" Position="VP QA" Branch="QA" Address="London, 120 Hanover Sq."> <Node FirstName="Alexander" LastName="Tuckings" Email="atuckings@contoso.com" Phone="(205) 555 - 9886" Position="Team Lead Team1" Branch="QA" Address="London, 120 Hanover Sq."> <Node FirstName="Brenda" LastName="Smith" Email="bsmith@contoso.com" Phone="(205) 555 - 9885" Position="Senior QA" Branch="QA" Address="London, 120 Hanover Sq."/> </Node> <Node FirstName="Mary" LastName="Bird" Email="mbird@contoso.com" Phone="(205) 555 - 9885" Position="Team Lead Team2" Branch="QA" Address="London, 120 Hanover Sq."/> </Node> </Node> <Node FirstName="Steven" LastName="Buchanan" Email="sbuchanan@contoso.com" Phone="(205) 555 - 9897" Position="President Dev Dept." Branch="Development" Address="London, 120 Hanover Sq."> <Node FirstName="Robert" LastName="King" Email="rking@contoso.com" Phone="(205) 555 - 9896" Position="VP Dev Dept." Branch="Development" Address="London, 120 Hanover Sq."> <Node FirstName="Laura" LastName="Callahan" Email="lcallahan@contoso.com" Phone="(205) 555 - 9892" Position="Team Lead Team1" Branch="Development" Address="London, 120 Hanover Sq."> <Node FirstName="Jason" LastName="Roland" Email="jroland@contoso.com" Phone="(205) 555 - 9872" Position="Senior Dev" Branch="Development" Address="London, 120 Hanover Sq."> </Node> </Node> <Node FirstName="Eric" LastName="Danstin" Email="edanstin@contoso.com" Phone="(205) 555 - 9882" Position="Team Lead Team2" Branch="Development" Address="London, 120 Hanover Sq."> <Node FirstName="Elizabeth" LastName="Lincoln" Email="elincoln@contoso.com" Phone="(205) 555 - 9862" Position="Senior Dev" Branch="Development" Address="London, 120 Hanover Sq."> </Node> <Node FirstName="Margaret" LastName="Peacock" Email="mpeacock@contoso.com" Phone="(205) 555 - 9852" Position="Senior Dev" Branch="Development" Address="London, 120 Hanover Sq."> </Node> </Node> </Node> </Node> </Node> </Root>
Regards, Saravanan.D
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Today @ 12:54 AM
Points: 42,
Visits: 148
|
|
Any One Please Help me... please take it as Challenges...
Regards, Saravanan.D
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Today @ 12:54 AM
Points: 42,
Visits: 148
|
|
Any One Please Help me... please take it as Challenges...
Regards, Saravanan.D
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Today @ 12:54 AM
Points: 42,
Visits: 148
|
|
Any One Please Help me... please take it as Challenges...
Regards, Saravanan.D
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Yesterday @ 1:17 PM
Points: 8,641,
Visits: 8,273
|
|
sarwaanmca (12/28/2012) Any One Please Help me... please take it as Challenges...
Regards, Saravanan.D
Please stop. You have been told repeatedly to not post so many threads and just continuing to beg for help is not going to work very well.
It seems that you need some help. You have generated a number of threads on this topic and have received help in almost all of them. Your answer is now spread all over the posts you have created. The biggest issue I have seen is that you keep asking for help but don't provide much in the way of details. We also haven't seen that you have even tried to figure it out on your own. The people who post here are volunteers, that means we don't get paid to solve your issues. We do it because we enjoy the challenge and teaching others.
Maybe if you take the time to be more clear in your requirements you might find somebody willing to take the time to help you.
_______________________________________________________________
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 Moden's splitter.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Yesterday @ 4:51 PM
Points: 32,923,
Visits: 26,811
|
|
thanks 4 ur work... but i need the same xml file Generation....
To be honest, this makes no sense. Why would you import and shred the XML data and then turn around and rebuild the XML? Just use the original XML data.
--Jeff Moden "RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".
First step towards the paradigm shift of writing Set Based code: Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Thursday, May 02, 2013 3:05 PM
Points: 39,
Visits: 87
|
|
sarwaanmca (12/10/2012)
Hi, I Successfully Imported the Following XML File ... Again I Want to Export (Generate) the Same XML File Format... Using The Output Data (Table Value ).... How To Generate XML File... pls Any one Help me.... ------------------------------------------------------------------------------------- DECLARE @idoc int DECLARE @doc xml DECLARE @xmldata Table (FirstName varchar(110), LastName varchar(210), Email varchar(110), Phone varchar(110), Position varchar(110), Branch varchar(110), Address varchar(110)) SET @doc ='<Root> <Node FirstName="Andrew" LastName="Fuller" Email="afuller@contoso.com" Phone="(205) 555 - 9898" Position="CEO" Branch="TopManagement" Address="London, 120 Hanover Sq."> <Node FirstName="Jeremy" LastName="Boather" Email="jboather@contoso.com" Phone="(205) 555 - 9888" Position="President QA" Branch="QA" Address="London, 120 Hanover Sq."> <Node FirstName="Anne" LastName="Dodsworth" Email="adodsworth@contoso.com" Phone="(205) 555 - 9887" Position="VP QA" Branch="QA" Address="London, 120 Hanover Sq."> <Node FirstName="Alexander" LastName="Tuckings" Email="atuckings@contoso.com" Phone="(205) 555 - 9886" Position="Team Lead Team1" Branch="QA" Address="London, 120 Hanover Sq."> <Node FirstName="Brenda" LastName="Smith" Email="bsmith@contoso.com" Phone="(205) 555 - 9885" Position="Senior QA" Branch="QA" Address="London, 120 Hanover Sq."/> </Node> <Node FirstName="Mary" LastName="Bird" Email="mbird@contoso.com" Phone="(205) 555 - 9885" Position="Team Lead Team2" Branch="QA" Address="London, 120 Hanover Sq."/> </Node> </Node> <Node FirstName="Steven" LastName="Buchanan" Email="sbuchanan@contoso.com" Phone="(205) 555 - 9897" Position="President Dev Dept." Branch="Development" Address="London, 120 Hanover Sq."> <Node FirstName="Robert" LastName="King" Email="rking@contoso.com" Phone="(205) 555 - 9896" Position="VP Dev Dept." Branch="Development" Address="London, 120 Hanover Sq."> <Node FirstName="Laura" LastName="Callahan" Email="lcallahan@contoso.com" Phone="(205) 555 - 9892" Position="Team Lead Team1" Branch="Development" Address="London, 120 Hanover Sq."> <Node FirstName="Jason" LastName="Roland" Email="jroland@contoso.com" Phone="(205) 555 - 9872" Position="Senior Dev" Branch="Development" Address="London, 120 Hanover Sq."> </Node> </Node> <Node FirstName="Eric" LastName="Danstin" Email="edanstin@contoso.com" Phone="(205) 555 - 9882" Position="Team Lead Team2" Branch="Development" Address="London, 120 Hanover Sq."> <Node FirstName="Elizabeth" LastName="Lincoln" Email="elincoln@contoso.com" Phone="(205) 555 - 9862" Position="Senior Dev" Branch="Development" Address="London, 120 Hanover Sq."> </Node> <Node FirstName="Margaret" LastName="Peacock" Email="mpeacock@contoso.com" Phone="(205) 555 - 9852" Position="Senior Dev" Branch="Development" Address="London, 120 Hanover Sq."> </Node> </Node> </Node> </Node> </Node> </Root>' EXEC sp_xml_preparedocument @idoc OUTPUT, @doc
Insert @xmldata SELECT * FROM OPENXML (@idoc,'//Node',1) WITH (FirstName varchar(110), LastName varchar(210), Email varchar(110), Phone varchar(110), Position varchar(110), Branch varchar(110), Address varchar(110)) select * from @xmldata
Regards, Saravanan.K.D
Does this all data come from an actual database object. If yes, please post that DDL and some sample data here. I had experience working with XML data. I am asking about the object because, it looks like the order / hierarchy of the employees is stored in a table.
for ex: CEO as top level, President QA as next level and so on.. I hope you got my point.
Thanks
|
|
|
|