Unhandled XmlException Help

Hi all,

I have encountered an XmlException issue with creating an XML document to follow a sample that I was provided. Below is a sample of what the final XML should look like.

<?xml version="1.0" encoding="UTF-8"?> <JMF xmlns="http://www.CIP4.org/JDFSchema_1_1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SenderID="JMFController" TimeStamp="2014-06-30T22:29:05+00:00" Version="1.4"> <Command ID="JMFdf1b461100bcf6b2" Type="RemoveQueueEntry" xsi:type="CommandRemoveQueueEntry"> <QueueEntryDef QueueEntryID="0f6292ab20070706150747968" /> </Command> </JMF>

The particular issue is this command here in my code:

node.SetAttribute("xsi:type", "CommandRemoveQueueEntry")

And here is the entire block of code for the XMLDocument:

[code]Dim xdoc As New XMLDocument

Dim root As XMLNode
root = xdoc.AppendChild(xdoc.CreateElement(kNamespace,“JMF”))
root.SetAttribute(“SenderID”, kSenderID)
root.SetAttribute(“TimeStamp”, currentdatetime)
root.SetAttribute(“Version”, “1.4”)
IndentNode(root, 0)

Dim node As XmlNode
node = root.AppendChild(xdoc.CreateElement(“Command”))
node.SetAttribute(“ID”, GetJMFID)
node.SetAttribute(“Type”, “RemoveQueueEntry”)
node.SetAttribute(“xsi:type”, “CommandRemoveQueueEntry”)
IndentNode(node, 1)

Dim childnode As XmlNode
childnode = node.AppendChild(xdoc.CreateElement(“QueueEntryDef”))
childnode.SetAttribute(“QueueEntryID”, hppcjobid)
IndentNode(childnode, 2)

IndentNodeCloseTag(node, 1)
IndentNodeCloseTag(root, 0)

Return xdoc.ToString[/code]

The error I am getting is: [quote] App.UnhandledException: XmlException
msg:invalid namespace prefix ‘xsi:type’
RuntimeRaiseException

REALPluginMain
XmlNode.SetAttribute%%oss
CreateJMF.XMLRemoveQueueEntry%s%os
Session.Session.JobCancelArchive%%o<Session.Session>s
WebPageViewStatus.WebPageViewStatus.Timer_Cancel_Action%%o<WebPageViewStatus.WebPageViewStatus>o
Delegate.IM_Invoke%%o
AddHandler.Stub.29%%
WebTimer._ExecuteEvent%b%osA1v
WebControl.!_ExecuteEvent%b%ssA1v
WebSession._HandleEvent%%oso<_HTTPServer.HTTPRequestContext>
WebSession._HandleRequest%i8%oso<_HTTPServer.HTTPRequestContext>
WebApplication._HandleHTTPRequest%%oo<_HTTPServer.HTTPRequestContext>
_HTTPServer.HTTPRequestThread.Event_Run%%o<_HTTPServer.HTTPRequestThread>
RuntimeStackCheck
RuntimeTextFromOldString
crt_at_quick_exit
BaseThreadInitThunk
RtlUserThreadStart[/quote]

Does anyone have any advice on how to get the attribute to read “xsi:type” as in the example XML? This one has me stumped.

It looks as though the namespace definition isn’t getting properly set on the JMF element. I believe the first argument to XmlDocument.CreateElement will only set your default namespace (not sure, I never use that), so kNamespace may not be doing what you expect if it’s got both namespaces in it.

I added below your "root = " line

xdoc.DocumentElement.SetAttribute("xmlns:xsi", "http://www/w3.org/2001/XMLSchema-instance")

then commented out the calls I didn’t define in my test and substituted dummy values for constants, etc., and the error disappeared. The return value was

<?xml version="1.0" encoding="UTF-8"?> <JMF xmlns="http://www.CIP4.org/JDFSchema_1_1" xmlns:xsi="http://www/w3.org/2001/XMLSchema-instance" SenderID="Foo" TimeStamp="Bar" Version="1.4"> <Command ID="JMFID" Type="RemoveQueueEntry" xsi:type="CommandRemoveQueueEntry"> <QueueEntryDef QueueEntryID="1"/> </Command> </JMF>

When I hit issues like this, I’ll take advantage of the debugger’s ability to show the ToString property of the XmlDocument and step through to make sure the XML is really getting created the way it should be.

Thanks Edward. You hit the nail on the head. I apparently missed that the namespace wasn’t getting properly set. My constant was for http://www.CIP4.org/JDFSchema_1_1 only, and I had not set an attribute in the root element for xmlns:xsi=“http://www/w3.org/2001/XMLSchema-instance”. This wasn’t a problem when I created the class to create JMF for a Type="SubmitQueueEntry over a year ago but flummoxed me today when adding a new method for Type=“RemoveQueueEntry” when I started getting the exception.

You solved my problem. I only needed to add the line root.SetAttribute("xmlns:xsi", "http://www/w3.org/2001/XMLSchema-instance") THANK YOU SO MUCH for your assistance!