Making kmz file

253 views
Skip to first unread message

eily

unread,
Apr 10, 2008, 11:37:54 AM4/10/08
to KML Developer Support - Getting Started with KML
I make a .kml file with coding in vb.net and zip it to make .kmz file
by using SharpZipLib.It makes the kmz file but google earth send error
while trying to open it:"Open the file "...." failed:Parse error at
line 1 , column 2:not well-formed(invalid token)", but if I rename
the .kmz file ti .zip it workes fine.
my coding is:

Response.Clear()
Response.AppendHeader("Content-Disposition", "attachment;
filename=doc.kmz")
Response.ContentType = "application/vnd.google-earth.kmz"

Dim bytes() As Byte
Dim str As String
Dim memStream As IO.MemoryStream = New IO.MemoryStream()
Dim myXmlSetting As New XmlWriterSettings
myXmlSetting.Indent = True
myXmlSetting.NewLineOnAttributes = True
Dim xmlTW As XmlWriter = XmlWriter.Create(memStream, myXmlSetting)
.
. ' xml writing
.
bytes = memStream.ToArray()
Dim memStream2 As IO.MemoryStream = New IO.MemoryStream()
Dim gzOs As ZipOutputStream = New ZipOutputStream(memStream2)

Using (gzOs)
Dim entry As ZipEntry = New ZipEntry("doc.kml")
gzOs.SetLevel(9)
gzOs.PutNextEntry(entry)
gzOs.Write(bytes, 0, bytes.Length)
gzOs.CloseEntry()
gzOs.Close()
End Using

Response.Clear()
Response.BinaryWrite(memStream2.ToArray())
Response.End()

ManoM

unread,
Apr 11, 2008, 8:30:20 AM4/11/08
to KML Developer Support - Getting Started with KML
Hi eily,

Disclaimer: I don't know VB.Net, so I'm not sure how ZipOutputStream
works.
What I do know is that KMZ files require the plainest version of the
zip format, no options set at all.

Mano

eily

unread,
Apr 11, 2008, 3:29:15 PM4/11/08
to KML Developer Support - Getting Started with KML
Hi Mano,

I made it work by adding the size before writing it, and it works.
but now I have another problem: I changed my program in tha way to
write the kml file in a doc1 in a function(this function returns doc1
as an object), when I want to zip it, the kmz file is different from
what I had with the privius metod(for some placemarks I don't have the
CDATA part.
I 'll be glad if someone can help me , I'm getting so confused.

the function is in my .aspx.vb file


Public Function GetKmlFile() As Object
Dim cnn As New
SqlConnection(ConfigurationManager.ConnectionStrings("....").ToString)
Dim cmm As New SqlCommand

cnn.Open()
cmm.CommandType = CommandType.StoredProcedure
cmm.CommandText = "......"
cmm.Connection = cnn
Dim parUtility As New SqlParameter("......", "......")
cmm.Parameters.Add(parUtility)
Dim sPath As String =
Request.Url.AbsoluteUri.Replace(Request.Url.AbsolutePath, "") +
Request.ApplicationPath & "......aspx"
Dim parUrl As New SqlParameter("@Url", sPath)
cmm.Parameters.Add(parUrl)
Dim result As XmlReader = cmm.ExecuteXmlReader()
result.Read()

Dim doc1 As MSXML2.DOMDocument30
Dim doc2 As MSXML2.DOMDocument30
Dim doc2Node As MSXML2.IXMLDOMNode

doc1 = New MSXML2.DOMDocument30
doc2 = New MSXML2.DOMDocument30


doc1.loadXML(result.ReadOuterXml())
doc2.load(Server.MapPath("KMLStylesDoc.XML"))
'Server.MapPath("KMLStylesDoc.XML")

If Not doc1.documentElement Is Nothing Then

For Each doc2Node In doc2.documentElement.childNodes
doc1.documentElement.insertBefore(doc2Node,
doc1.documentElement.firstChild)
'doc1.documentElement.appendChild(doc2Node)
Next

End If

Return doc1.xml.ToString

End Function

and in .aspx file I have:


Response.ContentType = "application/vnd.google-earth.kmz"
Response.AddHeader("Content-Disposition", "attachment;
filename=MeterData.kmz")

<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
<name>......</name>
<description>......</description>
.
.
.
</Document>
</kml>
<%
Dim bytes As Byte()
Dim enc As New UTF8Encoding
bytes = enc.GetBytes(GetKmlFile())
Dim memStream2 As IO.MemoryStream = New IO.MemoryStream()
Dim Zos As ZipOutputStream = New ZipOutputStream(memStream2)

Using (Zos)
Dim entry As ZipEntry
entry = New ZipEntry("MeterDetails.kml")
entry.Size = bytes.Length
Zos.SetLevel(9)
Zos.PutNextEntry(entry)
Zos.Write(bytes, 0, bytes.Length)
Zos.CloseEntry()
Zos.Close()
End Using

Response.Clear()
Response.BinaryWrite(memStream2.ToArray())
Response.End()
%>


it seams that GetKmlFile()return something different, if I cut the
html part after</kml> it just works fine(I can have the kml that I
want)!!??
> >     Response.End()- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages