Groups | Blog | Home
all groups > dotnet xml > july 2004 >

dotnet xml : XML Root Node


Mythran
7/14/2004 9:49:45 AM
I have a file I'm using as a Configuration file (configuration as in options and
such). When I create the xml file in the .Net IDE, it places the following
(snip):

<Configuration xmlns="Blah">

</Configuration>

This is the way I'd like it but it doesn't work this way :( When I validate it
against the xsd file, it says that it's invalid. (Can't remember error, don't
have time to reproduce). The fix is changing it to the following:

<cfg:Configuration xmlns:cfg="Blah">

</cfg:Configuration>




So, just need 1 of the two (preferably the first) questions answered:

1.) How can I get xml to be valid using <Configuration> rather than
<cfg:Configuration> when it loads? I'd rather use <Configuration> as it's nicer
on my eyes.

2.) How can I get the ide to automatically place the "cfg" prefix to the root
node as in <cfg:Configuration> as well as append to the xmlns attribute and
prepend to the closing Configuration tag?

Either way will work, but I really need one of them asap. Thanks for any and all
help :)

Mythran

Mythran
7/15/2004 8:22:42 AM
Wish it were that simple. elementFormDefault attribute already set.

Mythran

[quoted text, click to view]

Oleg Tkachenko [MVP]
7/15/2004 10:18:09 AM
[quoted text, click to view]

Change your schema. Read about elementFormDefault attribute.

--
Oleg Tkachenko [XML MVP]
Mythran
7/15/2004 11:50:44 AM

[quoted text, click to view]

Tell that to .Net! :P

All of the above are valid, and can load, with one exception...


<!--Sample.xml-->
<?xml version="1.0" encoding="utf-8" ?>

<Configuration xmlns="MCIS.Applications.Reports.Schema.Configuration">
<Report Path="crystalreports\Balance Sheet.rpt">
<ExportOptions FileNameFormat="Balance Sheet {0:MM-dd-yyyy HH.mm.ss tt}"
FileNameFormatValue="Date"
OutputFolder="pdfs"
OutputType="PortableDocFormat"
/>
</Report>
</Configuration>

It doesn't load, keeps giving me an error:

The element 'MCIS.Applications.Reports.Schema.Configuration:Configuration' has
invalid child element 'MCIS.Applications.Reports.Schema.Configuration:Report'.
Expected 'Report'. An error occurred at file:///C:/path/sample.xml, (4, 6).

Same things for ExportOptions and Report elements (the above message is repeated
a total of 3 times in the exception message).

The first part of the xsd file is:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="Configuration"
targetNamespace="MCIS.Applications.Reports.Schema.Configuration"
elementFormDefault="unqualified" attributeFormDefault="unqualified"
xmlns="MCIS.Applications.Reports.Schema.Configuration"
xmlns:mstns="MCIS.Applications.Reports.Schema.Configuration"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:msprop="urn:schemas-microsoft-com:xml-msprop">
<xs:annotation>
<xs:documentation>MCIS Automated Reports</xs:documentation>
</xs:annotation>
<xs:element name="Configuration" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Report" type="Report" />
</xs:choice>
</xs:complexType>
</xs:element>
<xs:simpleType name="ExportTypes" id="ExportTypes">
<xs:restriction base="xs:string">
<xs:enumeration value="NoFormat" />
<xs:enumeration value="CrystalReport" />
<xs:enumeration value="RichText" />
<xs:enumeration value="WordForWindows" />
<xs:enumeration value="Excel" />
<xs:enumeration value="PortableDocFormat" />
<xs:enumeration value="HTML32" />
<xs:enumeration value="HTML40" />
<xs:enumeration value="ExcelRecord" />
</xs:restriction>
</xs:simpleType>

Hope this helps shed some more light ;)

Mythran

Oleg Tkachenko [MVP]
7/15/2004 7:01:14 PM
[quoted text, click to view]

Oops I was wrong. elementFormDefault is only about locally defined
elements, while you are talking about root element.

[quoted text, click to view]

Basically there is no difference whether you are using prefixed
namespace or default namespace. Just make sure your schema defines
Configuration element in that namespace:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" xmlns:blah="Blah" targetNamespace="Blah">
<xs:element name="Configuration">
<xs:complexType>
<xs:sequence>
<xs:element name="foo" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

then both

<Configuration xmlns="Blah"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="Blah foo.xsd">
<foo/>
</Configuration>

and

<blah:Configuration xmlns:blah="Blah"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="Blah foo.xsd">
<blah:foo/>
</blah:Configuration>

are valid.

--
Oleg Tkachenko [XML MVP]
AddThis Social Bookmark Button