Thursday, 22 August 2013

How to Create XML File

XML file consists of the parameters and the contents we need to access in our flash program.
There can be two or more methods to create an xml file but here we are using two methods for creating an xml file.

Methods of creating XML file:
Notepad: the basic method of creating an xml file is the use of notepad, in which we write our own HTML codes. And after doing that it could be saved directly in .xml extension. Here is a sample code for creating an xml file in a note pad.
<dictionary>
<words>
<word> Abnigate </word>
<meaning> jhbjh </meaning>
<hind> khgjkhgt</hindi>
</words>
<words>
<word> Abnigate </word>
<meaning> jhbjh </meaning>
<hind> khgjkhgt</hindi>
</words>
<words>
<word> Abnigate </word>
<meaning> jhbjh </meaning>
<hind> khgjkhgt</hindi>
</words>
</dictionary>
-save the code with .xml extention

But for huge number of data we use another method, but before that we need to have a schema file which consists of parameters we need in our xml file. The schema file approaches one more step that it adds up with the EXCEL file.

For creating schema file we can write the code either in HTML or in VBA (Visual Basic), so here we generate the .xsd file with VBA by using the following code:

Sub createxsd()

   Dim StrMyXml As String, MyMap As XmlMap
   Dim StrMySchema As String
   StrMyXml = "<Dictionary>"
   StrMyXml = StrMyXml & "<Words>"
   StrMyXml = StrMyXml & "<Word>Text</Word>"
    StrMyXml = StrMyXml & "<Hindi>Text</Hindi>"
    StrMyXml = StrMyXml & "<Meaning>Text</Meaning>"
   StrMyXml = StrMyXml & "</Words>"
   StrMyXml = StrMyXml & "<Words>"
   StrMyXml = StrMyXml & "</Words>"
   StrMyXml = StrMyXml & "</Dictionary>"

   ' Turn off async loading.
   Application.DisplayAlerts = False
   ' Add the string to the XmlMaps collection.
   Set MyMap = ThisWorkbook.XmlMaps.Add(StrMyXml)
   Application.DisplayAlerts = True

   ' Create an empty file and output the schema.
   StrMySchema = ThisWorkbook.XmlMaps(1).Schemas(1).XML
   Open "destination.xsd" For Output As #1
   Print #1, StrMySchema
   Close #1
End Sub

And  in Note pad we can write the code in a simple manner
<dictionary>
<words>
<word> text </word>
<meaning> text </meaning>
<hind> text</hindi>
</words>
</dictionary>

After creating xsd file we can easily use another method for creating xml file.

EXCEL sheet: This could be a easy way for creating a large data of xml file. As we have created the xsd file above, we learn how to call it and do the processing.


- Goto Developer bar
- Click to Source option
- A a dialogue box will open-> click to XML Maps
- Search for the directory in which the xsd file have been saved






















- Now the parameters could be seen on the right box from there drag the parameters and drop to that column which is to be selected for the particular operation.
- Click to Export for generating the xml file.

No comments:

Post a Comment