Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

text/xmldecl not at the beginning of input

I am trying to insert xml file in database but i am getting this error text/xmldecl not at the beginning of input.

Here is the query:

INSERT [EMR].[tblTemplateForm]
 (FormXML)
 VALUES ( CAST('<?xml version="1.0" encoding="UTF-8"?><EMR>
  <CustomTextBox xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <Text>0.0</Text>
    <Type>TextBox</Type>
    <Width>300</Width>
    <id>txt1</id>
    <Label>POG(LMP)</Label>
    <LabelWidth>200</LabelWidth>
    <labelFontStyle>normal</labelFontStyle>
    <labelFontWeight>normal</labelFontWeight>
    <labelFontColor>Black</labelFontColor>
    <CaptionOrientation>Horizontal</CaptionOrientation>
    <NewControl>false</NewControl>
    <NumericText>0</NumericText>
    <TextMode>Singleline</TextMode>
    <rows>0</rows>
    <columns>0</columns>
  </CustomTextBox><?xml version="1.0"?>
  <CustomNumericTextBox xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <Type>NumericTxtBox</Type>
    <Width>500</Width>
    <id>numTxt1</id>
    <Label>numTxt1</Label>
    <LabelWidth>200</LabelWidth>
    <labelFontStyle>normal</labelFontStyle>
    <labelFontWeight>normal</labelFontWeight>
    <labelFontColor>Black</labelFontColor>
    <CaptionOrientation>Horizontal</CaptionOrientation>
    <NewControl>false</NewControl>
    <NumericText>3</NumericText>
  </CustomNumericTextBox><?xml version="1.0"?>
  <AllControlsCount xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <Width>0</Width>
    <id>ControlsID</id>
    <LabelWidth>0</LabelWidth>
    <NewControl>false</NewControl>
    <NumericText>0</NumericText>
    <lblCount>0</lblCount>
    <txtCount>12</txtCount>
    <numTxtCount>1</numTxtCount>
    <ddlCount>0</ddlCount>
    <rbCount>0</rbCount>
    <cbCount>0</cbCount>
  </AllControlsCount>
</EMR>' as XML))
 GO

Error message:

Msg 9438, Level 16, State 1, Line 1
XML parsing: line 19, character 24, text/xmldecl not at the beginning of input

Table structure:

TABLE [EMR].[tblTemplateForm](
    [FormID] [int] IDENTITY(1,1) NOT NULL,
    [FormName] [varchar](100) NULL,
    [FormDesc] [varchar](255) NULL,
    [FormXML] [xml] NULL,
    [Published] [bit] NULL,
    [FormType] [int] NULL,
    [CreatedID] [int] NULL,
    [CreatedDate] [datetime] NULL,
    [ModifiedID] [int] NULL,
    [ModifiedDate] [datetime] NULL,
like image 280
Sharun Avatar asked May 02 '13 07:05

Sharun


2 Answers

Repeating XML declaration

<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0"?>
<?xml version="1.0"?>

If the XML declaration is included, it must be situated at the first position of the first line in the XML document

like image 138
Aleksandr Fedorenko Avatar answered Nov 08 '22 16:11

Aleksandr Fedorenko


Why do you have extra

<?xml version="1.0"?>

in two places? Remove them and it should work fine.

Raj

like image 44
Raj Avatar answered Nov 08 '22 18:11

Raj