943,923 Members | Top Members by Rank

Ad:
Sep 20th, 2007
0

Helzz help me on Query For XML

Expand Post »
I've following database structure (just junk values)

XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1.  
  2. [ChannelID] [ChannelName] [ChannelCatID] [RSSFeedURL]
  3. 1 YouTube 1 ret
  4. 2 GoogleVideo 1 ert
  5. 3 MSNVideo 1 rtertert
  6. 4 ABC 2 retert
  7. 5 YahooVideo 1 erter
  8. 6 CBS 2 rtr
  9. 7 NBC 2 trtrt
  10. 8 ESPN 2 rt
  11. 9 FOX 2 rtrtttr
  12. 10 AOL 1 rt

I wanna generate following XML structure out of it

XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. - <DOC>
  2. - <Item Type="xyz">
  3. - <Channel id="a">
  4. <Name>aaaaa<Name/>
  5. <URL>aaaaa<URL/>
  6. </Channel>
  7.  
  8. - <Channel id="b">
  9. <Name>bbbb<Name/>
  10. <URL>bbbb<URL/>
  11. </Channel>
  12. ---
  13. ---
  14. </Item>
  15.  
  16. - <Item Type="lmn">
  17. - <Channel id="x">
  18. <Name>xxxx<Name/>
  19. <URL>xxxx<URL/>
  20. </Channel>
  21.  
  22. - <Channel id="y">
  23. <Name>yyyy<Name/>
  24. <URL>yyyy<URL/>
  25. </Channel>
  26. ---
  27. ---
  28. </Item>
  29. ------
  30. ------
  31. ------
  32. </DOC>


I 've written this Select For XML query

XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. SELECT ChannelCatID as '@type',
  2. ChannelID as 'Channel/@id',
  3. ChannelName as 'Channel/Name',
  4. RSSFeedURL as 'Channel/URL'
  5. FROM ChannelMaster
  6. FOR XML PATH('Item'), ROOT('DOC')

It gives me this result

XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. - <DOC>
  2. - <Item Type="xyz">
  3. - <Channel id="a">
  4. <Name>aaaaa<Name/>
  5. <URL>aaaaa<URL/>
  6. </Channel>
  7. </Item>
  8. - <Item Type="xyz">
  9. - <Channel id="b">
  10. <Name>bbbb<Name/>
  11. <URL>bbbb<URL/>
  12. </Channel>
  13. </Item>
  14. - <Item Type="xyz">
  15. ---
  16. </Item>
  17. - <Item Type="xyz">
  18. ---
  19. </Item>
  20. ------
  21. ------
  22. ------
  23. </DOC>



I want it this way:
all channels of Type xyz should come under singe <Item Type="xyz"> tag
instead of seperate tags
what changes should i make ??
Last edited by Ninad; Sep 20th, 2007 at 3:28 am.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Ninad is offline Offline
7 posts
since Sep 2007
Sep 20th, 2007
0

Re: Helzz help me on Query For XML

Hi,
Try adding this to the end of the query:
"group By Item Type"
Reputation Points: 13
Solved Threads: 29
Junior Poster
kb.net is offline Offline
169 posts
since Aug 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in XML, XSLT and XPATH Forum Timeline: Is this valid?
Next Thread in XML, XSLT and XPATH Forum Timeline: Looking for ExamXML features in a free application.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC