Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 XML query

Author  Topic 

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-15 : 11:04:33
I know how to get values from an XML content like this
DECLARE	@XML VARCHAR(8000)

SET @XML = '<InternationalAddress>
<IntAddressLine>10</IntAddressLine>
<IntAddressLine>Red Street</IntAddressLine>
<IntAddressLine>Middlesbrough</IntAddressLine>
<IntAddressLine>Cleveland</IntAddressLine>
<Test type="2">Peso</Test>
<Country>Test</Country>
<InternationalPostCode>Test</InternationalPostCode>
</InternationalAddress>'

DECLARE @docHandle INT

EXEC sp_xml_preparedocument @docHandle OUTPUT, @XML

SELECT *
FROM OPENXML(@docHandle, '/InternationalAddress', 2)
WITH (
IntAddressLine1 VARCHAR(200) 'IntAddressLine[1]',
IntAddressLine2 VARCHAR(200) 'IntAddressLine[2]',
IntAddressLine3 VARCHAR(200) 'IntAddressLine[3]',
IntAddressLine4 VARCHAR(200) 'IntAddressLine[4]'
)

EXEC sp_xml_removedocument @docHandle
But how to retreive the TYPE value for test tag?



E 12°55'05.25"
N 56°04'39.16"

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-10-15 : 11:19:16
Does this helps?

DECLARE	@XML VARCHAR(8000)

SET @XML = '<InternationalAddress>
<IntAddressLine>10</IntAddressLine>
<IntAddressLine>Red Street</IntAddressLine>
<IntAddressLine>Middlesbrough</IntAddressLine>
<IntAddressLine>Cleveland</IntAddressLine>
<Test type="2">Peso</Test>
<Country>Test</Country>
<InternationalPostCode>Test</InternationalPostCode>
</InternationalAddress>'

DECLARE @docHandle INT

EXEC sp_xml_preparedocument @docHandle OUTPUT, @XML

SELECT *
FROM OPENXML(@docHandle, '/InternationalAddress', 2)
WITH (
IntAddressLine1 VARCHAR(200) 'IntAddressLine[1]',
IntAddressLine2 VARCHAR(200) 'IntAddressLine[2]',
IntAddressLine3 VARCHAR(200) 'IntAddressLine[3]',
IntAddressLine4 VARCHAR(200) 'IntAddressLine[4]',
Type Varchar(1) 'Test/@type'
)

EXEC sp_xml_removedocument @docHandle


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-15 : 11:21:45
Yes!

Excellent. Thank you Harsh!
DECLARE	@XML VARCHAR(8000)

SET @XML = '<InternationalAddress>
<IntAddressLine>10</IntAddressLine>
<IntAddressLine>Red Street</IntAddressLine>
<IntAddressLine>Middlesbrough</IntAddressLine>
<IntAddressLine>Cleveland</IntAddressLine>
<Test type="123">Peso</Test>
<Test type="456">Peso2</Test>
<Country>Test</Country>
<InternationalPostCode>Test</InternationalPostCode>
</InternationalAddress>'

DECLARE @docHandle INT

EXEC sp_xml_preparedocument @docHandle OUTPUT, @XML

SELECT *
FROM OPENXML(@docHandle, '/InternationalAddress', 2)
WITH (
IntAddressLine1 VARCHAR(200) 'IntAddressLine[1]',
IntAddressLine2 VARCHAR(200) 'IntAddressLine[2]',
IntAddressLine3 VARCHAR(200) 'IntAddressLine[3]',
IntAddressLine4 VARCHAR(200) 'IntAddressLine[4]',
Type1 Varchar(34) 'Test[1]',
TestType1 Varchar(34) 'Test[1]/@type',
Type2 Varchar(34) 'Test[2]',
TestType2 Varchar(34) 'Test[2]/@type'
)

EXEC sp_xml_removedocument @docHandle



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -