Solved

Reading XML problem with invalid character

Posted on 2007-11-29
8
2,323 Views
Last Modified: 2012-05-05
Hi,
I am developing a web application using ASP and VBScript.
I have to read an XML data returned from another third party company using SAP.
The XML data looks like:

<eQuoteCustomer>
   <KISno>114735</KISno>
   <SAPno>73990</SAPno>
   <Type>Installation</Type>
   <Companyname>ETIC</Companyname>
   ...........

The whole job has been finished. Most of the returned XML files can be read without problem except those which contains some reserved character (like & ). So the following XML will cause the error:

<eQuoteCustomer>
   <KISno>114735</KISno>
   <SAPno>73990</SAPno>
   <Type>Installation</Type>
   <Companyname> CIAC & SO </Companyname>
....

I got this error : object required  objXML.documentElement. When ever the XML file contains:  &

How should I fix this problem?

Thanks,
JINNI
Function LoadCustomerData(ByRef objTpl, ByVal kisNo)	
	Dim objXML, contactList, index, strPath
	Dim sapNo, customerType, relative, address, postcode
	Set objXML = Server.CreateObject("Microsoft.XMLDOM")
	objXML.async = false
	
	strPath = strDirCRMData & "eQuote" & kisNo & ".xml"
	
	If CheckFileExists(strPath) Then 
		objXML.Load(strPath)		
		sapNo = objXML.documentElement.childNodes(1).text
		customerType = objXML.documentElement.childNodes(2).text
		relative = objXML.documentElement.childNodes(3).text
.............

Open in new window

0
Comment
Question by:jinn_hnnl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 11

Expert Comment

by:Rajesh Dalmia
ID: 20372668
using Server.HTMLEncode
0
 
LVL 25

Assisted Solution

by:Rouchie
Rouchie earned 100 total points
ID: 20372786
>> using Server.HTMLEncode

But that will encode the whole XML file won't it?  

Ideally the problem needs correct at the SAP end, because they are emitting invalid XML files that you are expected to deal with.  They should encode special characters in the XML file so that ASP can read it without error:

   <Companyname> CIAC &amp; SO </Companyname>
0
 
LVL 10

Author Comment

by:jinn_hnnl
ID: 20373121
@ rdonline1: can you please elaborate more your idea?. Because the error seems to appear as soon as I load the data. I guess if I use some kind of XMLParse code to check, it will give the error. But I must have the content of the file instead of throwing an exception overthere.

Rouchi, it is imposible. They are using some kind of IBM Lotus database, then export that database to XML using Domino designer. The content of the database is hardly changed. It gonna take a lot of time if I ask them to modify the code (company policy).

I will have to find a solution to deal with that XML file.

Any idea ?
0
Industry Leaders: 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!

 
LVL 28

Accepted Solution

by:
sybe earned 400 total points
ID: 20373266
Rouchie is right. The third party is exporting invalid XML.

If they don't fix it, you will have to fix it. But there are so many ways to create uinvalid XML (with invalid characters), that you are going to have serious problems to cover them all.

If you want to cover all possible errors, you should treat the xml as a string (which means basically write your own XML parser).

If you want to cover the problems for each character that occurs in reality, you could do something like:

Set oFS = Server.CreateObject("Scripting.FileSystemObject")
Set oTextStream = oFS.OpenTextFile(strPath)
sXML = oTextStream.ReadAll
oTextStream.Close: Set oTextStream = Nothing
sXML = Replace(sXML, "&", "&amp;")
' replace here any other invalid characters....

objXML.LoadXML(sXML)




0
 
LVL 28

Expert Comment

by:sybe
ID: 20373433
By the way, I don't believe that an IBM application would output invalid XML.

Maybe it is the way the XML is stored as a file, between the output from Domino and you picking it up. It looks as if the the XML file is stored as a text file, not as an XML file. If I were you I'd look at that first.
0
 
LVL 10

Author Comment

by:jinn_hnnl
ID: 20374129
Sybe,

Your solution is what I need :) Thanks, I have thought about it and I think you catched the solution.

Well as far as I am concern, the CRM - customer database is stored inside IBM Lotus database (if I am correct), our client need the data, they request a webservice, and XML files (plus some another jobs with SAP).

The procedure is written using Domino, and they export that Lotus database to XML file. Then content has the invalid character (some company name contains &).

But your solution is correct!

I still want to hear another possible solution before close this question.
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 20374193
I don't think there is another solution. Either you fix the errors or they do.  If their procedure is exporting raw symbols then they should fix it.

There are other symbols in XML that will invalidate the file.  The ampersand character is just the start of what you'll have to replace unless they fix this for you!
0
 
LVL 10

Author Closing Comment

by:jinn_hnnl
ID: 31411631
I have not test the code, but the idea is what I need :)
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

763 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