DataSet.ReadXmlSchema() changes namespace prefix

D

David Elliott

Trying to figure out why my XML Namespace is changing. Here is a snip of the full XML

Before DataSet.ReadXmlSchema() -- this is from xmlDoc.OuterXml

<?xml version=\"1.0\" encoding=\"utf-16\"?>
<xs:schema id=\"GetDocumentSummary\"
xmlns=\"\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"
xmlns:msdata =\"urn:schemas-microsoft-com:xml-msdata\"
xmlns:codegen=\"urn:schemas-microsoft-com:xml-msprop\">

Output from DataSet.GetXmlSchema()

<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n
<xs:schema id=\"GetDocumentSummary\"
xmlns=\"\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"
xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\"
xmlns:msprop=\"urn:schemas-microsoft-com:xml-msprop\">\r\n

Note the last line in each of the examples above xmlns:codegen changed to xmlns:msprop.

Why?

Thanks,
Dave


Here is the code I am using

// this is defined and set elsewhere in the system
XmlDataDocument xmlDoc;


public DataSet Schema
{
get
{
DataSet ds = new DataSet();
MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(xmlDoc.OuterXml));

ms.Position = 0;
ds.ReadXmlSchema(ms);
return (ds);
}
}
 
P

Peter Huang

Hi David,

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that after ReadXmlSchema and then
GetXmlSchema the xmlns:codegen will be changed into xmlns:msprop.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

I can reproduce the problem on my side with the code as below.
DataSet ds = new DataSet();
ds.ReadXmlSchema(@"..\..\orderDS.xsd");
Console.WriteLine(ds.GetXmlSchema());

Now I am researching the problem, I will update you with new information
ASAP.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Huang

Hi David,

Can you provide the information about how do you generate the schema
file(xsd file) with xmlns:codegen namespace and what do you want to do with
the xmlns:codegen namespace?

As we saw in the two schema before and after, we find the xmlns:codegen and
xmlns:msprop are pointed to the same namespace, so I think it may not have
any side effect with your application.

If we understand what do you want to do, there may be another better
solution for your senario.

Also if you really have any concern about the namespace alias change,
please feel free to let me know.

Thank you for your understanding.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Elliott

This is used in conjuction with the other e-mail you answered.
Looking for a better way to search & transfer information between DataSets and XmlDataDocuments

I am retrieving the original schema from a database using DataAdapter.FillSchema(),
searching for a node and then adding an attribute to the node. This will rename the field when creating
typed datasets. This is what I referenced.

http://msdn.microsoft.com/library/d...tml/cpconUsingAnnotationsWithTypedDataSet.asp

Cheers,
Dave



Here is the basic code with strings filled in.

// Create A Namspace
ns = new XmlNamespaceManager(xmlDoc.NameTable);
ns.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema")

// Add the CODEGEN Attribute to Namespace
attr = xmlDoc.CreateAttribute("xmlns", "codegen", "http://www.w3.org/2000/xmlns/");
attr.Value = "urn:schemas-microsoft-com:xml-msprop";
node.Attributes.Append(attr);
xmlDoc.Normalize();


// After Finding a particular node
// Add an attribute to rename the field when creating Typed DataSet
attr = xmlDoc.CreateAttribute( "codegen", "typedName", "urn:schemas-microsoft-com:xml-msprop");
attr.Value = "FileType";
nodeColumn.Attributes.Append(attr);


// Output from nodeColumn.OuterXml

"<xs:element
name=\"file_type\"
msdata:ReadOnly=\"true\"
type=\"xs:short\" minOccurs=\"0\"
codegen:typedName=\"FileType\"
xmlns:codegen=\"urn:schemas-microsoft-com:xml-msprop\"
xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\"
xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" />"
 
D

David Elliott

Peter,

Quick note.
I will be unavailable during the 21st - 25th.
I will catch up on any postings on the 28th.

Cheers,
Dave
 
P

Peter Huang

Hi David,

Thank you for your response.
I think the two xml namespaces as below are equal, from the xml schema
perspective, because they are pointed to the same actually namespace
"urn:schemas-microsoft-com:xml-msprop"
xmlns:msprop="urn:schemas-microsoft-com:xml-msprop" and
xmlns:codegen="urn:schemas-microsoft-com:xml-msprop"

I think we can just change the msdn article you have said in your last
reply as below.
use the xmlns:msprop="urn:schemas-microsoft-com:xml-msprop" in place of the
xmlns:codegen="urn:schemas-microsoft-com:xml-msprop"
and replace the codegen with msprop in the latter in the dataset schema(xsd
file).
It does not make any different based on the application of the MSDN article.
If you still have any concern, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top