473,399 Members | 3,302 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,399 software developers and data experts.

how to add or remove entity to a xml file

could someone tell me how to add or remove entity to a xml file

when i dim xmlentity as new xmlentity
it's say it's sube new is private

thks
Nov 12 '05 #1
4 6995
"terry" <te***@discussions.microsoft.com> wrote in message news:DA**********************************@microsof t.com...
could someone tell me how to add or remove entity to a xml file


XmlEntity can't be directly instantiated, you have to work through the InternalSubset
of the DTD (as represented by the XmlDocumentType class). When you specify
the InternalSubset for an XmlDocumentType object that you can create through
an XmlDocument's CreateDocumentType( ) method, .NET will parse the Entities
and build a collection of XmlEntity objects for you.

Given the following XML document,

- - - book.xml
<!DOCTYPE book [<!ENTITY h 'hardcover'>]>
<book genre='technology' ISBN='0-764548-26-3'>
<title>Visual Basic .NET Bible</title>
<style>&h;</style>
</book>
- - -

You might load it with the following VB.NET code,

Dim xmlDoc As New XmlDocument( )
xmlDoc.Load( "book.xml")
Then you'd create a pair of XmlDocumentType objects,

Dim oldDTD As XmlDocumentType = xmlDoc.DocumentType
Dim newDTD As XmlDocumentType

newDTD = xmlDoc.CreateDocumentType( _
oldDTD.Name, _
oldDTD.PublicId,_
oldDTD.SystemId, _
"<!ENTITY h 'softcover'>" _
)
Notice that I've used the CreateDocumentType( ) method of the XmlDocument
to create the new DTD. I copy it's primary characteristics (name, public and
system identifiers) from whatever the old DTD contained, and then I supply the
text of the internal subset I wish the DTD to use (it's left as an exercise for the
reader to enumerate Entities and Notations of the existing DTD to be maintained;
Hint: you can start by using the XmlDocumentType's InternalSubset string property
as the basis for keeping/revising tracts of text). In the replacement entity here,
I've redefined &h; to refer to the literal text, "softcover," instead of "hardcover."

Now, an XmlDocument can only have one XmlDocumentType. So to apply this
XmlDocumentType, and it's newly created Entities, I must replace the existing
XmlDocumentType node like so,

xmlDoc.ReplaceChild( newDTD, oldDTD)
If I now examine the contents of the DTD on the XmlDocument, I can see the
changes have taken effect.

Console.WriteLine( xmlDoc.DocumentType.OuterXml)
Finally, the XmlEntity that you wanted to create (to recap, it was the following
text I passed to the internalSubset argument of CreateDocumentType( )):

<!ENTITY h 'softcover'>
has been created for you in the Entitites collection of xmlDoc.DocumentType.
It can be examined like this:

Dim entity As XmlEntity = CType( xmlDoc.DocumentType.Entities, GetType( XmlEntity))
Console.Write( "{0} ", entity.NodeType)
Console.Write( "{0} ", entity.Name)
Console.Write( "{0} ", entity.NotationName)
Console.Write( "{0} ", entity.PublicId)
Console.Write( "{0} ", entity.SystemId)
Console.Write( "{0} ", entity.InnerText)
Derek Harmon
Nov 12 '05 #2
"terry" <te***@discussions.microsoft.com> wrote in message news:DA**********************************@microsof t.com...
could someone tell me how to add or remove entity to a xml file


XmlEntity can't be directly instantiated, you have to work through the InternalSubset
of the DTD (as represented by the XmlDocumentType class). When you specify
the InternalSubset for an XmlDocumentType object that you can create through
an XmlDocument's CreateDocumentType( ) method, .NET will parse the Entities
and build a collection of XmlEntity objects for you.

Given the following XML document,

- - - book.xml
<!DOCTYPE book [<!ENTITY h 'hardcover'>]>
<book genre='technology' ISBN='0-764548-26-3'>
<title>Visual Basic .NET Bible</title>
<style>&h;</style>
</book>
- - -

You might load it with the following VB.NET code,

Dim xmlDoc As New XmlDocument( )
xmlDoc.Load( "book.xml")
Then you'd create a pair of XmlDocumentType objects,

Dim oldDTD As XmlDocumentType = xmlDoc.DocumentType
Dim newDTD As XmlDocumentType

newDTD = xmlDoc.CreateDocumentType( _
oldDTD.Name, _
oldDTD.PublicId,_
oldDTD.SystemId, _
"<!ENTITY h 'softcover'>" _
)
Notice that I've used the CreateDocumentType( ) method of the XmlDocument
to create the new DTD. I copy it's primary characteristics (name, public and
system identifiers) from whatever the old DTD contained, and then I supply the
text of the internal subset I wish the DTD to use (it's left as an exercise for the
reader to enumerate Entities and Notations of the existing DTD to be maintained;
Hint: you can start by using the XmlDocumentType's InternalSubset string property
as the basis for keeping/revising tracts of text). In the replacement entity here,
I've redefined &h; to refer to the literal text, "softcover," instead of "hardcover."

Now, an XmlDocument can only have one XmlDocumentType. So to apply this
XmlDocumentType, and it's newly created Entities, I must replace the existing
XmlDocumentType node like so,

xmlDoc.ReplaceChild( newDTD, oldDTD)
If I now examine the contents of the DTD on the XmlDocument, I can see the
changes have taken effect.

Console.WriteLine( xmlDoc.DocumentType.OuterXml)
Finally, the XmlEntity that you wanted to create (to recap, it was the following
text I passed to the internalSubset argument of CreateDocumentType( )):

<!ENTITY h 'softcover'>
has been created for you in the Entitites collection of xmlDoc.DocumentType.
It can be examined like this:

Dim entity As XmlEntity = CType( xmlDoc.DocumentType.Entities, GetType( XmlEntity))
Console.Write( "{0} ", entity.NodeType)
Console.Write( "{0} ", entity.Name)
Console.Write( "{0} ", entity.NotationName)
Console.Write( "{0} ", entity.PublicId)
Console.Write( "{0} ", entity.SystemId)
Console.Write( "{0} ", entity.InnerText)
Derek Harmon
Nov 12 '05 #3

"Derek Harmon" <lo*******@msn.com> wrote in message news:#y**************@tk2msftngp13.phx.gbl...
Dim entity As XmlEntity = CType( xmlDoc.DocumentType.Entities, GetType( XmlEntity))


Gnit. :-) This line should read,

Dim entity As XmlEntity = CType( _
xmlDoc.DocumentType.Entities.Item( 0), _
GetType( XmlEntity) _
)

The type cast was meant on the XmlNode returned from the
XmlNamedNodeMap, not the XmlNamedNodeMap itself. :-/
Derek Harmon
Nov 12 '05 #4

"Derek Harmon" <lo*******@msn.com> wrote in message news:#y**************@tk2msftngp13.phx.gbl...
Dim entity As XmlEntity = CType( xmlDoc.DocumentType.Entities, GetType( XmlEntity))


Gnit. :-) This line should read,

Dim entity As XmlEntity = CType( _
xmlDoc.DocumentType.Entities.Item( 0), _
GetType( XmlEntity) _
)

The type cast was meant on the XmlNode returned from the
XmlNamedNodeMap, not the XmlNamedNodeMap itself. :-/
Derek Harmon
Nov 12 '05 #5

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

Similar topics

6
by: Vincent Lefevre | last post by:
I would like to know if the base URI considered to resolve an unparsed entity defined by a relative URI should be the URI before or after its rewriting due to a possible catalog. Let's take an...
2
by: Ed Dennison | last post by:
I'm starting to look at DocBook-XML (not SGML) for producing a large documentation set. The hierarchy of DocBook elements for organizing the content is (more or less); set book part chapter...
11
by: Douglas Reith | last post by:
Hi There, Can someone please tell me why the XML spec states that an attribute value with an external entity is forbidden? Or point me to the appropriate document? Or better still, perhaps you...
6
by: Thomas Sommer | last post by:
Hi, I know doing something like this <!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" > <section><title/>...
12
by: Oberon | last post by:
I have a large HTML document. It has hundreds of <span>s which have no attributes so these <span>s are redundant. How can I remove these tags automatically? The document also has <span>s with...
0
by: terry | last post by:
could someone tell me how to add or remove entity to a xml file when i dim xmlentity as new xmlentity it's say it's sube new is private thks
3
by: bgeci | last post by:
I have problem with Entity definition. ____________________________________________ my file "test.xml" ---- <?xml version="1.0" ?> <!DOCTYPE message > <message>&Ep;</message> ---- IE6 Error...
0
by: punjabinezzie | last post by:
I am developing an Application which currently has two XML files. One XML file with some nodes and an external entity reference to another XML file. The source XML file is being parsed using Xerces...
1
by: markla | last post by:
Hi, I have an Entity data model built in Entity Framework, which sources data primarily from an MS SQL 2008 database, and sources some static (data dictionary) values from code-based objects. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.