<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: How to write OPENXML query with USING FILE in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/how-to-write-openxml-query-with-using-file/qaa-p/13837931#M4868774</link>
    <description>&lt;P&gt;Here's an untested WAG...&lt;/P&gt;
&lt;PRE&gt;SELECT * 
FROM openxml( USING FILE 'H:\\Zeichnung.xml', '/Zeichnung' )
WITH ( CustNo CHAR(30) 'Kunde',
       ArtID   INTEGER  'Artikelnummer',
       PFilepath VARCHAR(254) 'Datei')
AS correlation-name;
&lt;/PRE&gt;

&lt;P&gt;I'm guessing it's a special syntax for using in big FROM clauses, with files or columns providing the xml.&lt;/P&gt;
&lt;P&gt;"Having invented another wonderful feature, the SQL Anywhere engineer moves on, never to touch the Help topic again" &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 21 Apr 2017 07:56:54 GMT</pubDate>
    <dc:creator>Breck_Carter</dc:creator>
    <dc:date>2017-04-21T07:56:54Z</dc:date>
    <item>
      <title>How to write OPENXML query with USING FILE</title>
      <link>https://community.sap.com/t5/technology-q-a/how-to-write-openxml-query-with-using-file/qaq-p/13837929</link>
      <description>&lt;P&gt;During my first steps using OPENXML I've tried to figure out, how this version of the syntax (&lt;A href="http://dcx.sap.com/index.html#sa160/en/dbreference/openxml-system-procedure.html" target="_blank"&gt;Syntax 2&lt;/A&gt;) could be used. &lt;BR /&gt;
&lt;/P&gt;&lt;PRE&gt;OPENXML( { USING FILE | USING VALUE }
xml-data
, xpath
[, flags
[, namespaces ] ]
)
WITH ( column-name column-type
[ xpath ] [ , ... ]
) 
[ OPTION ( scan-option ) ]
[ AS ] correlation-name
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;I've got this working example, where the file is read via xp_read_file:
&lt;/P&gt;&lt;PRE&gt;SELECT * 
FROM openxml( xp_read_file( 'H:\\Zeichnung.xml' ), '/Zeichnung' )
WITH ( CustNo CHAR(30) 'Kunde',
       ArtID   INTEGER  'Artikelnummer',
       PFilepath VARCHAR(254) 'Datei');
&lt;/PRE&gt;
I'd like to modify the query to the above syntax, but haven't got a clue how to write it. Browsing for any examples using this syntax didn't give useful hints. &lt;BR /&gt;
Does anyone know how to rewrite the query accordingly?&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2017 07:29:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-to-write-openxml-query-with-using-file/qaq-p/13837929</guid>
      <dc:creator>reimer_pods</dc:creator>
      <dc:date>2017-04-21T07:29:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to write OPENXML query with USING FILE</title>
      <link>https://community.sap.com/t5/technology-q-a/how-to-write-openxml-query-with-using-file/qaa-p/13837931#M4868774</link>
      <description>&lt;P&gt;Here's an untested WAG...&lt;/P&gt;
&lt;PRE&gt;SELECT * 
FROM openxml( USING FILE 'H:\\Zeichnung.xml', '/Zeichnung' )
WITH ( CustNo CHAR(30) 'Kunde',
       ArtID   INTEGER  'Artikelnummer',
       PFilepath VARCHAR(254) 'Datei')
AS correlation-name;
&lt;/PRE&gt;

&lt;P&gt;I'm guessing it's a special syntax for using in big FROM clauses, with files or columns providing the xml.&lt;/P&gt;
&lt;P&gt;"Having invented another wonderful feature, the SQL Anywhere engineer moves on, never to touch the Help topic again" &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2017 07:56:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-to-write-openxml-query-with-using-file/qaa-p/13837931#M4868774</guid>
      <dc:creator>Breck_Carter</dc:creator>
      <dc:date>2017-04-21T07:56:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to write OPENXML query with USING FILE</title>
      <link>https://community.sap.com/t5/technology-q-a/how-to-write-openxml-query-with-using-file/qaa-p/13837930#M4868773</link>
      <description>&lt;P&gt;Syntax 2 requires a correlation name whereas syntax 1 does not, so the following should do:&lt;/P&gt;
&lt;PRE&gt;SELECT * 
FROM openxml( using file 'H:\\Zeichnung.xml', '/Zeichnung' )
WITH ( CustNo CHAR(30) 'Kunde',
       ArtID   INTEGER  'Artikelnummer',
       PFilepath VARCHAR(254) 'Datei') DT;
&lt;/PRE&gt;

&lt;P&gt;FWIW, some tests with a built-in XML file from the v16 MobiLink/Setup/Dnet subdirectory:&lt;/P&gt;
&lt;PRE&gt;-- 2 variables to store file path resp. XML data
create or replace variable xmlPath varchar(255);
create or replace variable xmlValue xml;

set xmlPath =
  cast(xp_getenv('SQLANY16') as varchar(255)) || '\\\\MobiLink\\\\Setup\\\\Dnet\\\\mlDomConfig.xml';
set xmlValue = xp_read_file(xmlPath);
select xmlPath, xmlValue;

-- Syntax 1:
select *
from
   openxml(xp_read_file(xmlPath), '//*:name')
   with (element varchar(255) '&lt;A href="http://sqlanywhere-forum.sap.com/users/1344/mpaparelli"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/1344/mpaparelli"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/1344/mpaparelli"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/1344/mpaparelli"&gt;@mp&lt;/A&gt;:localname');

select *
from
   openxml(xmlValue, '//*:name')
   with (element varchar(255) '&lt;A href="http://sqlanywhere-forum.sap.com/users/1344/mpaparelli"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/1344/mpaparelli"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/1344/mpaparelli"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/1344/mpaparelli"&gt;@mp&lt;/A&gt;:localname');

-- Syntax 2 - note the "DT" correlation name:
select *
from
   openxml(using value xmlValue, '//*:name')
   with (element varchar(255) '&lt;A href="http://sqlanywhere-forum.sap.com/users/1344/mpaparelli"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/1344/mpaparelli"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/1344/mpaparelli"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/1344/mpaparelli"&gt;@mp&lt;/A&gt;:localname') DT;

select *
from
   openxml(using file xmlPath, '//*:name')
   with (element varchar(255) '&lt;A href="http://sqlanywhere-forum.sap.com/users/1344/mpaparelli"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/1344/mpaparelli"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/1344/mpaparelli"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/1344/mpaparelli"&gt;@mp&lt;/A&gt;:localname') dt;
&lt;/PRE&gt;

&lt;P&gt;Each query should return a result set with one colum "element" and two rows "name".&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2017 07:57:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-to-write-openxml-query-with-using-file/qaa-p/13837930#M4868773</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2017-04-21T07:57:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to write OPENXML query with USING FILE</title>
      <link>https://community.sap.com/t5/technology-q-a/how-to-write-openxml-query-with-using-file/qaa-p/13837932#M4868775</link>
      <description>&lt;P&gt;FWIW, Jack has added according samples to the &lt;A href="http://dcx.sap.com/index.html#sqla170/en/html/817205cf6ce21014a949c790fd6b0608.html"&gt;v17 DCX page&lt;/A&gt;, see the comments section:)&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2017 03:17:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-to-write-openxml-query-with-using-file/qaa-p/13837932#M4868775</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2017-04-25T03:17:35Z</dc:date>
    </item>
  </channel>
</rss>

