Hello,
I am not able to avoid repeating xml version tag in a xml
file I generated using Cold fusion program.
The steps aare as follows:
1. I read an xml file
2. Get data from database
3. Write it into another xml file.
In the third step where I write to xml file, I have the code
within a loop,so the xml version invariably appears. I tried to
move the logic outside the loop and other permutations and
combinations. But nothing seems to work.
Can anyone help me?
Any help is appreciated.
----------------------------------------CF
code:----------------------------------------------
<cfset XMLTextForFile='<eGrades>'>
<!--- Write to xml file--->
<cfset
varFile="d:\WebSites\WebServices\Aruna\studenttest.xml">
<cffile action="write" file="#varFile#"
output="#XMLTextForFile#">
<cfxml variable="POXML">
<xs:schema id="eGrades" xmlns="" xmlns:xs="
http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="eGrades" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Course">
<xs:complexType>
<xs:sequence>
<xs:element name="TaID" type="xs:int" />
<xs:element name="StuID" type="xs:int" />
<xs:element name="SSAN" type="xs:string" />
<xs:element name="Stu_Last" type="xs:string" />
<xs:element name="Stu_First" type="xs:string" />
<xs:element name="Crs_Code" type="xs:string" />
<xs:element name="Crs_Type" type="xs:string" />
<xs:element name="Crs_End" type="xs:dateTime" />
<xs:element name="Crs_Grade" type="xs:string"
minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
</cfxml>
<cfoutput>
<!--- Append to xml file 1--->
<cfset XMLTextForFile=ToString(POXML)>
<cfset
varFile="d:\WebSites\WebServices\Aruna\studenttest.xml">
<cffile action="append" file="#varFile#"
output="#XMLTextForFile#">
<!--- Read the Data file--->
<cfset
varFile="d:\WebSites\WebServices\Aruna\egrades1.xml">
<cffile action="read" file=#varFile#
variable="getInvXml">
<cfset InvXMLDoc = XMLParse(getInvxml)>
<cfset var3 = ArrayLen(Invxmldoc.eGrades.xmlchildren)>
<cfloop index="i" from ="1" to = #var3-1#>
<cfxml variable="egradeXML">
<cfquery datasource="psrepos" name="Grades">
SELECT STUD_NO, CRSM_SECT, STRM_SEM_KEY, STRM_COMP_CODE,
STRM_COMP_DATE, STRM_GRADE, CRSE_ID
FROM DSTRM
WHERE (STUD_NO = '#InvXMLdoc.eGrades.Course
.StuID.xmltext#')
and substring(crsm_sect,5,8)
='#InvXMLdoc.eGrades.Course.Crs_Code.xmltext#'
</cfquery>
<!--- Append to xml file 2--->
<Course>
<TaID>#InvXMLdoc.eGrades.Course
.TaID.xmltext#</TaID>
<StuID>#InvXMLdoc.eGrades.Course.StuID.xmltext#</StuID>
<SSAN>#InvXMLdoc.eGrades.Course
.SSAN.xmltext#</SSAN>
<Stu_Last>Stu_Last:
#InvXMLdoc.eGrades.Course.Stu_Last.xmltext#</Stu_Last>
<Stu_First>#InvXMLdoc.eGrades.Course
.Stu_First.xmltext#</Stu_First>
<Crs_Code>#InvXMLdoc.eGrades.Course.Crs_Code.xmltext#</Crs_Code>
<Crs_Type>#Grades.STRM_GRADE#</Crs_Type>
<Crs_End>#InvXMLdoc.eGrades.Course
.Crs_End.xmltext#</Crs_End>
</Course>
</cfxml>
<cfset XMLTextForFile=ToString(egradeXML)>
<cfset
varFile="d:\WebSites\WebServices\Aruna\studenttest.xml">
<cffile action="append" file="#varFile#"
output="#XMLTextForFile#">
</cfloop>
<!--- Append to xml file 3--->
<cfset XMLTextForFile='</eGrades>'>
<cfset
varFile="d:\WebSites\WebServices\Aruna\studenttest.xml">
<cffile action="append" file="#varFile#"
output="#XMLTextForFile#">
</cfoutput>
---------------------------------------xml code ( see above
each course tag)--------------------------------------
eGrades>
<?xml version="1.0" encoding="UTF-8" ?>
- <xs:schema id="eGrades" xmlns=""
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:xs="
http://www.w3.org/2001/XMLSchema">
- <xs:element msdata:IsDataSet="true" name="eGrades">
- <xs:complexType>
- <xs:choice maxOccurs="unbounded">
- <xs:element name="Course">
- <xs:complexType>
- <xs:sequence>
<xs:element name="TaID" type="xs:int" />
<xs:element name="StuID" type="xs:int" />
<xs:element name="SSAN" type="xs:string" />
<xs:element name="Stu_Last" type="xs:string" />
<xs:element name="Stu_First" type="xs:string" />
<xs:element name="Crs_Code" type="xs:string" />
<xs:element name="Crs_Type" type="xs:string" />
<xs:element name="Crs_End" type="xs:dateTime" />
<xs:element minOccurs="0" name="Crs_Grade"
type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<?xml version="1.0" encoding="UTF-8" ?>
- <Course>
<TaID>50104</TaID>
<StuID>0360040</StuID>
<SSAN>431111111</SSAN>
<Stu_Last>Stu_Last: Matukumalli</Stu_Last>
<Stu_First>Aruna</Stu_First>
<Crs_Code>PSYC100</Crs_Code>
<Crs_Type>A</Crs_Type>
<Crs_End>2008-12-14</Crs_End>
</Course>
<?xml version="1.0" encoding="UTF-8" ?>
- <Course>
<TaID>50104</TaID>
<StuID>0000602</StuID>
<SSAN>431211111</SSAN>
<Stu_Last>Stu_Last: Becton</Stu_Last>
<Stu_First>Sheela</Stu_First>
<Crs_Code>GVPT199P</Crs_Code>
<Crs_Type>C</Crs_Type>
<Crs_End>2008-10-22T00:00:00.0000000-04:00</Crs_End>
</Course>
<?xml version="1.0" encoding="UTF-8" ?>
- <Course>
<TaID>50106</TaID>
<StuID>0360040</StuID>
<SSAN>431211111</SSAN>
<Stu_Last>Stu_Last: Matukumalli</Stu_Last>
<Stu_First>Aruna</Stu_First>
<Crs_Code>IFSM300</Crs_Code>
<Crs_Type>B</Crs_Type>
<Crs_End>2003-05-16T00:00:00.0000000-04:00</Crs_End>
</Course>
</eGrades>