IMPORTANT:
this is not a Support Forum! Experienced users might answer from time to time questions posted here. If you need a professional and reliable answer, or if you want to report a bug, please contact Altova Support instead.

Profile: dev3
About
User Name: dev3
Forum Rank: Newbie
Real Name:
Location Canada
Occupation:
Interests:
Gender: None Specified
Statistics
Joined: Wednesday, February 28, 2018
Last Visit: Wednesday, February 28, 2018 5:34:09 AM
Number of Posts: 1
[0.01% of all post / 0.00 posts per day]
Avatar
Last 10 Posts
Topic: How to get a namespace prefix in element names instead of URL in generated code
Posted: Wednesday, February 28, 2018 5:33:22 AM
Hello dear forum members,

We have generated some c# classes from a set of schemas, each using a different namespace.
For example below, lets say that FirstName / LastName types have been defined in a different schema with namespace "http://custom.namespace".

Out of the box we get the xml below, which duplicates "http://custom.namespace" URL in each element like below:

<?xml version="1.0" encoding="utf-8"?>
<Customer xmlns="http://default.namespace">
<ID>123</ID>
<FirstName xmlns="http://custom.namespace">John</FirstName>
<LastName xmlns="http://custom.namespace">Doe</LastName>
</Customer>

What do we need to do in code in order to get "http://custom.namespace" namespace listed in a root element with some prefix and have FirstName / LastName elements use it, so it would look like this:

<?xml version="1.0" encoding="utf-8"?>
<Customer xmlns="http://default.namespace" xmlns:nax="http://custom.namespace">
<ID>123</ID>
<nax:FirstName>John</FirstName>
<nax:LastName>Doe</LastName>
</Customer>

Use of the Altova User Forum(s) is governed by the Altova Terms of Use.