我有以下查询:
SELECT QuestionID_PK ,
QuestionTitle ,
( SELECT dbo.Tags.TagID_PK ,
dbo.Tags.TagTitle ,
dbo.Tags.TagTitle_EN
FROM dbo.Question_Tag_Rel
INNER JOIN dbo.Questions
ON dbo.Question_Tag_Rel.QuestionID_FK = dbo.Questions.QuestionID_PK
INNER JOIN dbo.Tags
ON dbo.Question_Tag_Rel.TagID_FK = dbo.Tags.TagID_PK
AND dbo.Questions.QuestionID_PK = '2116'
FOR
XML PATH('') ,
TYPE ,
ELEMENTS
) AS Tags
FROM Questions
WHERE QuestionID_PK = '2116'
FOR XML AUTO ,
ELEMENTS;
产生这个xml的:
<Questions>
<QuestionID_PK>2116</QuestionID_PK>
<QuestionTitle>Trying to find the execution time of my code using this</QuestionTitle>
<Tags>
<TagID_PK>3</TagID_PK>
<TagTitle>جافا</TagTitle>
<TagTitle_EN>Java</TagTitle_EN>
<TagID_PK>8</TagID_PK>
<TagTitle>بايثون</TagTitle>
<TagTitle_EN>Python</TagTitle_EN>
<TagID_PK>9</TagID_PK>
<TagTitle>أندرويد</TagTitle>
<TagTitle_EN>Android</TagTitle_EN>
</Tags>
</Questions>
如您所见,我希望(TagID_PK,TagTitle,TagTitle_EN)标记位于父XML标记内,以下是查询应输出的示例:
<Questions>
<QuestionID_PK>2116</QuestionID_PK>
<QuestionTitle>Trying to find the execution time of my code using this</QuestionTitle>
<Tags>
<tag>
<TagID_PK>3</TagID_PK>
<TagTitle>جافا</TagTitle>
<TagTitle_EN>Java</TagTitle_EN>
</tag>
<tag>
<TagID_PK>8</TagID_PK>
<TagTitle>بايثون</TagTitle>
<TagTitle_EN>Python</TagTitle_EN>
</tag>
<tag>
<TagID_PK>9</TagID_PK>
<TagTitle>أندرويد</TagTitle>
<TagTitle_EN>Android</TagTitle_EN>
</tag>
</Tags>
</Questions>
为了将它绑定到我的ASP.NET应用程序中的Repeater,
你能帮我解决这个问题吗?
答案 0 :(得分:1)
将XML PATH('')
更改为XML PATH('tag')