使用时,将xsi:type添加到元素... for xml explicit,root(' ArrayOfEventItem')

时间:2014-08-12 20:53:27

标签: sql-server xml tsql

我在SQL Server中创建了一些XML:

select 
    1 as Tag,
    NULL as Parent,    
    a.Start as [EventItem!1!StartTime!Element],
    a.[End] as [EventItem!1!EndTime!Element],
    a.ResId as [EventItem!1!ResourceId!Element],
 from
    Activity a 
 for xml explicit, root('ArrayOfEventItem')

结果是:

  <EventItem>
    <StartTime>2012-08-16T08:00:00</StartTime>
    <EndTime>2012-08-16T17:00:00</EndTime>
    <ResourceId>3</ResourceId>
  </EventItem>
  <EventItem>
    <StartTime>2013-06-06T08:00:00</StartTime>
    <EndTime>2013-06-06T17:00:00</EndTime>
    <ResourceId>4</ResourceId>
  </EventItem>

但我也需要结果中的类型信息 - 它应该是:

<EventItem>
    <StartTime xsi:type="xsd:dateTime">2012-08-16T08:00:00</StartTime>
    <EndTime xsi:type="xsd:dateTime">2012-08-16T17:00:00</EndTime>
    <ResourceId xsi:type="xsd:int">3</ResourceId>
</EventItem>
<EventItem>
    <StartTime xsi:type="xsd:dateTime">2013-06-06T08:00:00</StartTime>
    <EndTime xsi:type="xsd:dateTime">2013-06-06T17:00:00</EndTime>
    <ResourceId xsi:type="xsd:int">4</ResourceId>
</EventItem>

如何将此(xsi:type="")添加到我的select语句?

1 个答案:

答案 0 :(得分:0)

def add(x,y):
    answer = x + y
    return answer  # Please notice how i use RETURN to return a value from the function call

def subtract(x,y):
    answer = x - y
    return answer

y = int ( input("Enter First number "))
x = int ( input("Enter Second number "))

operation = input("Subtract or Add ")

result = None
if operation == "add":
    result = add(x,y)  # Please notice how I store what the function returns!
else:
    result = subtract(x,y)

if (result != None):
    print result
else:
    print "There is no result!"