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

Reading through an XML string from an object[]

P: n/a
Okay, I had a previous post called reading an XML document. Since this post I
have revised my code and got it to work. Now, Like Derek had mentioned in
answer to my previous post, I am getting an XmlException. The error message
is invalid date SEMICOLON expected at Line 1 Position 380. Derek you had said
something about the UTF encoding attribute in the xml declaration, it is in
fact UTF-8. So if this is my problem or what is causing the exception can you
tell me how to get around this. Of course all help is highly appreciated. The
code that follows is my C# code in the Test case that calls the xml string
from the discovered device. there is also the xml string that is returned by
this call. Derek if you take a look at this also look at my previous post
entitled reading an xml document as I had posted another part to it.

private bool xmlNav(string sString)
XmlDocument deviceInfo = new XmlDocument();
XmlNode root = deviceInfo.DocumentElement;
if(Convert.ToInt32(deviceInfo.FirstChild.ChildNode s[0].InnerText) < 1)
return true;
return false;
catch(XmlException e)
return false;
private RunResult TestAssertion(ref RunState resultState, out string
//Declare Local Variables.
UPnPRootDevice root;
UPnPDevice device;
object[] objOut = new object[0];

//Initialize default values.
root = null;
device = null;
RunResult result = RunResult.Passed;
resultMessage = "Device properly refuses additional connections requests
when occupied by a connected UI!";

//Create UPnP device.
root = new UPnPRootDevice(_url, _localInterface);

// Find the device by UDN.
device = root.FindDeviceByUDN(_udn);
if(device == null)
resultMessage = "The UDN was not found in any device at location '"
+ _url + "'!";
//Use Invoke Method to get protocolinfo xml.
bool xmlContent = false;
device.Services[0].Invoke("GetDeviceProfile",out objOut);
xmlContent = xmlNav(objOut[0].ToString());
result = RunResult.Passed;
resultMessage = "Device properly refuses additional connections requests
when occupied by a connected UI!";
result = RunResult.Failed;
resultMessage = "Device does not support Stack Capability and properly
refuses connection requests when occupied by a UI";
return result;

The XML String is as follows:

<?xml version="1.0" encoding="UTF-8"><deviceprofile
DeviceProfile.xsd"><maxHoldUI>10</maxHoldUI><protocol shortName="XRT2"
<protocolInfo>version=2.1,displayWidth=640,display Height=480,imageEncoding=JPEG&PNG,maxCommandSize=3 00000</protocolInfo>
Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
"Ldaled" <Ld****> wrote in message news:D8**********************************@microsof
I am getting an XmlException. The error message
is invalid date SEMICOLON expected at Line 1 Position 380. : : <?xml version="1.0" encoding="UTF-8"><deviceprofile
This XML declaration should end with "?>", like this,

<?xml version="1.0" encoding="UTF-8" ?>

Since it is represented as a .NET String, the encoding should also
be UTF-16, which was the point I was trying to make in the earlier
thread (but if you aren't experiencing any problems from this,
curious, then I suppose it can stand).

: : [...]=480,imageEncoding=JPEG&PNG,maxCommandSize=300000[...]
The SEMICOLON error message comes from this location. The
ampersand ('&') character is restricted because it is customarily
used to denote the start of an entity reference.

The XML parser is reading &PNG, and trying to interpret it as
an entity reference; however ',' is an illegal character for such a
name and at this point it throws an XmlException.

The XML producer has two options (to produce correct XML):

1. When it needs to emit an ampersand ('&'), it should emit the
character entity reference for an ampersand:


By this token, the above name/value pair for imageEncoding would
look like this,

2. It can emit the content of any text node that uses forbidden
characters within a CDATA section. CDATA sections are
unparsed (_except_ for the CDATA section terminator, "]]>",
which is then the only prohibited content in a CDATA section).

By this token, if the protocolInfo element _only_ contained an
imageEncoding name/value pair it would look like this,

If it turns out the XML generator already burnt into the hardware
of your device is faulty, then you need to pre-process the string
before it can be parsed as legal XML by replacing instances of
the ampersand ('&') in your software client,

sString = sString.Replace( "&", "&amp;");
deviceInfo.LoadXml( sString);
: : if(Convert.ToInt32(deviceInfo.FirstChild.ChildNode s[0].InnerText) < 1)

You might also want to perform some null checking on the return
values of these properties, to ensure the maxHoldUI element truly
exists where you believe.
Derek Harmon
Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.