|
-
Nov 18th, 2011, 04:59 PM
#1
Thread Starter
Addicted Member
XML reformatting on load
I'm fairly new to developing XML (I know enough to be dangerous) and I am having a problem (in VBA) when I load an XML document, it seems to reformat my XML (and incorrectly at that). I don't want the XML formatted. How do I keep it from reformatting?
Here are is some of the code I am using:
Code:
Dim xmlDoc As MSXML2.DOMDocument60 'early bind
...
Set xmlDoc = New MSXML2.DOMDocument60 'early bind
...
xmlDoc.async = False
xmlDoc.validateOnParse = False 'put this attempting to stop formatting
xmlDoc.resolveExternals = False 'put this attempting to stop formatting
'open the XML file
If xmlDoc.Load(fso.BuildPath(xmlDocPath, UIN & ".xml")) Then
Debug.Print xmlDoc.XML
...
Else
...
End If
Here is the XML before load:
Code:
<?xml version="1.0" encoding="UTF-8"?><assessmentItem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" keyType="SingleResponse" schema="our XML schema" schemaVersion="1.0" guid="4EE3791C-BB87-4577-BAE3-973A4C8E2FAB" uin="123456"><itemBody><stemArea id="stem1"><text id="text1">some text here<i> </i>text<i> </i>more text here</text></stemArea</itemBody></assessmentItem>
Here is the XML generated immediately after load (debug.print xmlDoc.XML):
Code:
<?xml version="1.0"?>
<assessmentItem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" keyType="SingleResponse" schema="our XML schema" schemaVersion="1.0" guid="4EE3791C-BB87-4577-BAE3-973A4C8E2FAB" uin="123456"><itemBody><stemArea id="stem1"><text id="text1">some text here<i>
</i>text<i>
</i>more text here</text></stemArea></itemBody></assessmentItem>
Again, how can I stop it from reformatting the XML? I need it to be unformatted.
-
Nov 18th, 2011, 07:17 PM
#2
Hyperactive Member
Re: XML reformatting on load
It's probably because you are using the Microsoft XML Libary, it is probably automatically determining the line formatting.
If you don't want it split up then just use a regular text reader...
Last edited by nO_OnE; Nov 18th, 2011 at 07:32 PM.
-
Nov 18th, 2011, 11:10 PM
#3
Re: XML reformatting on load
don't confuse the data with the display output... as long as the object is being loaded with the data correctly, does it really matter what the output format looks like?
Besides, I happened to notice that there is a space or something at the same points where your printed xml breaks and indents... which makes me wonder if your xml really is the way you think it is...
-tg
-
Nov 21st, 2011, 09:55 AM
#4
Thread Starter
Addicted Member
Re: XML reformatting on load
Actually, the XML ouput does matter since I will be updating and saving the XML back to the original XML file I am reading it from. The samples of XML I provided were both from the Immediate window in the VBE as a result of a Debug.Print.
I have been given XML files that I need to update and then send back to the person that sent them to me. I'm under strict instructions that I am to update one tag and nothing else. When I sent these back to the client, they caused issues because of the change in formatting.
Besides, I happened to notice that there is a space or something at the same points where your printed xml breaks and indents... which makes me wonder if your xml really is the way you think it is...
That is what I am having the biggest problem with, techgnome. Some of these XML files I receive were created from an old in-house XML generator and some seem to somehow have these empty tags in them (<i> </i>, etc). Unfortunately, I am not allowed to remove them.
So my question still stands: How do I keep DOMDocument60's Load event from reformatting my XML?
-
Nov 21st, 2011, 01:10 PM
#5
Thread Starter
Addicted Member
Re: XML reformatting on load
I got around my problem by using FileSystemObject and string functions to update the data I needed to update (I didnt really like doing this, but I had to do what I had to do). It is odd that the DOMDocument's Load created the hard line breaks where it did. I am still not sure why it happened and what I needed to do to stop it from happening. My problem is resolved, but I am going to leave this open for about a week to see if anyone may have ideas of what may have been causing this to happen and/or suggestions of how to stop it from happening in the future.
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
|
Click Here to Expand Forum to Full Width
|