?
Solved

XML load without encoding possible?

Posted on 2006-05-10
12
Medium Priority
?
273 Views
Last Modified: 2008-02-01
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("MSXML2.DOMDocument")
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 ????????
0
Comment
Question by:Guff_
  • 6
  • 3
  • 3
12 Comments
 
LVL 28

Expert Comment

by:sybe
ID: 16648838
<names>
   <name>P&#228;trick</name>
</names>
0
 

Author Comment

by:Guff_
ID: 16648885
I can't change xml2 so thats not an option
0
 
LVL 28

Expert Comment

by:sybe
ID: 16649015
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Guff_
ID: 16649055
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?
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 16649201
What is the parseError ? I managed to load the doc ok.
0
 

Author Comment

by:Guff_
ID: 16649287
parseError:
An invalid character was found in text content.

I read somewhere that i could be a server "problem".
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 16649323
Well, I loaded it as a string using the following code and it parsed ok:

    <%
        sXml = "<names><name>Pätrick</name></names>"
        Set oDom = Server.CreateObject("MSXML2.DOMDocument.4.0")

        bOK = oDom.loadXML(sXml)

        If Not bOK Then
            Response.Write oDom.parseError.reason
        Else
            Response.Write oDom.selectSingleNode("/names/name").Text
        End If

        Set oDom = Nothing
    %>
0
 

Author Comment

by:Guff_
ID: 16649468
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. ?
0
 
LVL 28

Expert Comment

by:sybe
ID: 16649537
Hmm, why not read the file into a string and then load it? Would that help?
0
 

Author Comment

by:Guff_
ID: 16649563
@sybe
seems logical...
but how do i read the xml into a string?
sorry i'm a bit a n00b
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 750 total points
ID: 16649635
Load the contents into a string using:

    Set fso = Server.CreateObject("Scripting.FileSystemObject")
    Set ts = fso.OpenTextFile("test2.xml", 1, false)

    sXml = ts.ReadAll
   
    ts.Close
0
 

Author Comment

by:Guff_
ID: 16707751
Tnx!

The solution was to do a binary2string conversion and then load it into a string:

Set xmlhttp = Server.CreateObject("Msxml2.ServerXMLHTTP.3.0")
xmlhttp.Open "GET", urlXML, False
xmlhttp.send

' XML verwerken
sXml = "<?xml version='1.0' encoding='iso-8859-1'?>" & SimpleBinaryToString(xmlhttp.responseBody)
Set oDom = Server.CreateObject("MSXML2.DOMDocument")
bOK = oDom.loadXML(sXml)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question