By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,702 Members | 1,101 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,702 IT Pros & Developers. It's quick & easy.

Cannot Read CDATA (using WINDOWS-1252 encoding)

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a


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

P: n/a
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

P: n/a


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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.