Solved

xml serialization class is not working with colon in element tag

Posted on 2011-03-08
8
1,150 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 75

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 75

Expert Comment

by:käµfm³d 👽
ID: 35069528
Where woudl the "pre:" be going?
0
Technology Partners: 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!

 

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
 

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

Industry Leaders: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
vb.net Configuration, settings file location? 8 41
SSIS GUID Variable 2 30
vb.net sendkey 4 17
Web page design problem 3 10
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
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…

679 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