Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA + XML

Status
Not open for further replies.
Jun 17, 2004
50
GB
I have written a vba routine in access that looks at a 3 of tables in an Oracle database and then puts all of that into an xml file. This works ok and the file works as I can upload it into the required website.

However the actual file itself looks pretty ugly when not viewed through something that parses it nicely (xmlnotepad). Which isn't a huge problem but it would be nice not to have everything all on 1 line!

I am using MSXML v4.0 and I was wondering if there is anything I can do to insert some formatting after each tag (whitespace?) to make it look a bit prettier? Does adding formating to these files make them even bigger than they already are?

I am a total XML novice (can you tell) so it might be that there is no need to make it look pretty in a text editor and I should stop worrying and be happy that they work!

Views and comments would be appreciated...
 
Does it look pretty in IE ?
Anyway, who cares the behind the scene ?
 
it looks ok in IE.

I have just seen another tek-tips thread


that basically sticks a textnode with a vbcrlf in after each element I add if I want it to look nice.

I am not sure if I have the energy to go through all the elements and do this. There are large amounts of data in these files anyway. Adding thousands of vbcrlf's in seems to be creating the possibility of more confusion and even bigger files....
 
There is no need to make it look pretty. XML is for reading by computers, not by humans :)

I would try to insert CRLF's after tags though (in some kind of logical fashion, while building your XML string) to make it a LITTLE easier to read if you need to identify a problem. But this depeds on one thing:

How are you getting the data into XML?

Hope this helps,

Alex

Ignorance of certain subjects is a great part of wisdom
 
hi alex,

I basically create some ADO recordsets and then loop through sticking data into appropriate tags.

This an example below of how I put stuff in;

This bit sets where I want to be (this gets very laborious when I am down to the 8th or 9th level!)...
Set objRootElem = objDom.childNodes(1).childNodes(1).childNodes(lng - 1).childNodes(NodeCounter).childNodes(0)

This a rudimentary error capturing thing...
ErrorString = "tblEMSdata - FAMILYNAME"

I check to see if there is something in the recordset field and if so create an element, append it and stick the value in
If Not (IsNull(rst.fields("FAMILYNAME").Value)) Then
Set objElement = objDom.createElement("ind:FamilyName")
objRootElem.appendChild objElement
objElement.Text = rst.fields("FAMILYNAME").Value
End If

And so on and so on through the structure. Do you think I should be trying to add a vbcrlf somewhre in the if statement?
 
All you are doing is making the file bigger. If this is a file that needs to be transferred over a network, you should be doing the opposite, i.e. take out any unnecessary characters.

Also, with the tinkering you are doing you may inadvertantly add something that makes the file invalid - why tempt fate?


 
Thanks for your comments, I think I will leave it looking like it is !!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top