简体   繁体   中英

May I only parse one node in xml at one time in sql server?

If I have following xml:

<Main>
  <Group>
    <Insert />
  </Group>

  <Group>
    <Insert />
  </Group>

  ...
</Main>

I know that if I use openxml(@xml, 'Main/Group/Insert',1) , I will parse all <Insert> .

Is there a way I can read only one group node, parse its Insert node and then read the next group node and parse its Insert node?

The OpenXML or newer XML datatype and XPath treat the XML as a table, extracting and treating the results as multiple rows in one go.

What you are asking is equivalent to, for a normal SQL Server table, can you select one record, then read the next record? Of course - such as using cursors or WHILE loop - , but why?

Consider what you want to do with it, and you will soon come around to treating it properly as a dataset and getting the parsed results as records, and applying SET logic to the values you retrieve from it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM