473,322 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Cannot Read CDATA (using WINDOWS-1252 encoding)

Hi all,

I have an XML document fed to me from a third party app:

<?xml version="1.0" encoding="WINDOWS-1252" ?>
<GatewayPlan xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Diagnostics>
<ErrorCode>0</ErrorCode>
<ErrorDescription>OK</ErrorDescription>
<Date>11/10/2004</Date>
<Time>12:45 PM</Time>
</Diagnostics>
<GatewayProjectID>5</GatewayProjectID>
<CostCenters>
<CostCenter>1239280000</CostCenter>
<CostCenter>1239320000</CostCenter>
</CostCenters>
<Plan>
<JDEID>1108</JDEID>
<GatewayID>2186</GatewayID>
<Name><![CDATA[1108 Maravilla]]></Name>
<Description><![CDATA[Step into the first floor and take in the spacious
living and dining rooms. Enjoy the gourmet-ready kitchen connected to the
family room on one side and the nook on the other. A den is included
downstairs near the third bath. Go upstairs and enjoy 3 beautiful bedrooms,
2 baths and a tech center.]]></Description>
</Plan>
</GatewayPlan>

I use an XMLTextReader in my app that used to be able to read this type of
data, but the developer of the TPA changed encoding on me and now when I try
to read the CDATA section:

Dim oXmlRdrAs New XmlTextReader(New StringReader(strDocument))
With oXmlRdr
Select Case .Name
Case "Description"
planDesc = .ReadElementString
End Select
....

I receive the following error on "planDesc = .ReadElementString"
ex.Message = "'EndElement' is an invalid node type. Line 1, position 843."

Any ideas on why my app would suddenly not be able to read this?

TIA
-Rich

Nov 12 '05 #1
4 4735


Rich Wallace wrote:

I have an XML document fed to me from a third party app:

<?xml version="1.0" encoding="WINDOWS-1252" ?>
<GatewayPlan xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Diagnostics>
<ErrorCode>0</ErrorCode>
<ErrorDescription>OK</ErrorDescription>
<Date>11/10/2004</Date>
<Time>12:45 PM</Time>
</Diagnostics>
<GatewayProjectID>5</GatewayProjectID>
<CostCenters>
<CostCenter>1239280000</CostCenter>
<CostCenter>1239320000</CostCenter>
</CostCenters>
<Plan>
<JDEID>1108</JDEID>
<GatewayID>2186</GatewayID>
<Name><![CDATA[1108 Maravilla]]></Name>
<Description><![CDATA[Step into the first floor and take in the spacious
living and dining rooms. Enjoy the gourmet-ready kitchen connected to the
family room on one side and the nook on the other. A den is included
downstairs near the third bath. Go upstairs and enjoy 3 beautiful bedrooms,
2 baths and a tech center.]]></Description>
</Plan>
</GatewayPlan>

I use an XMLTextReader in my app that used to be able to read this type of
data, but the developer of the TPA changed encoding on me and now when I try
to read the CDATA section:

Dim oXmlRdrAs New XmlTextReader(New StringReader(strDocument))
With oXmlRdr
Select Case .Name
Case "Description"
planDesc = .ReadElementString
End Select
...

I receive the following error on "planDesc = .ReadElementString"
ex.Message = "'EndElement' is an invalid node type. Line 1, position 843."

Any ideas on why my app would suddenly not be able to read this?


I see that you are using an XmlTextReader on top of a StringReader so
somewhere you probably construct the string strDocument and maybe there
your code doesn't pay attention to the encoding. Just a guess but we
need to see how you construct the strDocument and from where you
construct it to be able to help.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
Sorry about that....

It's passed to me as a string value.

Function ProcessMessage(ByVal strDocument As String) As String 'This
accepts the incoming document as a string

Dim oXmlRdr As New XmlTextReader(New StringReader(strDocument))
Dim oXmlDoc As New XmlDocument()

oXmlDoc.LoadXml(strDocument)
...
End Function
"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:ud**************@TK2MSFTNGP15.phx.gbl...


Rich Wallace wrote:

I have an XML document fed to me from a third party app:

<?xml version="1.0" encoding="WINDOWS-1252" ?>
<GatewayPlan xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Diagnostics>
<ErrorCode>0</ErrorCode>
<ErrorDescription>OK</ErrorDescription>
<Date>11/10/2004</Date>
<Time>12:45 PM</Time>
</Diagnostics>
<GatewayProjectID>5</GatewayProjectID>
<CostCenters>
<CostCenter>1239280000</CostCenter>
<CostCenter>1239320000</CostCenter>
</CostCenters>
<Plan>
<JDEID>1108</JDEID>
<GatewayID>2186</GatewayID>
<Name><![CDATA[1108 Maravilla]]></Name>
<Description><![CDATA[Step into the first floor and take in the spacious living and dining rooms. Enjoy the gourmet-ready kitchen connected to the family room on one side and the nook on the other. A den is included
downstairs near the third bath. Go upstairs and enjoy 3 beautiful bedrooms, 2 baths and a tech center.]]></Description>
</Plan>
</GatewayPlan>

I use an XMLTextReader in my app that used to be able to read this type of data, but the developer of the TPA changed encoding on me and now when I try to read the CDATA section:

Dim oXmlRdrAs New XmlTextReader(New StringReader(strDocument))
With oXmlRdr
Select Case .Name
Case "Description"
planDesc = .ReadElementString
End Select
...

I receive the following error on "planDesc = .ReadElementString"
ex.Message = "'EndElement' is an invalid node type. Line 1, position 843."
Any ideas on why my app would suddenly not be able to read this?


I see that you are using an XmlTextReader on top of a StringReader so
somewhere you probably construct the string strDocument and maybe there
your code doesn't pay attention to the encoding. Just a guess but we
need to see how you construct the strDocument and from where you
construct it to be able to help.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 12 '05 #3


Rich Wallace wrote:

It's passed to me as a string value.

Function ProcessMessage(ByVal strDocument As String) As String 'This
accepts the incoming document as a string

Dim oXmlRdr As New XmlTextReader(New StringReader(strDocument))


Maybe the XML parser gets confused when it reads from a string which is
always UTF-16 encoded but the string starts with an XML declaration
declaring the encoding as Windows-1252. What happends if you use string
processing to remove the XML declaration from the string before you pass
it to the XmlTextReader?

Other than that I can only suggest to try to reduce your code to the
minimum to reproduce the problem and then post that and the input XML so
that others can check what is wrong, I am not sure where that error message
'EndElement' is an invalid node type
comes from.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #4
I am not able to repro this issue. Here is my code. Can you tell me what is
different from this code and your code?

using System;
using System.IO;
using System.Text;
using System.Collections;
using System.Xml;
using System.Xml.Schema;
using System.Xml.XPath;

public class Test
{

public static void ValidationCallback( object o, ValidationEventArgs e)
{
Console.WriteLine ( e.Message );
}

public static void Main( string[] args )
{
string xmlStr = @"<?xml version='1.0' encoding='WINDOWS-1252' ?>
<GatewayPlan xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<Diagnostics>
<ErrorCode>0</ErrorCode>
<ErrorDescription>OK</ErrorDescription>
<Date>11/10/2004</Date>
<Time>12:45 PM</Time>
</Diagnostics>
<GatewayProjectID>5</GatewayProjectID>
<CostCenters>
<CostCenter>1239280000</CostCenter>
<CostCenter>1239320000</CostCenter>
</CostCenters>
<Plan>
<JDEID>1108</JDEID>
<GatewayID>2186</GatewayID>
<Name><![CDATA[1108 Maravilla]]></Name>
<Description><![CDATA[Step into the first floor and take in the spacious
living and dining rooms. Enjoy the gourmet-ready kitchen connected to the
family room on one side and the nook on the other. A den is included
downstairs near the third bath. Go upstairs and enjoy 3 beautiful bedrooms,
2 baths and a tech center.]]></Description>
</Plan>
</GatewayPlan>";

XmlTextReader tr = new XmlTextReader( new StringReader( xmlStr ) );

while ( tr.Read() );
}

}
"Rich Wallace" <rw********@gmail.dontspamme.com> wrote in message
news:uG**************@TK2MSFTNGP12.phx.gbl...
Hi all,

I have an XML document fed to me from a third party app:

<?xml version="1.0" encoding="WINDOWS-1252" ?>
<GatewayPlan xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Diagnostics>
<ErrorCode>0</ErrorCode>
<ErrorDescription>OK</ErrorDescription>
<Date>11/10/2004</Date>
<Time>12:45 PM</Time>
</Diagnostics>
<GatewayProjectID>5</GatewayProjectID>
<CostCenters>
<CostCenter>1239280000</CostCenter>
<CostCenter>1239320000</CostCenter>
</CostCenters>
<Plan>
<JDEID>1108</JDEID>
<GatewayID>2186</GatewayID>
<Name><![CDATA[1108 Maravilla]]></Name>
<Description><![CDATA[Step into the first floor and take in the spacious
living and dining rooms. Enjoy the gourmet-ready kitchen connected to the
family room on one side and the nook on the other. A den is included
downstairs near the third bath. Go upstairs and enjoy 3 beautiful bedrooms, 2 baths and a tech center.]]></Description>
</Plan>
</GatewayPlan>

I use an XMLTextReader in my app that used to be able to read this type of
data, but the developer of the TPA changed encoding on me and now when I try to read the CDATA section:

Dim oXmlRdrAs New XmlTextReader(New StringReader(strDocument))
With oXmlRdr
Select Case .Name
Case "Description"
planDesc = .ReadElementString
End Select
...

I receive the following error on "planDesc = .ReadElementString"
ex.Message = "'EndElement' is an invalid node type. Line 1, position 843."
Any ideas on why my app would suddenly not be able to read this?

TIA
-Rich

Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: bb | last post by:
Hello In my Session_OnStart in Global.asa, I am setting some cookies. One of them, I set as follows: dim UserID UserID = Request.ServerVariables("LOGON_USER") Response.Cookies("User")("ID")...
5
by: Axel Dachtler | last post by:
Hi, I have a listener problem. The listener cannot read SERVICE_NAME in TNS-Descriptor. The service-name I specified in Oracle Net Manager for this database is testdb as well. ...
3
by: wenmang | last post by:
Hi, I ma thinking whether to use Base64 encoding to encode the binary content in the XML file. I have done some simple calculations, it seems to me that the size for encoded content increases by...
2
by: Jill | last post by:
Hi I am using ms acces 2002 to read an xml file. I am using the DOM object in ms access - version xml 4 with service pack 2. here is the start of the code below. But I am having trouble reading...
4
by: Yiu | last post by:
upgent help i want to start IE explorer using C# i try many code such as below: ProcessStartInfo startInfo = new ProcessStartInfo("IEXPLORE.EXE"); Process.Start(startInfo); or Process...
0
by: Christopher Attard | last post by:
Hi, I'm using the PerformanceCounter .NET class to obtain the "% Processor Time" for processes that are running on a remote host. These processes are obtained using the...
15
by: waltbrad | last post by:
Hello. I'm studying the book "C++ Primer Plus" by Stephan Prata. In chapter 6 he gives an exercise that reads from a file. The list is thus: 4 Sam Stone 2000 Freida Flass 100500 Tammy...
4
by: pedro | last post by:
application cannot read the app.config file i have a config file for the executable i try to read it but it throws an exception when building the setup for the project vs2005 do not add the...
8
by: gkhangelani | last post by:
Hi How would I fix an error below: server.log file :
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.