Discussion:
DOMDocument Load failure with <?xml version="1.0" encoding="UTF-8" ?>
(too old to reply)
Helene Day
2003-09-18 15:00:54 UTC
Permalink
Hi everyone,



I am using MS XML version 3.0 from VB 6.0 (SP5).



I use MSXML2.DOMDocument to load an XML string, and the Load method returns
false when the XML string contains the following:

<?xml version="1.0" encoding="UTF-8" ?>



I am surprise since my browser can display the xml string.



Is this a setting with the DOMDocument?



When I remove that one line, the load method is successful. But I don't want
to touch the string, I would like to be able to load it without problem.



Any clue?



Helene



- <string xmlns="http://tempuri.org/">

<?xml version="1.0" encoding="UTF-8" ?>

- <ParentTag>

<ChildTag>TRUE</ChildTag>

</ParentTag>

</string>
Oleg Tkachenko
2003-09-18 16:11:05 UTC
Permalink
Post by Helene Day
I use MSXML2.DOMDocument to load an XML string, and the Load method returns
Check parseError property to find out what exactly the problem is:

Dim xmlDoc As New Msxml2.DOMDocument40
Dim myErr As IXMLDOMParseError
xmlDoc.async = False
xmlDoc.Load ("books.xml")
Set myErr = xmlDoc.parseError
If (myErr.errorCode <> 0) Then
MsgBox ("You have error " & myErr.reason)
End If
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel
Helene Day
2003-09-18 18:13:14 UTC
Permalink
I get "Invalid xml declaration."

Helene
Post by Oleg Tkachenko
Post by Helene Day
I use MSXML2.DOMDocument to load an XML string, and the Load method returns
Dim xmlDoc As New Msxml2.DOMDocument40
Dim myErr As IXMLDOMParseError
xmlDoc.async = False
xmlDoc.Load ("books.xml")
Set myErr = xmlDoc.parseError
If (myErr.errorCode <> 0) Then
MsgBox ("You have error " & myErr.reason)
End If
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel
Oleg Tkachenko
2003-09-18 19:34:57 UTC
Permalink
Post by Helene Day
I get "Invalid xml declaration."
Hmmmm, show us your code then and small sample of XML you are parsing.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel
SQL Server Development Team [MSFT]
2003-09-18 18:37:49 UTC
Permalink
VB string is a BSTR which is UTF-16 encodied stream. If you put <?xml
version="1.0" encoding="UTF-8" ?>
in the Xml file, you tell the parsing to use UTF-8 encoding format to parse
UTF-16 encodied stream.

There are two ways to make the XmlDecl and Xml content consistant:
1). Change the Xml decl to <?xml version="1.0" encoding="UTF-16" ?>. It
means the orginal source for generating the document need to generate the
correct XmlDecl.
2). Using the stream as Xml file storage. It means use the stream object
instead of string.

Howard Hao
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/copyright.htm.
Post by Helene Day
Hi everyone,
I am using MS XML version 3.0 from VB 6.0 (SP5).
I use MSXML2.DOMDocument to load an XML string, and the Load method returns
<?xml version="1.0" encoding="UTF-8" ?>
I am surprise since my browser can display the xml string.
Is this a setting with the DOMDocument?
When I remove that one line, the load method is successful. But I don't want
to touch the string, I would like to be able to load it without problem.
Any clue?
Helene
- <string xmlns="http://tempuri.org/">
<?xml version="1.0" encoding="UTF-8" ?>
- <ParentTag>
<ChildTag>TRUE</ChildTag>
</ParentTag>
</string>
Franck Guillaud
2003-09-19 06:38:23 UTC
Permalink
Post by Helene Day
Hi everyone,
I am using MS XML version 3.0 from VB 6.0 (SP5).
I use MSXML2.DOMDocument to load an XML string, and the Load method
<?xml version="1.0" encoding="UTF-8" ?>
This line should only be on the very first line of your file.

Franck.
Helene Day
2003-09-19 16:44:49 UTC
Permalink
I cannot touch the xml string since this is coming from a third party
company.

So, I am not using the parser anymore. I am doing string manipulation.



Here is the function I wrote to extract the element value.

Thanks for everyone reply.



Helene



Private Function GetElementValue(ByVal sTagName As String) As String

' This function returns the XML element value.



On Error Resume Next



Dim iPos1 As Long

Dim iPos2 As Long

Dim sStartTag As String

Dim sCloseTag As String

Dim sValue As String



GetElementValue = ""

sStartTag = "<" & sTagName & ">"

sCloseTag = "</" & sTagName & ">"



iPos1 = InStr(g_sResponse, sStartTag)



If iPos1 <> 0 Then

iPos1 = iPos1 + Len(sStartTag)

iPos2 = InStr(g_sResponse, sCloseTag)

sValue = Mid$(g_sResponse, iPos1, iPos2 - iPos1)

GetElementValue = sValue

End If

End Function
Post by Franck Guillaud
Post by Helene Day
Hi everyone,
I am using MS XML version 3.0 from VB 6.0 (SP5).
I use MSXML2.DOMDocument to load an XML string, and the Load method
<?xml version="1.0" encoding="UTF-8" ?>
This line should only be on the very first line of your file.
Franck.
Loading...