johngr904
asked on
How do remove or replace a TM symbol in an XML File
I have written a vba program in Excel that logs onto a website, navigates to an XML export file, and saves it to a network folder for processing by our AS/400. The problem is that occasionally a trademark symbol chr(153) is in the file and that causes the file to bomb out on the AS/400 because it does not recognize the symbol. Any ideas for a simple routine to remove the TM symbol or replace it with a space? I keep having issues with importing it into a worksheet and changing it there. It loses the XML format, mostly involving quote signs.
This should work without having to add the referenec
Dim iSource As Integer, iDest As Integer, sText As String
''Close any open text files
Close
''Get the number of the next free text file
iSource = FreeFile
''Write the entire file to sText
Open "C:\input.xml" For Input As #nSourceFile
sText = Input$(LOF(1), 1)
Close
'set and open file for output
iDest = FreeFile
Open "C:\input2.xml" For Output As iDest
'write project info and then a blank line. Note the comma is required
Print #fnum, Replace(sText, Chr(153), "TM")
Close #fnum
End Sub
ASKER
Neither Works. They both run fine, but when I look at the revised file, the ™ symbols are still there.
What are you using to open the XML files anyway? Internet Explorer?
Instead of replacing what I thought is the raw character in the XML file, you probably have to replace this &153;
Print #fnum, Replace(sText, "&153;", "TM")
If you open the source xml from notepad, it should have &153; in it
Instead of replacing what I thought is the raw character in the XML file, you probably have to replace this &153;
Print #fnum, Replace(sText, "&153;", "TM")
If you open the source xml from notepad, it should have &153; in it
ASKER
Doesn't make any difference using the &153, and when I open the XML file with notepad it shows the ™ symbol.
ASKER
It has something to do with the trademark symbol, because I can replace other text strings and it works fine, just not with the ™ symbol.
Trademark symbol can be Chr(153) or Unicode ChrW(2122).
Can you attach the original file that contains the ™ symbol?
Can you attach the original file that contains the ™ symbol?
ASKER
Sure, here is a sample record in the file that contains a ™ symbol. I also tried ChrW(2122), per your reply, but that didn't work either. I had also tried ChrW(8482).
Sample-Batch-Record.xml
Sample-Batch-Record.xml
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, that was just what I needed! Couldn't find that information anywhere!
Open in new window