I have the next code:
import pypyodbc as pyodbc
cnxn = pyodbc.connect(
'Trusted_Connection=yes;DRIVER={SQL Server};SERVER=localhost;DATABASE=HOLA;UID=sa;PWD=HOLAMUNDO'
)
idPerson = 2
cursor = cnxn.cursor()
cursor.execute('SELECT * FROM prueba WHERE id=?', (idPerson,))
for row in cursor.fetchall():
print(row)
This works fine, and the selected XML field have the next format:
<PERSON>
<INFO>
<NAME>Charlie</NAME>
<LASTNAME>Brown</LASTNAME>
</INFO>
</PERSON>
How can I take that field and save it in a new XML file in a directory...?
This is the script for my database:
USE [HOLA]
GO
/****** Object: Table [dbo].[prueba] Script Date: 04/03/2016 8:29:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[prueba](
[id] [int] NOT NULL,
[xml] [xml] NULL,
CONSTRAINT [PK_prueba] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
rowstring to file.