Solved

xml serialization class is not working with colon in element tag

Posted on 2011-03-08
8
1,106 Views
Last Modified: 2012-05-11
Hello experts, I am using the xml serialization class to create a serialized xml file, within the xml i have tags that need to contain a colon.   When the xml is created the colon is replaced with _x003A_

<pre_x003A_salesorder>

<pre:salesorder>

Why is this happening and how do i fix it?
0
Comment
Question by:tentavarious
  • 6
  • 2
8 Comments
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
ID: 35069269
In XML, the construct xxx: indicates an alias to a namespace. There should be a matching namespace declaration in your XML which defines the namespace which xxx represents. Can you post the code and a sanitized example of your XML?
0
 

Author Comment

by:tentavarious
ID: 35069472
Here is a simplified version of the xml that gets generated


<?xml version="1.0" encoding="utf-16"?>
<pre_x003A_SalesOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <DataArea>
    <Received>
      <Status>SUCCESS</Status>
    </Received>
    <Order>
      <Headinfo>
       <Note>OrderDate: 3/8/2011</Note>
      </Headinfo>
    </Order>
  </DataArea>
</pre_x003A_SalesOrder>

I cant post the xml code because it contains sensitive information but should i be looking for attribute tags like this?

System.Xml.Serialization.XmlTypeAttribute([Namespace]:="http://ourcompany.com/salesorderinfo"),  _
 System.Xml.Serialization.XmlRootAttribute("SalesOrder", [Namespace]:="http://ourcompany.com/salesorderinfo", IsNullable:=false)>  _
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 35069528
Where woudl the "pre:" be going?
0
 

Author Comment

by:tentavarious
ID: 35069577
Well what the generate xml should look like is this

<pre:SalesOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <DataArea>
    <Received>
      <Status>SUCCESS</Status>
    </Received>
    <Order>
      <Headinfo>
       <Note>OrderDate: 3/8/2011</Note>
      </Headinfo>
    </Order>
  </DataArea>
</pre:SalesOrder>
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:tentavarious
ID: 35097589
Ok, when i go through and serialize the xml why does it put this tag on

<?xml version="1.0" encoding="utf-16"?>

instead of encoding it in utf-8  ?
0
 

Author Comment

by:tentavarious
ID: 35097828
Hey guys i found the problem, this site provided me with the answer

http://stackoverflow.com/questions/3862063/serializing-an-object-as-utf-8-xml-in-net


The default encoding must be utf-16, so switching it to uft-8 before serializing seems to have fixed the issue.
0
 

Author Comment

by:tentavarious
ID: 35108809
Ok, i still cant get this working, i am using the xsd.exe tool to create the xml serialization class based off the schema they are sending me.  Can someone point me to a tutorial that better explains what i should be doing.
0
 

Author Comment

by:tentavarious
ID: 35109018
K, could someone explain what this code should be doing?

<System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42"), _
 System.SerializableAttribute(), _
 System.Diagnostics.DebuggerStepThroughAttribute(), _
 System.ComponentModel.DesignerCategoryAttribute("code"), _
 System.Xml.Serialization.XmlTypeAttribute([Namespace]:="http://mycom.com/updatemachine"), _
 System.Xml.Serialization.XmlRootAttribute("UpdateOrder", [Namespace]:="http://mycom.com/updatemachine", IsNullable:=False)> _
Partial Public Class UpdateOrderType
end Class

I left out all the variables, this code gets created when i run the xsd.exe tool on their provided shema?   When i run this code the it creates this opening tag

<UpdateOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="<UpdateOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://mycom.com/updatemachine">


The above tag is missing the "pre:"  I am being told the above tag should look like this

<pre:UpdateOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="<UpdateOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pre="http://mycom.com/updatemachine">
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now