• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1285
  • Last Modified:

xml serialization class is not working with colon in element tag

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
tentavarious
Asked:
tentavarious
  • 6
  • 2
1 Solution
 
käµfm³d 👽Commented:
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
 
tentavariousAuthor Commented:
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
 
käµfm³d 👽Commented:
Where woudl the "pre:" be going?
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
tentavariousAuthor Commented:
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
 
tentavariousAuthor Commented:
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
 
tentavariousAuthor Commented:
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
 
tentavariousAuthor Commented:
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
 
tentavariousAuthor Commented:
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now