-
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
-
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
< <
& &
> >
" "
' '
This can be implemented using Replace() function in VB6.0 as:
"<Person>" & Replace(poRS.Fields("Name"),"<","<") & "</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
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks