嗨,我是 xml 新手
我有这样的查询
SELECT ProjectId,
ProjectCode,
ProjectName,
TechId,
-- LocationId,
( SELECT GeoId,PoliticalDivisionId ,GeographicLocationName,IsoCode,Longitude,Latitude,ParentLocationId,
t2.CreatedBy,t2.CreatedOn,t2.LastUpdatedBy,t2.LastUpdatedOn
FROM GeographicLocation t2
WHERE GeoId = t1.LocationId
FOR XML PATH('Location') ),
RtoId,
CreatedBy,
CreatedOn,
LastUpdatedBy,
LastUpdatedOn
FROM Project t1
where ProjectId=1
FOR XML PATH('ProjectInfo')
它将xml返回为
<ProjectInfo>
<ProjectId>1</ProjectId>
<ProjectCode>US-W1-00001</ProjectCode>
<ProjectName>Rees</ProjectName>
<TechId>1</TechId>
<Location><GeoId>235</GeoId><PoliticalDivisionId>2</PoliticalDivisionId><GeographicLocationName>UNITED STATES</GeographicLocationName><IsoCode>US</IsoCode></Location>
<RtoId>3</RtoId>
<CreatedBy>1</CreatedBy>
<CreatedOn>2013-06-30T20:55:21.587</CreatedOn>
<LastUpdatedBy>1</LastUpdatedBy>
<LastUpdatedOn>2013-06-30T20:55:21.587</LastUpdatedOn>
项目标签以 < 和 > 的形式显示。但是 Location 的内部标签显示为“<” 和“>” 如何用 < 和 > 替换它们
更新:问题中有一个小错误。内部 xml 不是用于 rtoid ,而是用于 Location
我将查询更新为
SELECT ProjectId,
ProjectCode,
ProjectName,
TechId,
-- LocationId,
replace(replace( ( SELECT GeoId,PoliticalDivisionId ,GeographicLocationName,IsoCode,Longitude,Latitude,ParentLocationId,
t2.CreatedBy,t2.CreatedOn,t2.LastUpdatedBy,t2.LastUpdatedOn
FROM GeographicLocation t2
WHERE GeoId = t1.LocationId
FOR XML PATH('Location') ), '<', '<'), '>', '>'),
RtoId,
CreatedBy,
CreatedOn,
LastUpdatedBy,
LastUpdatedOn
FROM Project t1
where ProjectId=1
FOR XML PATH('ProjectInfo')
但还是一样