473,761 Members | 9,284 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating DTD using DOM

Hi,

I want to create a DTD in an XML file in memory. The XML file is created
using the DOM in C#. I am new to all this, but couldn't find anything
about creating DTD's using the DOM (well, I found some references but it
doesn't tell me how to do what I want).

Here's my code:

XmlDocument xdoc = new XmlDocument();
XmlElement root = xdoc.DocumentEl ement;
XmlDeclaration xdec = xdoc.CreateXmlD eclaration("1.0 ", "utf-8", null);
xdoc.InsertBefo re(xdec, root);
xdoc.AppendChil d(xdoc.CreateDo cumentType("Con fig", null, null,
"<!ELEMENT Config (Shows, Schedules)*>")) ;

The last line will add one DTD entry to my XML file, but I want several
more. Unfortunately, appending more DTD entries using AppendChild
doesn't work since the XML document can have only one document type node.

So this will result in an error:

xdoc.AppendChil d(xdoc.CreateDo cumentType("Sho ws", null, null, "<!ELEMENT
Shows (Show)*>"));
I want to create this DTD:

<!DOCTYPE Config [
<!ELEMENT Config (Shows, Schedules)*>

<!ELEMENT Shows (Show)*>
<!ELEMENT Show (title, url, livestream, savefolder, filename?, keepold)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT url (#PCDATA)>
<!ELEMENT livestream (#PCDATA)>
<!ELEMENT savefolder (#PCDATA)>
<!ELEMENT filename (#PCDATA)>
<!ELEMENT keepold (#PCDATA)>

<!ELEMENT Schedules (Schedule)*>
<!ELEMENT Schedule (whenchanged, ((start, stop) | interval | days |
monthday))>
<!ELEMENT whenchanged (#PCDATA)>
<!ELEMENT start (#PCDATA)>
<!ELEMENT stop (#PCDATA)>
<!ELEMENT interval (#PCDATA)>
<!ELEMENT days (#PCDATA)>
<!ELEMENT monthday (#PCDATA)>

<!ATTLIST Show id ID #REQUIRED>
<!ATTLIST Schedule id ID #REQUIRED>
<!ATTLIST Schedule showid REFID #REQUIRED>

So besides creating the elements, I also want to add attributes, but I
have no idea how to do that.

Another question: the ID field in the attribute list tells the XML
parser that the id attribute needs to be unique. Is there any way to get
a unique number automatically from the DOM? Or should I scan through the
id's and keep a list of used ids?
To summarize:

1. How to create multiple <!ELEMENT entries using DOM
2. How to create multiple <!ATTLIST entries where I can specify ID
#REQUIRED using DOM
3. How to get a unique ID from the DOM
Thank you for your time!
Michel Verhagen
May 22 '06 #1
4 1925
Hi Michel,

The problem is, DTD, unlike XSD, is not XML itself - hence you cannot create
it using the DOM API.
Yet, why would you stick to a DTD at all? Do you need compatibility with
some legacy code? Unless something is "holding you back", I'd recommend that
you use XSD instead.

"Michel Verhagen" <mv*******@nosp am.embeddedfusi on.com> wrote in message
news:OC******** ******@TK2MSFTN GP04.phx.gbl...
Hi,

I want to create a DTD in an XML file in memory. The XML file is created
using the DOM in C#. I am new to all this, but couldn't find anything
about creating DTD's using the DOM (well, I found some references but it
doesn't tell me how to do what I want).

Here's my code:

XmlDocument xdoc = new XmlDocument();
XmlElement root = xdoc.DocumentEl ement;
XmlDeclaration xdec = xdoc.CreateXmlD eclaration("1.0 ", "utf-8", null);
xdoc.InsertBefo re(xdec, root);
xdoc.AppendChil d(xdoc.CreateDo cumentType("Con fig", null, null, "<!ELEMENT
Config (Shows, Schedules)*>")) ;

The last line will add one DTD entry to my XML file, but I want several
more. Unfortunately, appending more DTD entries using AppendChild doesn't
work since the XML document can have only one document type node.

So this will result in an error:

xdoc.AppendChil d(xdoc.CreateDo cumentType("Sho ws", null, null, "<!ELEMENT
Shows (Show)*>"));
I want to create this DTD:

<!DOCTYPE Config [
<!ELEMENT Config (Shows, Schedules)*>

<!ELEMENT Shows (Show)*>
<!ELEMENT Show (title, url, livestream, savefolder, filename?, keepold)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT url (#PCDATA)>
<!ELEMENT livestream (#PCDATA)>
<!ELEMENT savefolder (#PCDATA)>
<!ELEMENT filename (#PCDATA)>
<!ELEMENT keepold (#PCDATA)>

<!ELEMENT Schedules (Schedule)*>
<!ELEMENT Schedule (whenchanged, ((start, stop) | interval | days |
monthday))>
<!ELEMENT whenchanged (#PCDATA)>
<!ELEMENT start (#PCDATA)>
<!ELEMENT stop (#PCDATA)>
<!ELEMENT interval (#PCDATA)>
<!ELEMENT days (#PCDATA)>
<!ELEMENT monthday (#PCDATA)>

<!ATTLIST Show id ID #REQUIRED>
<!ATTLIST Schedule id ID #REQUIRED>
<!ATTLIST Schedule showid REFID #REQUIRED>

So besides creating the elements, I also want to add attributes, but I
have no idea how to do that.

Another question: the ID field in the attribute list tells the XML parser
that the id attribute needs to be unique. Is there any way to get a unique
number automatically from the DOM? Or should I scan through the id's and
keep a list of used ids?
To summarize:

1. How to create multiple <!ELEMENT entries using DOM
2. How to create multiple <!ATTLIST entries where I can specify ID
#REQUIRED using DOM
3. How to get a unique ID from the DOM
Thank you for your time!
Michel Verhagen


May 23 '06 #2
Thank you for your reply Dmytro,

As I said, I'm a total newbie to XML stuff. I will look into XSD and see
how that works. Maybe you can give me some pointers or example on how to
do what I want?

Thanks!

Michel.

Dmytro Lapshyn [MVP] wrote:
Hi Michel,

The problem is, DTD, unlike XSD, is not XML itself - hence you cannot
create it using the DOM API.
Yet, why would you stick to a DTD at all? Do you need compatibility with
some legacy code? Unless something is "holding you back", I'd recommend
that you use XSD instead.

"Michel Verhagen" <mv*******@nosp am.embeddedfusi on.com> wrote in message
news:OC******** ******@TK2MSFTN GP04.phx.gbl...
Hi,

I want to create a DTD in an XML file in memory. The XML file is
created using the DOM in C#. I am new to all this, but couldn't find
anything about creating DTD's using the DOM (well, I found some
references but it doesn't tell me how to do what I want).

Here's my code:

XmlDocument xdoc = new XmlDocument();
XmlElement root = xdoc.DocumentEl ement;
XmlDeclaration xdec = xdoc.CreateXmlD eclaration("1.0 ", "utf-8", null);
xdoc.InsertBefo re(xdec, root);
xdoc.AppendChil d(xdoc.CreateDo cumentType("Con fig", null, null,
"<!ELEMENT Config (Shows, Schedules)*>")) ;

The last line will add one DTD entry to my XML file, but I want
several more. Unfortunately, appending more DTD entries using
AppendChild doesn't work since the XML document can have only one
document type node.

So this will result in an error:

xdoc.AppendChil d(xdoc.CreateDo cumentType("Sho ws", null, null,
"<!ELEMENT Shows (Show)*>"));
I want to create this DTD:

<!DOCTYPE Config [
<!ELEMENT Config (Shows, Schedules)*>

<!ELEMENT Shows (Show)*>
<!ELEMENT Show (title, url, livestream, savefolder, filename?, keepold)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT url (#PCDATA)>
<!ELEMENT livestream (#PCDATA)>
<!ELEMENT savefolder (#PCDATA)>
<!ELEMENT filename (#PCDATA)>
<!ELEMENT keepold (#PCDATA)>

<!ELEMENT Schedules (Schedule)*>
<!ELEMENT Schedule (whenchanged, ((start, stop) | interval | days |
monthday))>
<!ELEMENT whenchanged (#PCDATA)>
<!ELEMENT start (#PCDATA)>
<!ELEMENT stop (#PCDATA)>
<!ELEMENT interval (#PCDATA)>
<!ELEMENT days (#PCDATA)>
<!ELEMENT monthday (#PCDATA)>

<!ATTLIST Show id ID #REQUIRED>
<!ATTLIST Schedule id ID #REQUIRED>
<!ATTLIST Schedule showid REFID #REQUIRED>

So besides creating the elements, I also want to add attributes, but I
have no idea how to do that.

Another question: the ID field in the attribute list tells the XML
parser that the id attribute needs to be unique. Is there any way to
get a unique number automatically from the DOM? Or should I scan
through the id's and keep a list of used ids?
To summarize:

1. How to create multiple <!ELEMENT entries using DOM
2. How to create multiple <!ATTLIST entries where I can specify ID
#REQUIRED using DOM
3. How to get a unique ID from the DOM
Thank you for your time!
Michel Verhagen

May 23 '06 #3
Michel,

The direct answer to your question is here:

http://www.vijaymukhi.com/documents/books/xsd/chap7.htm

However, I'd also recommend that you read the following materials:

- An introduction to XSD schemas:
http://www.vijaymukhi.com/documents/books/xsd/chap2.htm
- System.Xml.Sche ma namespace docs in MSDN library.
- Formal XSD definition that can be found on w3.org:
http://www.w3.org/XML/Schema#dev

"Michel Verhagen (eMVP)" <mi************ *@nospam.embedd edfusion.com> wrote
in message news:OP******** ******@TK2MSFTN GP04.phx.gbl...
Thank you for your reply Dmytro,

As I said, I'm a total newbie to XML stuff. I will look into XSD and see
how that works. Maybe you can give me some pointers or example on how to
do what I want?

Thanks!

Michel.

Dmytro Lapshyn [MVP] wrote:
Hi Michel,

The problem is, DTD, unlike XSD, is not XML itself - hence you cannot
create it using the DOM API.
Yet, why would you stick to a DTD at all? Do you need compatibility with
some legacy code? Unless something is "holding you back", I'd recommend
that you use XSD instead.

"Michel Verhagen" <mv*******@nosp am.embeddedfusi on.com> wrote in message
news:OC******** ******@TK2MSFTN GP04.phx.gbl...
Hi,

I want to create a DTD in an XML file in memory. The XML file is created
using the DOM in C#. I am new to all this, but couldn't find anything
about creating DTD's using the DOM (well, I found some references but it
doesn't tell me how to do what I want).

Here's my code:

XmlDocument xdoc = new XmlDocument();
XmlElement root = xdoc.DocumentEl ement;
XmlDeclaration xdec = xdoc.CreateXmlD eclaration("1.0 ", "utf-8", null);
xdoc.InsertBefo re(xdec, root);
xdoc.AppendChil d(xdoc.CreateDo cumentType("Con fig", null, null,
"<!ELEMENT Config (Shows, Schedules)*>")) ;

The last line will add one DTD entry to my XML file, but I want several
more. Unfortunately, appending more DTD entries using AppendChild
doesn't work since the XML document can have only one document type
node.

So this will result in an error:

xdoc.AppendChil d(xdoc.CreateDo cumentType("Sho ws", null, null, "<!ELEMENT
Shows (Show)*>"));
I want to create this DTD:

<!DOCTYPE Config [
<!ELEMENT Config (Shows, Schedules)*>

<!ELEMENT Shows (Show)*>
<!ELEMENT Show (title, url, livestream, savefolder, filename?, keepold)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT url (#PCDATA)>
<!ELEMENT livestream (#PCDATA)>
<!ELEMENT savefolder (#PCDATA)>
<!ELEMENT filename (#PCDATA)>
<!ELEMENT keepold (#PCDATA)>

<!ELEMENT Schedules (Schedule)*>
<!ELEMENT Schedule (whenchanged, ((start, stop) | interval | days |
monthday))>
<!ELEMENT whenchanged (#PCDATA)>
<!ELEMENT start (#PCDATA)>
<!ELEMENT stop (#PCDATA)>
<!ELEMENT interval (#PCDATA)>
<!ELEMENT days (#PCDATA)>
<!ELEMENT monthday (#PCDATA)>

<!ATTLIST Show id ID #REQUIRED>
<!ATTLIST Schedule id ID #REQUIRED>
<!ATTLIST Schedule showid REFID #REQUIRED>

So besides creating the elements, I also want to add attributes, but I
have no idea how to do that.

Another question: the ID field in the attribute list tells the XML
parser that the id attribute needs to be unique. Is there any way to get
a unique number automatically from the DOM? Or should I scan through the
id's and keep a list of used ids?
To summarize:

1. How to create multiple <!ELEMENT entries using DOM
2. How to create multiple <!ATTLIST entries where I can specify ID
#REQUIRED using DOM
3. How to get a unique ID from the DOM
Thank you for your time!
Michel Verhagen


May 24 '06 #4
Thank you very much, you've been very helpful!

Regards,

Michel.

Dmytro Lapshyn [MVP] wrote:
Michel,

The direct answer to your question is here:

http://www.vijaymukhi.com/documents/books/xsd/chap7.htm

However, I'd also recommend that you read the following materials:

- An introduction to XSD schemas:
http://www.vijaymukhi.com/documents/books/xsd/chap2.htm
- System.Xml.Sche ma namespace docs in MSDN library.
- Formal XSD definition that can be found on w3.org:
http://www.w3.org/XML/Schema#dev

"Michel Verhagen (eMVP)" <mi************ *@nospam.embedd edfusion.com>
wrote in message news:OP******** ******@TK2MSFTN GP04.phx.gbl...
Thank you for your reply Dmytro,

As I said, I'm a total newbie to XML stuff. I will look into XSD and
see how that works. Maybe you can give me some pointers or example on
how to do what I want?

Thanks!

Michel.

Dmytro Lapshyn [MVP] wrote:
Hi Michel,

The problem is, DTD, unlike XSD, is not XML itself - hence you cannot
create it using the DOM API.
Yet, why would you stick to a DTD at all? Do you need compatibility
with some legacy code? Unless something is "holding you back", I'd
recommend that you use XSD instead.

"Michel Verhagen" <mv*******@nosp am.embeddedfusi on.com> wrote in
message news:OC******** ******@TK2MSFTN GP04.phx.gbl...
Hi,

I want to create a DTD in an XML file in memory. The XML file is
created using the DOM in C#. I am new to all this, but couldn't find
anything about creating DTD's using the DOM (well, I found some
references but it doesn't tell me how to do what I want).

Here's my code:

XmlDocument xdoc = new XmlDocument();
XmlElement root = xdoc.DocumentEl ement;
XmlDeclaration xdec = xdoc.CreateXmlD eclaration("1.0 ", "utf-8", null);
xdoc.InsertBefo re(xdec, root);
xdoc.AppendChil d(xdoc.CreateDo cumentType("Con fig", null, null,
"<!ELEMENT Config (Shows, Schedules)*>")) ;

The last line will add one DTD entry to my XML file, but I want
several more. Unfortunately, appending more DTD entries using
AppendChild doesn't work since the XML document can have only one
document type node.

So this will result in an error:

xdoc.AppendChil d(xdoc.CreateDo cumentType("Sho ws", null, null,
"<!ELEMENT Shows (Show)*>"));
I want to create this DTD:

<!DOCTYPE Config [
<!ELEMENT Config (Shows, Schedules)*>

<!ELEMENT Shows (Show)*>
<!ELEMENT Show (title, url, livestream, savefolder, filename?,
keepold)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT url (#PCDATA)>
<!ELEMENT livestream (#PCDATA)>
<!ELEMENT savefolder (#PCDATA)>
<!ELEMENT filename (#PCDATA)>
<!ELEMENT keepold (#PCDATA)>

<!ELEMENT Schedules (Schedule)*>
<!ELEMENT Schedule (whenchanged, ((start, stop) | interval | days |
monthday))>
<!ELEMENT whenchanged (#PCDATA)>
<!ELEMENT start (#PCDATA)>
<!ELEMENT stop (#PCDATA)>
<!ELEMENT interval (#PCDATA)>
<!ELEMENT days (#PCDATA)>
<!ELEMENT monthday (#PCDATA)>

<!ATTLIST Show id ID #REQUIRED>
<!ATTLIST Schedule id ID #REQUIRED>
<!ATTLIST Schedule showid REFID #REQUIRED>

So besides creating the elements, I also want to add attributes, but
I have no idea how to do that.

Another question: the ID field in the attribute list tells the XML
parser that the id attribute needs to be unique. Is there any way to
get a unique number automatically from the DOM? Or should I scan
through the id's and keep a list of used ids?
To summarize:

1. How to create multiple <!ELEMENT entries using DOM
2. How to create multiple <!ATTLIST entries where I can specify ID
#REQUIRED using DOM
3. How to get a unique ID from the DOM
Thank you for your time!
Michel Verhagen


--
Michel Verhagen, eMVP
Embedded Fusion
www.embeddedfusion.com
mverhagen at embeddedfusion dot com
May 24 '06 #5

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

Similar topics

0
1759
by: Robert | last post by:
I get these errors when creating a asp .net web application project in VS 2003 on a remote web server: "Microsoft Development Environment The Web was created successfully, but an error occurred when trying to configure the application root for this Web. Web projects may not operate correctly without an application root. The returned error was: Active Directory Services cannot find the web server. A possible cause for this is an...
4
561
by: Altramagnus | last post by:
I have 30 - 40 type of different window. For each type I need about 20 instances of the window. When I try to create them, I get "Error creating window handle" My guess is there is a maximum number of window handle, because if I reduce to about 2 instances of each window, it can run. But not 20 instances of each window. Does anyone know what the problem is? is it really because it exceeds the maximum number of window handle?
8
5968
by: Nanda | last post by:
hi, I am trying to generate parameters for the updatecommand at runtime. this.oleDbDeleteCommand1.CommandText=cmdtext; this.oleDbDeleteCommand1.Connection =this.oleDbConnection1; this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_ApplicantName", dataset.Tables.Columns.DataType, 50,
15
6750
by: Carlos Lozano | last post by:
Hi, What is the right way to create an OCX COM component. The component is already registerred, but can't create an instance. I am using the reference to the interop module created. If I use javascript or vbscript it works. I will appreciate any help. I do the following (C#):
3
1870
by: Ken Varn | last post by:
I am just starting the process of creating ASP.NET server controls. I have created controls for .NET applications, but have just started with ASP.NET. I am a little confused about some areas that I am hoping someone can help clear up. 1. What is the difference between initializing a control in the constructor, vs the OnInit(), vs the CreateChildControls() methods? 2. The control that I created contains an Items collection attribute...
15
2835
by: David Thielen | last post by:
Hi; My ASP.NET app (C# calling J# under .net 2.0) creates a png file in a subdirectory to display as part of the created page. However, the bitmap will not display due to a security violation. Everything is the default settings I believe. IIS is running under Local System. In IIS the DefaultAppPool is running under Network Service. Annonymous access uses the account IUSR_JASMINE (machine name is Jasmine).
17
1948
by: Lee Harr | last post by:
I understand how to create a property like this: class RC(object): def _set_pwm(self, v): self._pwm01 = v % 256 def _get_pwm(self): return self._pwm01 pwm01 = property(_get_pwm, _set_pwm)
11
3730
by: Matthew Wells | last post by:
Hello. I have figured out how to create an instance of an object only knowing the type by string. string sName = "MyClassName"; Type t = Type.GetType(sName); Object objNew = Activator.CreateInstance(t); This works, but now I need to declare an array like
9
2985
by: =?Utf-8?B?YmJn?= | last post by:
Hi all, I read somewhere "using kernel stuff in thread is not good.." if ManualResetEvent object is created in thread but not actually used, will it affect performance? Bob
0
10136
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9988
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9923
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8813
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5266
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3911
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.