Guff_
asked on
XML load without encoding possible?
Hi,
I have 3 xml files
xml1.xml :
<names>
<name>Patrick</name>
</names>
xml2.xml :
<names>
<name>Pätrick</name>
</names>
xml3.xml :
<?xml version="1.0" encoding="iso-8859-1" ?>
<names>
<name>Pätrick</name>
</names>
now i want to load the xml.
I use :
set xml = Server.CreateObject("MSXML 2.DOMDocum ent")
xml.async = false
xml.load("xml#.xml")
if xml.parseError.errorcode<> 0 then Response.Write "Error" END IF
set xml = nothing
xml 1 and 3 don't give an Error
xml 2 does (due encoding probs)
now it comes :
it is possible to load xml 2 without Error WITHOUT changing the xml file itself ????????
I have 3 xml files
xml1.xml :
<names>
<name>Patrick</name>
</names>
xml2.xml :
<names>
<name>Pätrick</name>
</names>
xml3.xml :
<?xml version="1.0" encoding="iso-8859-1" ?>
<names>
<name>Pätrick</name>
</names>
now i want to load the xml.
I use :
set xml = Server.CreateObject("MSXML
xml.async = false
xml.load("xml#.xml")
if xml.parseError.errorcode<>
set xml = nothing
xml 1 and 3 don't give an Error
xml 2 does (due encoding probs)
now it comes :
it is possible to load xml 2 without Error WITHOUT changing the xml file itself ????????
ASKER
I can't change xml2 so thats not an option
There is an error because it isn't valid XML.
If you get it from somewhere, then you should ask them to send valid XML, not a string that looks like it is XML, but isn't.
The other option is to change to XML you get into something that is valid XML. I don't think that there is any other option.
If you get it from somewhere, then you should ask them to send valid XML, not a string that looks like it is XML, but isn't.
The other option is to change to XML you get into something that is valid XML. I don't think that there is any other option.
ASKER
Option 1 : ask for valid xml
This not possible :(
Option 2 : convert invalid xml to valid xml
Ok sounds nice. Is there a simple way to do that?
This not possible :(
Option 2 : convert invalid xml to valid xml
Ok sounds nice. Is there a simple way to do that?
What is the parseError ? I managed to load the doc ok.
ASKER
parseError:
An invalid character was found in text content.
I read somewhere that i could be a server "problem".
An invalid character was found in text content.
I read somewhere that i could be a server "problem".
Well, I loaded it as a string using the following code and it parsed ok:
<%
sXml = "<names><name>Pätrick</nam e></names> "
Set oDom = Server.CreateObject("MSXML 2.DOMDocum ent.4.0")
bOK = oDom.loadXML(sXml)
If Not bOK Then
Response.Write oDom.parseError.reason
Else
Response.Write oDom.selectSingleNode("/na mes/name") .Text
End If
Set oDom = Nothing
%>
<%
sXml = "<names><name>Pätrick</nam
Set oDom = Server.CreateObject("MSXML
bOK = oDom.loadXML(sXml)
If Not bOK Then
Response.Write oDom.parseError.reason
Else
Response.Write oDom.selectSingleNode("/na
End If
Set oDom = Nothing
%>
ASKER
On that exact code i get:
Server.CreateObject Failed
I try without ".4.0" and i get Pätrick .. huh...?
But stored in an xml file on the server i get:
An invalid character was found in text content. ?
Server.CreateObject Failed
I try without ".4.0" and i get Pätrick .. huh...?
But stored in an xml file on the server i get:
An invalid character was found in text content. ?
Hmm, why not read the file into a string and then load it? Would that help?
ASKER
@sybe
seems logical...
but how do i read the xml into a string?
sorry i'm a bit a n00b
seems logical...
but how do i read the xml into a string?
sorry i'm a bit a n00b
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Tnx!
The solution was to do a binary2string conversion and then load it into a string:
Set xmlhttp = Server.CreateObject("Msxml 2.ServerXM LHTTP.3.0" )
xmlhttp.Open "GET", urlXML, False
xmlhttp.send
' XML verwerken
sXml = "<?xml version='1.0' encoding='iso-8859-1'?>" & SimpleBinaryToString(xmlht tp.respons eBody)
Set oDom = Server.CreateObject("MSXML 2.DOMDocum ent")
bOK = oDom.loadXML(sXml)
The solution was to do a binary2string conversion and then load it into a string:
Set xmlhttp = Server.CreateObject("Msxml
xmlhttp.Open "GET", urlXML, False
xmlhttp.send
' XML verwerken
sXml = "<?xml version='1.0' encoding='iso-8859-1'?>" & SimpleBinaryToString(xmlht
Set oDom = Server.CreateObject("MSXML
bOK = oDom.loadXML(sXml)
<name>Pätrick</name>
</names>