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.DocumentElement;
XmlDeclaration xdec = xdoc.CreateXmlDeclaration("1.0", "utf-8", null);
xdoc.InsertBefore(xdec, root);
xdoc.AppendChild(xdoc.CreateDocumentType("Config", 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.AppendChild(xdoc.CreateDocumentType("Shows", 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 4 1879
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*******@nospam.embeddedfusion.com> wrote in message
news:OC**************@TK2MSFTNGP04.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.DocumentElement; XmlDeclaration xdec = xdoc.CreateXmlDeclaration("1.0", "utf-8", null); xdoc.InsertBefore(xdec, root); xdoc.AppendChild(xdoc.CreateDocumentType("Config", 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.AppendChild(xdoc.CreateDocumentType("Shows", 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
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*******@nospam.embeddedfusion.com> wrote in message news:OC**************@TK2MSFTNGP04.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.DocumentElement; XmlDeclaration xdec = xdoc.CreateXmlDeclaration("1.0", "utf-8", null); xdoc.InsertBefore(xdec, root); xdoc.AppendChild(xdoc.CreateDocumentType("Config", 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.AppendChild(xdoc.CreateDocumentType("Shows", 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,
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.Schema 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.embeddedfusion.com> wrote
in message news:OP**************@TK2MSFTNGP04.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*******@nospam.embeddedfusion.com> wrote in message news:OC**************@TK2MSFTNGP04.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.DocumentElement; XmlDeclaration xdec = xdoc.CreateXmlDeclaration("1.0", "utf-8", null); xdoc.InsertBefore(xdec, root); xdoc.AppendChild(xdoc.CreateDocumentType("Config", 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.AppendChild(xdoc.CreateDocumentType("Shows", 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
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.Schema 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.embeddedfusion.com> wrote in message news:OP**************@TK2MSFTNGP04.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*******@nospam.embeddedfusion.com> wrote in message news:OC**************@TK2MSFTNGP04.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.DocumentElement; XmlDeclaration xdec = xdoc.CreateXmlDeclaration("1.0", "utf-8", null); xdoc.InsertBefore(xdec, root); xdoc.AppendChild(xdoc.CreateDocumentType("Config", 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.AppendChild(xdoc.CreateDocumentType("Shows", 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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;...
|
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...
|
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...
|
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.
...
|
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)
|
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 =...
|
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
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
| |