Extracting name value pairs from an XML string

Extracting name value pairs from an XML string

Post by Dave » Sat, 23 Aug 2003 01:34:05



I am having a difficult time createing a stored procedure that extracts name
value pairs from an XML string.

I need to extract both element and attribute values.  Here is an example of
the XML that is passed to the stored proc:

EXEC spCLASS_SaveHPAssets '<homepage realtorid="14042222">
 <homepagetypeid>12</homepagetypeid>
 <homepagetabs>
  <homepagetab menutabid="1">Home</homepagetab>
  <homepagetab menutabid="20"></homepagetab>
 </homepagetabs>
 <homepagedetails>
  <homepagedetail attributeid="3" attributename="agadd1">3522 Oak
Street</homepagedetail>
  <homepagedetail attributeid="5"
attributename="agcity">Westfield</homepagedetail>
  <homepagedetail attributeid="6"
attributename="agcountry">USA</homepagedetail>
  <homepagedetail attributeid="7"

 </homepagedetails>
</homepage>

I need to be able to grab the following values:

homepagetypeid, 12
agadd, 3522 Oak Street
agcity,Westfield
agcountry,USA

I seem to be able to get attribute values but not the element values.  For
example, the following gets all the "attributename" values but not the
associated "homepagedetail" values:


 With (




 )

Does anyone have some sample code that illustrates how I can access both
type of values?

Thanks
Dave