473,385 Members | 1,707 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,385 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 6994
"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: 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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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.