小编San*_*apu的帖子

将字符串形式的XML内容添加到XDocument

我必须制作一个这样的xml并即时发布到url

<Student>
<Name>John</Name>
<Age>17</Age>
<Marks>
    <Subject>
        <Title>Maths</Title>
        <Score>55</Score>
    </Subject>
    <Subject>
        <Title>Science</Title>
        <Score>50</Score>
    </Subject>
</Marks>
</Student>

string marksxml = "<Marks><Subject><Title>Maths</Title><Score>55</Score></Subject><Subject><Title>Science</Title><Score>50</Score></Subject></Marks>";
XDocument doc = new XDocument(new XElement("Student",
new XElement("Name", "John"),
new XElement("Age", "17")));
Run Code Online (Sandbox Code Playgroud)

将字符串marksxml嵌入到XDocument中需要做什么?

c# xml

4
推荐指数
1
解决办法
1862
查看次数

在 SQL Server 中使用 XQuery 将 XML 转换为表数据

是否可以在 SQL Server 中使用 XQuery 从输出中获得下表

编辑:我的要求发生了变化,考虑我有一个表,其中存储了以下 xml 和 UserID

DECLARE  @XML xml
set @XML = '<Security>
             <FiscalYear Name="2012">
            <Country Id="204">
              <State Id="1">
                <City Id="10"></City>
              </State>
              <State Id="2">
                <City Id="20"></City>
                <City Id="30"></City>
              </State>
              <State Id ="3"></State>
              </Country >
            </FiscalYear>
        </Security>'

CREATE TABLE #tmp_user
(UserID INT,SecurityXML XML)

INSERT INTO #tmp_user
        ( UserID, SecurityXML )
VALUES  ( 1, 
          @XML
          )
Run Code Online (Sandbox Code Playgroud)

现在我怎样才能得到 ao/p 喜欢

输出:

 UserID StateID       CityID
     1      1           10
     1      2           20
     1      2           30
     1      3            0
Run Code Online (Sandbox Code Playgroud)

有可能实现吗?

sql xquery-sql

2
推荐指数
1
解决办法
6312
查看次数

标签 统计

c# ×1

sql ×1

xml ×1

xquery-sql ×1