EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
> I've been changing back all my special characters for two weeks now,
> and am sick of it.
You can almost always automate that task through VBA macros.
This problem troubled me also. I originally file-copied my FP site to a
different folder then opened it in EW. I executed a find and replace to
universally add a HTML 4.01 DOCTYPE statement, only to subsequently find
many pages with corrupted characters above the 256 basic ANSI range.
But when I (re-)imported the offending pages into EW overwriting the
corrupted pages, then applied the DOCTYPE, all was OK.
I cannot reliably reproduce the problem, seems to be hit or miss.
Cheers,
Charax
> I originally file-copied my FP site to a different folder then opened
> it in EW. I executed a find and replace to universally add a HTML
> 4.01 DOCTYPE statement, only to subsequently find many pages with
> corrupted characters above the 256 basic ANSI range.
A BOM is not corruption, but a Unicode standard for ten years. Besides that,
if your files have an explicit encoding declaration such as
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />,
this will not happen. If your files don't have an explicit encoding
declaration, they're already corrupted.
You misunderstood and I wasn't clear. I'm saying that when I used find &
replace to mass redesignate file-copied pages with win-1252 or iso-8859-1
pages to HTML 4.01 / utf-8, then opened in many characters above ANSI 256
range were corrupted. It doesn't seem to happen with imported pages, and can
not be duplicated consistently. Only file copied pages opened in EW after a
find & Replace of the encoding and doctype shown the problem.
Charax
> I'm saying that when I used find & replace to mass redesignate
> file-copied pages with win-1252 or iso-8859-1 pages to HTML 4.01 /
> utf-8, then opened in many characters above ANSI 256 range were
> corrupted.
I would _never_ use find & replace to change the encoding declaration. It's
not sufficient to replace the declaration, EW also needs to make sure that
the actual encoding is changed. There might be situations when this doesn't
happen. If you want to recode all files in a website, you should probably
use a VBA macro such
<http://google.com/groups?selm=ca88dq.16o.1%40news.christoph.schneegans.de>.
Note the line
pw.Document.DocumentHTML = pw.Document.DocumentHTML
which seems redundant. In fact, it is absolutely necessary. Without it, EW
would only change the encoding declaration, but not update the actual
encoding. You would end up with a declaration such as
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
while the file is still Windows-1252 encododed. The same problem might have
occured during your replace operation.
Replacing the document type declaration is safe, however.
Thanks very much. Better I find out late than never.... I still have a lot
of conversions to do.
An interesting bit of code but I can't compile, evidently missing a library
ref. I get a compile error on the dim statement for PageWindowEx. Here's
what I've got loaded:
Visual Basic for Applications
Microsoft Expression Web 12.0 Web Object Reference Library
OLE Automation
Microsoft Office 12.0 Object Library
Microsoft Expression Web 12.0 Page Object Reference Library
Encoding Converters Repository and basic converter engine wrappers
What ref am I missing?
Thanks,
Charax
>> <http://google.com/groups?selm=ca88dq.16o.1%40news.christoph.schneegans.de>.
>
> An interesting bit of code but I can't compile, evidently missing a
> library ref.
Oops, that was an macro written for FrontPage. Here's the version adapted
for EW:
Sub SetEncodingDeclaration()
Dim wf As WebFile
Dim pw As PageWindow
For Each wf In ActiveWeb.AllFiles
'Process .html and .htm files only.
If wf.Extension <> "html" And wf.Extension <> "htm" Then GoTo NextFile
Set pw = wf.Edit(PageViewNoWindow)
'Search for existing encoding declaration.
Dim meta As MetaElement
For Each meta In pw.Document.all.tags("head")(0).all.tags("meta")
If meta.httpEquiv = "Content-Type" Then
Exit For
End If
Next
'No encoding declaration found, create a new one.
If meta Is Nothing Then
pw.Document.all.tags("head")(0).insertAdjacentHTML "AfterBegin", "<meta />"
Set meta = pw.Document.all.tags("head")(0).all.tags("meta")(0)
End If
With meta
.httpEquiv = "Content-Type"
.content = "text/html"
.Charset = "utf-8"
End With
pw.Document.documentHTML = pw.Document.documentHTML
pw.Save
pw.Close
NextFile:
Next
End Sub
Be sure to backup your website before running this macro.
Many thanks, Christof. That's very helpful!
I will also recode for single page use and put a button on the toolbar. It
will be a valuable and much used utility for me as I move everything to
utf-8.
Charax