473,383 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Setting a reference to a schema doesn't work?

Hello NG!

Using the System.Xml.XmlDocument I want to create such a xml-file:

<?xml version="1.0" encoding="utf-8"?>
<RootElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="RootElement.xsd ">
....
</RootElement>

(That's what XMLSpy generates when assigning a schema to an xml-file.)

I tried...
pDoc = New System.Xml.XmlDocument
pDoc.AppendChild(pDoc.CreateXmlDeclaration("1.0", "utf-8", ""))
pRoot = pDoc.AppendChild(pDoc.CreateElement("RootElement") )
pRoot.Attributes.Append(pDoc.CreateAttribute("xmln s:xsi"))
pRoot.Attributes("xmlns:xsi").Value =
"http://www.w3.org/2001/XMLSchema-instance"
pRoot.Attributes.Append(pDoc.CreateAttribute("xsi: noNamespaceSchemaLocation"))
pRoot.Attributes("xsi:noNamespaceSchemaLocation"). Value = "RootElement.xsd"

But then I get
<RootElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
noNamespaceSchemaLocation="RootElement.xsd">

So the Prefix "xsi" for "noNamespaceSchemaLocation" is missing and the file
can't be validated, because this attribute is "unexpected". What's wrong
with that code? How can I produce a correct link to an schema?

Thanks,
D.Barisch
Nov 12 '05 #1
1 1803
Found it by myself...

The framework does more work than I expected. Using

pRoot = pDoc.AppendChild(pDoc.CreateElement("RootElement") )
pRoot.Attributes.Append(pDoc.CreateAttribute("xsi: noNamespaceSchemaLocation",
"http://www.w3.org/2001/XMLSchema-instance"))
pRoot.Attributes("xsi:noNamespaceSchemaLocation"). Value = "RootElement.xsd"

instead of

| pRoot.Attributes.Append(pDoc.CreateAttribute("xmln s:xsi"))
| pRoot.Attributes("xmlns:xsi").Value =
| "http://www.w3.org/2001/XMLSchema-instance"
|
pRoot.Attributes.Append(pDoc.CreateAttribute("xsi: noNamespaceSchemaLocation"))
| pRoot.Attributes("xsi:noNamespaceSchemaLocation"). Value =
"RootElement.xsd"

is enough.

Bye,
D.Barisch
Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Olaf Meyer | last post by:
Apprentently xerces 2.6.0 (Java) does not validate against contraints specified in the schema (e.g. constraints specified via unique element). The validation works with the XML editor I'm using...
4
by: Ian | last post by:
I would like to set a path to a schema where both the xml file and the schema are on my local hard drive (e.g. c:\XML\auto.xml and c:\XML\auto.xsd) Thank you, Ian
6
by: trexim | last post by:
Hi, I am trying to create a Web Reference for CSTA using the URL http://www.ecma-international.org/standards/ecma-348/csta-wsdl/csta-wsdl-all-operations.wsdl Visual .Net complains that: "...
18
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on...
0
by: Richard Gregory | last post by:
Hi, I have the wsdl below, for an Axis web service, and when I select Add Web Refernce in Visual Studio the proxy is missing a class representing the returnedElementsType (see reference.cs below...
2
by: Mark | last post by:
Hi... I've been trying the .Validate() method on the XmlDocument to validate some xml against a schema, but one thing I noted was that unless the document explicitly declares the schema as a...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
9
by: Doug Glancy | last post by:
I got the following code from Francesco Balena's site, for disposing of Com objects: Sub SetNothing(Of T)(ByRef obj As T) ' Dispose of the object if possible If obj IsNot Nothing AndAlso...
0
by: =?ISO-8859-1?Q?Jan_Thom=E4?= | last post by:
Hi, I've been trying like a madman to make my WSDL work with .net, but it seems I am out of luck. Whenever I add a service reference to Visual C#, the code gets generated fine, however all...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.