473,382 Members | 1,423 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,382 software developers and data experts.

XML Root Node

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
Nov 12 '05 #1
4 3756
Mythran wrote:
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.


Change your schema. Read about elementFormDefault attribute.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #2
Wish it were that simple. elementFormDefault attribute already set.

Mythran

"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:u$**************@TK2MSFTNGP10.phx.gbl...
Mythran wrote:
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.


Change your schema. Read about elementFormDefault attribute.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com

Nov 12 '05 #3
Mythran wrote:
Wish it were that simple. elementFormDefault attribute already set.


Oops I was wrong. elementFormDefault is only about locally defined
elements, while you are talking about root element.
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


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]
http://blog.tkachenko.com
Nov 12 '05 #4

"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:ed**************@TK2MSFTNGP11.phx.gbl...
Mythran wrote:
Wish it were that simple. elementFormDefault attribute already set.


Oops I was wrong. elementFormDefault is only about locally defined
elements, while you are talking about root element.
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


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.


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.Configurat ion">
<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:Co nfiguration' has
invalid child element 'MCIS.Applications.Reports.Schema.Configuration:Re port'.
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.Configurat ion"
xmlns:mstns="MCIS.Applications.Reports.Schema.Conf iguration"
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
Nov 12 '05 #5

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

Similar topics

1
by: Jay Sartoris | last post by:
Hi, I'm adding a node to my XML document using DOM. When I serialize it, I lose my comments that are above my root node. I've created an OutputFormat obect and set the setOmitComments(false)...
2
by: Scott Simpson | last post by:
Can you query from a non-root node using XPathAPI's function selectNodeList(Node contextNode, java.lang.String str)? I'm trying this using the XPath expression "//*" and I'm getting nothing back. I...
12
by: pillepop2003 | last post by:
Hey! Can anyone give me a hint, how this problem is best implemented: I have a table of users (see below), where every user has one "superior user" (= parent node), this should be a fully...
6
by: David B. Bitton | last post by:
I am having a problem deserializing XML when the root node is missing a namespace declaration. My Type has an XmlTypeAttribute with a namespace defined. If I attempt to deserialize the XML, I get...
16
by: Bob Rock | last post by:
Hello, when serializing an array of elements of a class Classname using XmlSerializer.Serialize() I get an XML like the following: <?xml version="1.0"> <ArrayOfClassname> ....... ..........
15
by: Stig Brautaset | last post by:
Hi group, I'm playing with a little generic linked list/stack library, and have a little problem with the interface of the pop() function. If I used a struct like this it would be simple: ...
0
by: Martin | last post by:
Hi, I am retriving data from sql server using the xml raw clause and an xmltextwriter. this is working out fine except the xml raw clause does not put a root node on the xml that is returned...
6
by: rlueneberg | last post by:
Can someone tell if Sitemap always require a starting root? Can it have more than one root? I am having a problem trying to hide a root node without hiding its children using a Treeview component....
0
by: Paulers | last post by:
Hello, I am trying to add sub items to a unique root node but it seems that it is duplicating the root node instead of placing subnode under it. Here is my code. Is ther anyone who can show me...
11
by: =?ISO-8859-1?Q?Une_B=E9v?==?ISO-8859-1?Q?ue?= | last post by:
at the page : <http://thoraval.yvon.free.fr/Fixed_layout/import_nodes.xhtml> when importing an svg document i have to do : document.importNode(...
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
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.