Re: Create xml with VB


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Re: Create xml with VB

Hybrid View

  1. #1
    Cuong Guest

    Re: Create xml with VB



    "Rohit Wason" <rohitw@futuresoftindia.com> wrote:
    >
    >"dumm" <pontolan@hotmail.com> wrote:
    >>
    >>Hi,
    >>Need some hints on creating xml file in VB 6.
    >>
    >>Examples? Hints?

    >XML can be created by any **** source - SQL, VB, ASP, C, C++ any thing you
    >can imagine. XML is a "general" form text written in some hierarchical manner
    >eg:
    >
    ><Persons>
    > <Person>
    > <Name>Rohit</Name>
    > <Age>23</Age>
    > </Person>
    > <Person>
    > <Name>Shubo</Name>
    > <Age>123</Age>
    > </Person>
    > <Person>
    > <Name>dumm</Name>
    > <Age>??</Age>
    > </Person>
    ></Persons>
    >
    >The data above represents a few records of persons.
    >This can be read from any source (SQL/Oracle or whatever) and written using
    >VB/VC/ASP/ or whatever.
    >
    >In VB for instance, we can write:
    >Print #1, "<Persons>" + vbCRLF & _
    >" <Person>" + vbCRLF & _
    >" <Name>Rohit</Name>" + vbCRLF & _
    >" <Age>23</Age>" + vbCRLF & _
    >" </Person>" + vbCRLF & _
    >" <Person>" + vbCRLF & _
    >" <Name>Shubo</Name>" + vbCRLF & _
    >" <Age>123</Age>" + vbCRLF & _
    >" </Person>" + vbCRLF & _
    >" <Person>" + vbCRLF & _
    >" <Name>dumm</Name>" + vbCRLF & _
    >" <Age>??</Age>" + vbCRLF & _
    >" </Person>" + vbCRLF & _
    >"</Persons>"
    >
    >Okay?

    --------------------
    I know this way man! But the problem is that your code is not general. What
    if we are taking data from a database and we don't really know the field
    names(we are using field names as elements)?

    Another thing is that your data may contain some special characters ("/",
    "<", ">", "&", etc.) and in this case your output XML may not be well-formed!!!

    I am writing VB code to export a finacial report in XML, please give me your
    advice.

    Thanks

    ~Cuong


  2. #2
    Rohit Wason Guest

    Re: Create xml with VB


    "Cuong" <cuongvan@hcm.vnn.vn> wrote:
    >
    >
    >"Rohit Wason" <rohitw@futuresoftindia.com> wrote:
    >>
    >>"dumm" <pontolan@hotmail.com> wrote:
    >>>
    >>>Hi,
    >>>Need some hints on creating xml file in VB 6.
    >>>
    >>>Examples? Hints?

    >>XML can be created by any **** source - SQL, VB, ASP, C, C++ any thing

    you
    >>can imagine. XML is a "general" form text written in some hierarchical

    manner
    >>eg:
    >>
    >><Persons>
    >> <Person>
    >> <Name>Rohit</Name>
    >> <Age>23</Age>
    >> </Person>
    >> <Person>
    >> <Name>Shubo</Name>
    >> <Age>123</Age>
    >> </Person>
    >> <Person>
    >> <Name>dumm</Name>
    >> <Age>??</Age>
    >> </Person>
    >></Persons>
    >>
    >>The data above represents a few records of persons.
    >>This can be read from any source (SQL/Oracle or whatever) and written using
    >>VB/VC/ASP/ or whatever.
    >>
    >>In VB for instance, we can write:
    >>Print #1, "<Persons>" + vbCRLF & _
    >>" <Person>" + vbCRLF & _
    >>" <Name>Rohit</Name>" + vbCRLF & _
    >>" <Age>23</Age>" + vbCRLF & _
    >>" </Person>" + vbCRLF & _
    >>" <Person>" + vbCRLF & _
    >>" <Name>Shubo</Name>" + vbCRLF & _
    >>" <Age>123</Age>" + vbCRLF & _
    >>" </Person>" + vbCRLF & _
    >>" <Person>" + vbCRLF & _
    >>" <Name>dumm</Name>" + vbCRLF & _
    >>" <Age>??</Age>" + vbCRLF & _
    >>" </Person>" + vbCRLF & _
    >>"</Persons>"
    >>
    >>Okay?

    >--------------------
    >I know this way man! But the problem is that your code is not general. What
    >if we are taking data from a database and we don't really know the field
    >names(we are using field names as elements)?
    >
    >Another thing is that your data may contain some special characters ("/",
    >"<", ">", "&", etc.) and in this case your output XML may not be well-formed!!!
    >
    >I am writing VB code to export a finacial report in XML, please give me

    your
    >advice.
    >
    >Thanks
    >
    >~Cuong
    >


    Hey simple!

    One, you've asked about populating the data in XML, w/o knowing the structure
    beforehand right? This can be done using the well known Fields() collection
    in ADO Recordset. As you suggest, we can build a portion of XML only for
    the structure of the table (to make it generic).

    Two, you asked about the special characters like <,&,> etc. MSDN Jan 2000
    tells about this. I found the following mapping in the URL: mk:@MSITStore:\\fspdc\MSDN(Latest)\MSDN\inet.chm::/xml/general/what-is-xml.htm

    < &lt;
    & &amp;
    > &gt;

    " &quot;
    ' &apos;

    This can be implemented using Replace() function in VB6.0 as:
    "<Person>" & Replace(poRS.Fields("Name"),"<","&lt") & "</Person>"
    and so on...

    It might appear that this solution doesn't directly spply to your problem,
    but slight workout with it may solve it. And let me suggest you one thing
    - one can't go for 100% genericity. we have to get specific at some point.
    Your Financial Report seems an ideal example for using XML for exporting
    data, in case you still face problems you are welcome at my e-mail above.

    All the Best
    Rohit


  3. #3
    Hal Guest

    Re: Create xml with VB


    Someone may have already answered this, so I won't go over the details on
    how to do it. Here is some general advice for writing XML in VB.

    1. Plan the layout for your XML document. Figure out what is going to be
    a node element and what is going to be an attribute. Determine what the hierarchy
    is for your elements. {Experiment with the VB code until you have it figured
    out}.

    2. Use the dom object (reference msxml.dll).

    3. I would suggest making a class module to represent a record of data.
    You can pull data from the database to populate the object made from the
    class, and then you can have a method that creates XML from that data. You
    can also go the other way, and have the object be populated by XML and then
    have a method for the object to save its data to the database. That way
    you can minimize the impact to your code if the data model changes.

    Good luck.

    "Cuong" <cuongvan@hcm.vnn.vn> wrote:
    >
    >
    >"Rohit Wason" <rohitw@futuresoftindia.com> wrote:
    >>
    >>"dumm" <pontolan@hotmail.com> wrote:
    >>>
    >>>Hi,
    >>>Need some hints on creating xml file in VB 6.
    >>>
    >>>Examples? Hints?

    >>XML can be created by any **** source - SQL, VB, ASP, C, C++ any thing

    you
    >>can imagine. XML is a "general" form text written in some hierarchical

    manner
    >>eg:
    >>
    >><Persons>
    >> <Person>
    >> <Name>Rohit</Name>
    >> <Age>23</Age>
    >> </Person>
    >> <Person>
    >> <Name>Shubo</Name>
    >> <Age>123</Age>
    >> </Person>
    >> <Person>
    >> <Name>dumm</Name>
    >> <Age>??</Age>
    >> </Person>
    >></Persons>
    >>
    >>The data above represents a few records of persons.
    >>This can be read from any source (SQL/Oracle or whatever) and written using
    >>VB/VC/ASP/ or whatever.
    >>
    >>In VB for instance, we can write:
    >>Print #1, "<Persons>" + vbCRLF & _
    >>" <Person>" + vbCRLF & _
    >>" <Name>Rohit</Name>" + vbCRLF & _
    >>" <Age>23</Age>" + vbCRLF & _
    >>" </Person>" + vbCRLF & _
    >>" <Person>" + vbCRLF & _
    >>" <Name>Shubo</Name>" + vbCRLF & _
    >>" <Age>123</Age>" + vbCRLF & _
    >>" </Person>" + vbCRLF & _
    >>" <Person>" + vbCRLF & _
    >>" <Name>dumm</Name>" + vbCRLF & _
    >>" <Age>??</Age>" + vbCRLF & _
    >>" </Person>" + vbCRLF & _
    >>"</Persons>"
    >>
    >>Okay?

    >--------------------
    >I know this way man! But the problem is that your code is not general. What
    >if we are taking data from a database and we don't really know the field
    >names(we are using field names as elements)?
    >
    >Another thing is that your data may contain some special characters ("/",
    >"<", ">", "&", etc.) and in this case your output XML may not be well-formed!!!
    >
    >I am writing VB code to export a finacial report in XML, please give me

    your
    >advice.
    >
    >Thanks
    >
    >~Cuong
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center