SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 retrive all attributes xml attributes
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

savibp1
Starting Member

6 Posts

Posted - 03/19/2013 :  06:44:25  Show Profile  Reply with Quote
I need a single query to retrieve all xml attributes .Pls help???

edit: moved to proper forum

bandi
Flowing Fount of Yak Knowledge

India
2168 Posts

Posted - 03/19/2013 :  07:37:57  Show Profile  Reply with Quote
post the structure of that XML variable and also expected output......


--
Chandu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 03/19/2013 :  11:46:53  Show Profile  Reply with Quote
see

http://visakhm.blogspot.in/2012/10/shred-data-as-well-as-metadata-from-xml.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

savibp1
Starting Member

6 Posts

Posted - 03/19/2013 :  11:55:19  Show Profile  Reply with Quote
quote:
Originally posted by savibp1

I need a single query to retrieve all xml attributes .Pls help???



<?xml version="1.0" ?>
- <PA_TRANSACTIONS_Test1>
<TransID>DX7430701S</TransID>
<TransEffDate>2012-11-01T20:00:00</TransEffDate>
<TransType>Submission</TransType>
<CreateDateTime>2013-03-01T07:27:19.500</CreateDateTime>
<CreateOperator>Unnati</CreateOperator>
<ObjClass>Aegis-Ins-UW-PolicyAdmin-Work-Application</ObjClass>
<UpdateDateTime>2013-03-01T07:32:20.443</UpdateDateTime>
<UpdateOperator>Unnati</UpdateOperator>
- <TransXml>
- <Submission>
<ApplicantEntryComplete>false</ApplicantEntryComplete>
<AssistantUnderwriter>davisg</AssistantUnderwriter>
<CATTIV_USD>0</CATTIV_USD>
<pyWorkIDPrefix>A-</pyWorkIDPrefix>
<pyWorkPartiesRule>Default</pyWorkPartiesRule>
- <Brokerage>
<AddressLine1 Special="Red">5605 Glenridge Dr NE</AddressLine1>
<AddressLine2>One Premier Plaza, Ste 300</AddressLine2>
<Assets>0</Assets>
<BusinessDesc>Broker/Consultant</BusinessDesc>
<StateCode>GA</StateCode>
<ZipCode>30342-1365</ZipCode>
<numberOfEmployees>0</numberOfEmployees>
- <Contact>
<AddressLine1>5605 Glenridge Dr NE</AddressLine1>
<AddressLine2>One Premier Plaza, Ste 300</AddressLine2>
<BusinessUnitId>070935</BusinessUnitId>
<ZipCode>30342-1365</ZipCode>
<pxCreateDateTime>2013-03-01T12:29:24.021Z</pxCreateDateTime>
<pxCreateOperator>VimalrajM</pxCreateOperator>
</Contact>
- <Contact>
<AddressLine1>5605 Glenridge Dr NE</AddressLine1>
<AddressLine2>One Premier Plaza, Ste 300</AddressLine2>
<BusinessUnitId>0709352</BusinessUnitId>
<ZipCode>30342-1365</ZipCode>
<pxCreateDateTime>2013-03-01T12:29:24.021Z</pxCreateDateTime>
<pxCreateOperator>SelviM</pxCreateOperator>
</Contact>
</Brokerage>
- <Policy>
<SLADate>2013-05-24</SLADate>
<SLADatePol>2013-03-06</SLADatePol>
<SLADateRen>2013-03-06</SLADateRen>
</Policy>
- <Submission>
<CompletionStatus>Complete</CompletionStatus>
<PlacementType>W</PlacementType>
<ProductClass>Excess</ProductClass>
<SubmissionID>DX7430701S</SubmissionID>
<SubmissionStatus>Converted</SubmissionStatus>
</Submission>
- <Quote>
<DSSUBNO>72999</DSSUBNO>
<SLADate>2013-03-06</SLADate>
<SLADateRen>2013-03-06</SLADateRen>
<SurplusCredit>0</SurplusCredit>
<InsuredCompany />
<Submission />
</Quote>
- <InsuredCompany>
<AddressLine1>1700 Pacific Ave</AddressLine1>
<AddressLine2>Ste 2900</AddressLine2>
<Assets>492000000</Assets>
<BusinessDesc>Gas (Local Dist/Intg Co)</BusinessDesc>
<ZipCode>75201-4666</ZipCode>
<numberOfEmployees>0</numberOfEmployees>
- <Contact>
<AddressLine1>1700 Pacific Ave</AddressLine1>
<AddressLine2>Ste 2900</AddressLine2>
<Title>Chief Accounting Officer</Title>
<ZipCode>75201-4666</ZipCode>
</Contact>
</InsuredCompany>
</Submission>
</TransXml>
</PA_TRANSACTIONS_Test1>
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 03/20/2013 :  10:07:52  Show Profile  Reply with Quote
So what should be the output?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
29908 Posts

Posted - 03/20/2013 :  15:01:56  Show Profile  Visit SwePeso's Homepage  Reply with Quote
There are no attributes in the XML above, only entities.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
29908 Posts

Posted - 03/20/2013 :  16:18:18  Show Profile  Visit SwePeso's Homepage  Reply with Quote
Try this
DECLARE	@Data XML = N'<?xml version="1.0" ?> 
 <PA_TRANSACTIONS_Test1>
 <TransID>DX7430701S</TransID> 
 <TransEffDate>2012-11-01T20:00:00</TransEffDate> 
 <TransType>Submission</TransType> 
 <CreateDateTime>2013-03-01T07:27:19.500</CreateDateTime> 
 <CreateOperator>Unnati</CreateOperator> 
 <ObjClass>Aegis-Ins-UW-PolicyAdmin-Work-Application</ObjClass> 
 <UpdateDateTime>2013-03-01T07:32:20.443</UpdateDateTime> 
 <UpdateOperator>Unnati</UpdateOperator> 
 <TransXml>
 <Submission>
 <ApplicantEntryComplete>false</ApplicantEntryComplete> 
 <AssistantUnderwriter>davisg</AssistantUnderwriter> 
 <CATTIV_USD>0</CATTIV_USD> 
 <pyWorkIDPrefix>A-</pyWorkIDPrefix> 
 <pyWorkPartiesRule>Default</pyWorkPartiesRule> 
 <Brokerage>
 <AddressLine1 Special="Red">5605 Glenridge Dr NE</AddressLine1> 
 <AddressLine2>One Premier Plaza, Ste 300</AddressLine2> 
 <Assets>0</Assets> 
 <BusinessDesc>Broker/Consultant</BusinessDesc> 
 <StateCode>GA</StateCode> 
 <ZipCode>30342-1365</ZipCode> 
 <numberOfEmployees>0</numberOfEmployees> 
 <Contact>
 <AddressLine1>5605 Glenridge Dr NE</AddressLine1> 
 <AddressLine2>One Premier Plaza, Ste 300</AddressLine2> 
 <BusinessUnitId>070935</BusinessUnitId> 
 <ZipCode>30342-1365</ZipCode> 
 <pxCreateDateTime>2013-03-01T12:29:24.021Z</pxCreateDateTime> 
 <pxCreateOperator>VimalrajM</pxCreateOperator> 
 </Contact>
 <Contact>
 <AddressLine1>5605 Glenridge Dr NE</AddressLine1> 
 <AddressLine2>One Premier Plaza, Ste 300</AddressLine2> 
 <BusinessUnitId>0709352</BusinessUnitId> 
 <ZipCode>30342-1365</ZipCode> 
 <pxCreateDateTime>2013-03-01T12:29:24.021Z</pxCreateDateTime> 
 <pxCreateOperator>SelviM</pxCreateOperator> 
 </Contact>
 </Brokerage>
 <Policy>
 <SLADate>2013-05-24</SLADate> 
 <SLADatePol>2013-03-06</SLADatePol> 
 <SLADateRen>2013-03-06</SLADateRen> 
 </Policy>
 <Submission>
 <CompletionStatus>Complete</CompletionStatus> 
 <PlacementType>W</PlacementType> 
 <ProductClass>Excess</ProductClass> 
 <SubmissionID>DX7430701S</SubmissionID> 
 <SubmissionStatus>Converted</SubmissionStatus> 
 </Submission>
 <Quote>
 <DSSUBNO>72999</DSSUBNO> 
 <SLADate>2013-03-06</SLADate> 
 <SLADateRen>2013-03-06</SLADateRen> 
 <SurplusCredit>0</SurplusCredit> 
 <InsuredCompany /> 
 <Submission /> 
 </Quote>
 <InsuredCompany>
 <AddressLine1>1700 Pacific Ave</AddressLine1> 
 <AddressLine2>Ste 2900</AddressLine2> 
 <Assets>492000000</Assets> 
 <BusinessDesc>Gas (Local Dist/Intg Co)</BusinessDesc> 
 <ZipCode>75201-4666</ZipCode> 
 <numberOfEmployees>0</numberOfEmployees> 
 <Contact>
 <AddressLine1>1700 Pacific Ave</AddressLine1> 
 <AddressLine2>Ste 2900</AddressLine2> 
 <Title>Chief Accounting Officer</Title> 
 <ZipCode>75201-4666</ZipCode> 
 </Contact>
 </InsuredCompany>
 </Submission>
 </TransXml>
 </PA_TRANSACTIONS_Test1>';

SELECT	d.n.value('(local-name(.))', 'VARCHAR(MAX)') AS Entity,
	d.n.value('(.)', 'VARCHAR(MAX)') AS Value
FROM	@Data.nodes('(//*[count(*) = 0])') AS d(n);



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

savibp1
Starting Member

6 Posts

Posted - 03/22/2013 :  01:22:34  Show Profile  Reply with Quote
quote:
Originally posted by SwePeso

Try this
DECLARE	@Data XML = N'<?xml version="1.0" ?> 
 <PA_TRANSACTIONS_Test1>
 <TransID>DX7430701S</TransID> 
 <TransEffDate>2012-11-01T20:00:00</TransEffDate> 
 <TransType>Submission</TransType> 
 <CreateDateTime>2013-03-01T07:27:19.500</CreateDateTime> 
 <CreateOperator>Unnati</CreateOperator> 
 <ObjClass>Aegis-Ins-UW-PolicyAdmin-Work-Application</ObjClass> 
 <UpdateDateTime>2013-03-01T07:32:20.443</UpdateDateTime> 
 <UpdateOperator>Unnati</UpdateOperator> 
 <TransXml>
 <Submission>
 <ApplicantEntryComplete>false</ApplicantEntryComplete> 
 <AssistantUnderwriter>davisg</AssistantUnderwriter> 
 <CATTIV_USD>0</CATTIV_USD> 
 <pyWorkIDPrefix>A-</pyWorkIDPrefix> 
 <pyWorkPartiesRule>Default</pyWorkPartiesRule> 
 <Brokerage>
 <AddressLine1 Special="Red">5605 Glenridge Dr NE</AddressLine1> 
 <AddressLine2>One Premier Plaza, Ste 300</AddressLine2> 
 <Assets>0</Assets> 
 <BusinessDesc>Broker/Consultant</BusinessDesc> 
 <StateCode>GA</StateCode> 
 <ZipCode>30342-1365</ZipCode> 
 <numberOfEmployees>0</numberOfEmployees> 
 <Contact>
 <AddressLine1>5605 Glenridge Dr NE</AddressLine1> 
 <AddressLine2>One Premier Plaza, Ste 300</AddressLine2> 
 <BusinessUnitId>070935</BusinessUnitId> 
 <ZipCode>30342-1365</ZipCode> 
 <pxCreateDateTime>2013-03-01T12:29:24.021Z</pxCreateDateTime> 
 <pxCreateOperator>VimalrajM</pxCreateOperator> 
 </Contact>
 <Contact>
 <AddressLine1>5605 Glenridge Dr NE</AddressLine1> 
 <AddressLine2>One Premier Plaza, Ste 300</AddressLine2> 
 <BusinessUnitId>0709352</BusinessUnitId> 
 <ZipCode>30342-1365</ZipCode> 
 <pxCreateDateTime>2013-03-01T12:29:24.021Z</pxCreateDateTime> 
 <pxCreateOperator>SelviM</pxCreateOperator> 
 </Contact>
 </Brokerage>
 <Policy>
 <SLADate>2013-05-24</SLADate> 
 <SLADatePol>2013-03-06</SLADatePol> 
 <SLADateRen>2013-03-06</SLADateRen> 
 </Policy>
 <Submission>
 <CompletionStatus>Complete</CompletionStatus> 
 <PlacementType>W</PlacementType> 
 <ProductClass>Excess</ProductClass> 
 <SubmissionID>DX7430701S</SubmissionID> 
 <SubmissionStatus>Converted</SubmissionStatus> 
 </Submission>
 <Quote>
 <DSSUBNO>72999</DSSUBNO> 
 <SLADate>2013-03-06</SLADate> 
 <SLADateRen>2013-03-06</SLADateRen> 
 <SurplusCredit>0</SurplusCredit> 
 <InsuredCompany /> 
 <Submission /> 
 </Quote>
 <InsuredCompany>
 <AddressLine1>1700 Pacific Ave</AddressLine1> 
 <AddressLine2>Ste 2900</AddressLine2> 
 <Assets>492000000</Assets> 
 <BusinessDesc>Gas (Local Dist/Intg Co)</BusinessDesc> 
 <ZipCode>75201-4666</ZipCode> 
 <numberOfEmployees>0</numberOfEmployees> 
 <Contact>
 <AddressLine1>1700 Pacific Ave</AddressLine1> 
 <AddressLine2>Ste 2900</AddressLine2> 
 <Title>Chief Accounting Officer</Title> 
 <ZipCode>75201-4666</ZipCode> 
 </Contact>
 </InsuredCompany>
 </Submission>
 </TransXml>
 </PA_TRANSACTIONS_Test1>';

SELECT	d.n.value('(local-name(.))', 'VARCHAR(MAX)') AS Entity,
	d.n.value('(.)', 'VARCHAR(MAX)') AS Value
FROM	@Data.nodes('(//*[count(*) = 0])') AS d(n);



N 56°04'39.26"
E 12°55'05.63"


Go to Top of Page

savibp1
Starting Member

6 Posts

Posted - 03/22/2013 :  01:23:50  Show Profile  Reply with Quote
Thanks for your solution.this is very useful for me.

[


quote]Originally posted by SwePeso

Try this
DECLARE	@Data XML = N'<?xml version="1.0" ?> 
 <PA_TRANSACTIONS_Test1>
 <TransID>DX7430701S</TransID> 
 <TransEffDate>2012-11-01T20:00:00</TransEffDate> 
 <TransType>Submission</TransType> 
 <CreateDateTime>2013-03-01T07:27:19.500</CreateDateTime> 
 <CreateOperator>Unnati</CreateOperator> 
 <ObjClass>Aegis-Ins-UW-PolicyAdmin-Work-Application</ObjClass> 
 <UpdateDateTime>2013-03-01T07:32:20.443</UpdateDateTime> 
 <UpdateOperator>Unnati</UpdateOperator> 
 <TransXml>
 <Submission>
 <ApplicantEntryComplete>false</ApplicantEntryComplete> 
 <AssistantUnderwriter>davisg</AssistantUnderwriter> 
 <CATTIV_USD>0</CATTIV_USD> 
 <pyWorkIDPrefix>A-</pyWorkIDPrefix> 
 <pyWorkPartiesRule>Default</pyWorkPartiesRule> 
 <Brokerage>
 <AddressLine1 Special="Red">5605 Glenridge Dr NE</AddressLine1> 
 <AddressLine2>One Premier Plaza, Ste 300</AddressLine2> 
 <Assets>0</Assets> 
 <BusinessDesc>Broker/Consultant</BusinessDesc> 
 <StateCode>GA</StateCode> 
 <ZipCode>30342-1365</ZipCode> 
 <numberOfEmployees>0</numberOfEmployees> 
 <Contact>
 <AddressLine1>5605 Glenridge Dr NE</AddressLine1> 
 <AddressLine2>One Premier Plaza, Ste 300</AddressLine2> 
 <BusinessUnitId>070935</BusinessUnitId> 
 <ZipCode>30342-1365</ZipCode> 
 <pxCreateDateTime>2013-03-01T12:29:24.021Z</pxCreateDateTime> 
 <pxCreateOperator>VimalrajM</pxCreateOperator> 
 </Contact>
 <Contact>
 <AddressLine1>5605 Glenridge Dr NE</AddressLine1> 
 <AddressLine2>One Premier Plaza, Ste 300</AddressLine2> 
 <BusinessUnitId>0709352</BusinessUnitId> 
 <ZipCode>30342-1365</ZipCode> 
 <pxCreateDateTime>2013-03-01T12:29:24.021Z</pxCreateDateTime> 
 <pxCreateOperator>SelviM</pxCreateOperator> 
 </Contact>
 </Brokerage>
 <Policy>
 <SLADate>2013-05-24</SLADate> 
 <SLADatePol>2013-03-06</SLADatePol> 
 <SLADateRen>2013-03-06</SLADateRen> 
 </Policy>
 <Submission>
 <CompletionStatus>Complete</CompletionStatus> 
 <PlacementType>W</PlacementType> 
 <ProductClass>Excess</ProductClass> 
 <SubmissionID>DX7430701S</SubmissionID> 
 <SubmissionStatus>Converted</SubmissionStatus> 
 </Submission>
 <Quote>
 <DSSUBNO>72999</DSSUBNO> 
 <SLADate>2013-03-06</SLADate> 
 <SLADateRen>2013-03-06</SLADateRen> 
 <SurplusCredit>0</SurplusCredit> 
 <InsuredCompany /> 
 <Submission /> 
 </Quote>
 <InsuredCompany>
 <AddressLine1>1700 Pacific Ave</AddressLine1> 
 <AddressLine2>Ste 2900</AddressLine2> 
 <Assets>492000000</Assets> 
 <BusinessDesc>Gas (Local Dist/Intg Co)</BusinessDesc> 
 <ZipCode>75201-4666</ZipCode> 
 <numberOfEmployees>0</numberOfEmployees> 
 <Contact>
 <AddressLine1>1700 Pacific Ave</AddressLine1> 
 <AddressLine2>Ste 2900</AddressLine2> 
 <Title>Chief Accounting Officer</Title> 
 <ZipCode>75201-4666</ZipCode> 
 </Contact>
 </InsuredCompany>
 </Submission>
 </TransXml>
 </PA_TRANSACTIONS_Test1>';

SELECT	d.n.value('(local-name(.))', 'VARCHAR(MAX)') AS Entity,
	d.n.value('(.)', 'VARCHAR(MAX)') AS Value
FROM	@Data.nodes('(//*[count(*) = 0])') AS d(n);



N 56°04'39.26"
E 12°55'05.63"

[/quote]
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.11 seconds. Powered By: Snitz Forums 2000