Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

How to display a portion of XML text with tags and without tag ?

Total Hit ( 2949)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
DECLARE @h int
EXEC sp_xml_preparedocument @h OUTPUT,N'
<?xml version="1.0" ?>
<Orders>
   <Item>
       <CID>1</CID>
       <ModelNumber>HO1255</ModelNumber>
       <Features>
           <AutoStart>Yes</AutoStart>
           <AutoGear>No</AutoGear>
           <PowerWindow>Yes</PowerWindow>
       </Features>
       <Description/>
       <Make>Honda Accord LX</Make>
       <ModelYear>2001</ModelYear>
   </Item>
   <Item>
       <CID>2</CID>
       <ModelNumber>FO7855</ModelNumber>
       <Features>
           <AutoStart>No</AutoStart>
           <AutoGear>No</AutoGear>
           <PowerWindow>No</PowerWindow>
       </Features>
       <Make>Ford Winstar</Make>
       <ModelYear>1998</ModelYear>
   </Item>
   <Item>
       <CID>3</CID>
       <ModelNumber>TO8989</ModelNumber>
       <Make>Toyota Camry</Make>
       <ModelYear>1990</ModelYear>
   </Item>
</Orders>'


/*Try the following part which will return row text for <features> tag*/

-- SELECT CID,ModelNumber,Make,ModelYear, Features
-- FROM OpenXML(@h,'/Orders/Item/Features', 2)
-- WITH
--  (CID INT '../CID',
--    ModelNumber varchar(100) '../ModelNumber',
--    Make varchar(100) '../Make',
--    ModelYear varchar(100) '../ModelYear',
--   Features ntext '@mp:xmltext')
-- WHERE Features IS NOT NULL

/*Try the following part which will return row text and tag both for <features> tag*/

SELECT CID,ModelNumber,Make,ModelYear, Features
FROM OpenXML(@h,'/Orders/Item/Features', 2)
WITH
  (CID INT '../CID',
   ModelNumber varchar(100) '../ModelNumber',
   Make varchar(100) '../Make',
   ModelYear varchar(100) '../ModelYear',
  Features ntext '@mp:xmltext')
WHERE Features IS NOT NULL

/* >>> Output <<<

CID     ModelNumber    Make                    ModelYear    Features
-----------------------------------------------------------------------------------------
1        HO1255            Honda Accord LX        2001        <Features>
                                                           <AutoStart>Yes</AutoStart>
                                                           <AutoGear>No</AutoGear>
                                                           <PowerWindow>Yes</PowerWindow>
                                                       </Features>

2        FO7855            Ford Winstar        1998        <Features>
                                                           <AutoStart>No</AutoStart>
                                                           <AutoGear>No</AutoGear>
                                                           <PowerWindow>No</PowerWindow>
                                                       </Features>

*/


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.