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

new xml file is larger than the original

i'm working on a windows application that will edit and create xml files from
another application. the original file is 83k, the one created by my vb.net
program is 153k but all i add is a new xmlelement when i use the other
program and add a xmlelement is only increased the file to 85k. how come my
application increased 70k in size and also added the <?xml version="1.0"?>
when i didn't tell it to.

how do i duplicated a xml file and only add the xml element that i want to
insert. where did the extra 70k come from.

thanks

here is my code:

Dim newEvtEnrollElem As XmlElement = Nothing
Dim str1, str2 As String

str1 = strPath.Substring(0, strPath.LastIndexOf("."))
str2 = str1.ToString.Remove(0, 42)

newEvtEnrollElem =
CType(xDoc.SelectSingleNode("AutomationControl/EventEnrollments"), XmlElement)

str1 = strPath.Substring(0, strPath.LastIndexOf("."))
str2 = str1.ToString.Remove(0, 42)

If newEvtEnrollElem IsNot Nothing Then

Dim EvtEnrollElem As XmlElement =
xDoc.CreateElement("EventEnrollment")
Dim EvtEnrollAttr As XmlAttribute =
xDoc.CreateAttribute("InstanceNumber")

EvtEnrollAttr.Value = "3744"
EvtEnrollElem.Attributes.Append(EvtEnrollAttr)

EvtEnrollElem.InnerXml =
"<BackwardReferences/><EventEnrollmentProperties><EnabledReference/><EventParameters><SetpointReference/></EventParameters><EventSources/></EventEnrollmentProperties><GeneralProperties><Desc ription/></GeneralProperties>"

Dim EvtEnrollProp_AckRequiredAttrNode As XmlAttribute =
xDoc.CreateAttribute("AckRequired")
EvtEnrollProp_AckRequiredAttrNode.Value = "0"
Dim EvtEnrollProp_EvtEnabledAttrNode As XmlAttribute =
xDoc.CreateAttribute("EventEnable")
EvtEnrollProp_EvtEnabledAttrNode.Value = "0"
Dim EvtEnrollProp_EvtTypeAttrNode As XmlAttribute =
xDoc.CreateAttribute("EventType")
EvtEnrollProp_EvtTypeAttrNode.Value = "0"
Dim EvtEnrollProp_NotifyClassAttrNode As XmlAttribute =
xDoc.CreateAttribute("NotifyClass")
EvtEnrollProp_NotifyClassAttrNode.Value = "0"
Dim EvtEnrollProp_NotifyTypeAttrNode As XmlAttribute =
xDoc.CreateAttribute("NotifyType")
EvtEnrollProp_NotifyTypeAttrNode.Value = "0"
Dim EvtEnrollProp_PresentValueAttrNode As XmlAttribute =
xDoc.CreateAttribute("PresentValue")
EvtEnrollProp_PresentValueAttrNode.Value = "0"
Dim EvtEnrollProp_ToFaultTextAttrNode As XmlAttribute =
xDoc.CreateAttribute("ToFaultText")
EvtEnrollProp_ToFaultTextAttrNode.Value = ""
Dim EvtEnrollProp_ToNormalTextAttrNode As XmlAttribute =
xDoc.CreateAttribute("ToNormalText")
EvtEnrollProp_ToNormalTextAttrNode.Value = ""
Dim EvtEnrollProp_ToOffNormalTextAttrNode As XmlAttribute =
xDoc.CreateAttribute("ToOffNormalText")
EvtEnrollProp_ToOffNormalTextAttrNode.Value = ""
EvtEnrollElem.Item("EventEnrollmentProperties").Se tAttributeNode(EvtEnrollProp_AckRequiredAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").Se tAttributeNode(EvtEnrollProp_EvtEnabledAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").Se tAttributeNode(EvtEnrollProp_EvtTypeAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").Se tAttributeNode(EvtEnrollProp_NotifyClassAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").Se tAttributeNode(EvtEnrollProp_NotifyTypeAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").Se tAttributeNode(EvtEnrollProp_PresentValueAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").Se tAttributeNode(EvtEnrollProp_ToFaultTextAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").Se tAttributeNode(EvtEnrollProp_ToNormalTextAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").Se tAttributeNode(EvtEnrollProp_ToOffNormalTextAttrNo de)

Dim EnRef_ObjKeyAttrNode As XmlAttribute =
xDoc.CreateAttribute("ObjectKey")
EnRef_ObjKeyAttrNode.Value = ""
Dim EnRef_PropName As XmlAttribute =
xDoc.CreateAttribute("PropertyName")
EnRef_PropName.Value = ""
EvtEnrollElem.Item("EventEnrollmentProperties").It em("EnabledReference").SetAttributeNode(EnRef_ObjK eyAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").It em("EnabledReference").SetAttributeNode(EnRef_Prop Name)

Dim EvtPara_BitMaskAttrNode As XmlAttribute =
xDoc.CreateAttribute("BitMask")
EvtPara_BitMaskAttrNode.Value = "0"
Dim EvtPara_DeadbandAttrNode As XmlAttribute =
xDoc.CreateAttribute("Deadband")
EvtPara_DeadbandAttrNode.Value = ""
Dim EvtPara_HighDiffLimitAttrNode As XmlAttribute =
xDoc.CreateAttribute("HighDiffLimit")
EvtPara_HighDiffLimitAttrNode.Value = ""
Dim EvtPara_HighLimitAttrNode As XmlAttribute =
xDoc.CreateAttribute("HighLimit")
EvtPara_HighLimitAttrNode.Value = ""
Dim EvtPara_ListOfBitStringValuesAttrNode As XmlAttribute =
xDoc.CreateAttribute("ListOfBitStringValues")
EvtPara_ListOfBitStringValuesAttrNode.Value = ""
Dim EvtPara_ListOfValuesAttrNode As XmlAttribute =
xDoc.CreateAttribute("ListOfValues")
EvtPara_ListOfValuesAttrNode.Value = ""
Dim EvtPara_LowDiffLimitAttrNode As XmlAttribute =
xDoc.CreateAttribute("LowDiffLimit")
EvtPara_LowDiffLimitAttrNode.Value = ""
Dim EvtPara_LowLimitAttrNode As XmlAttribute =
xDoc.CreateAttribute("LowLimit")
EvtPara_LowLimitAttrNode.Value = ""
Dim EvtPara_RefPropIncrAttrNode As XmlAttribute =
xDoc.CreateAttribute("ReferencedPropertyIncrement" )
EvtPara_RefPropIncrAttrNode.Value = "1"
Dim EvtPara_TimeDelayAttrNode As XmlAttribute =
xDoc.CreateAttribute("TimeDelay")
EvtPara_TimeDelayAttrNode.Value = "60"
Dim EvtPara_TimeIntervalAttrNode As XmlAttribute =
xDoc.CreateAttribute("TimeInterval")
EvtPara_TimeIntervalAttrNode.Value = "1"
EvtEnrollElem.Item("EventEnrollmentProperties").It em("EventParameters").SetAttributeNode(EvtPara_Bit MaskAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").It em("EventParameters").SetAttributeNode(EvtPara_Dea dbandAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").It em("EventParameters").SetAttributeNode(EvtPara_Hig hDiffLimitAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").It em("EventParameters").SetAttributeNode(EvtPara_Hig hLimitAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").It em("EventParameters").SetAttributeNode(EvtPara_Lis tOfBitStringValuesAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").It em("EventParameters").SetAttributeNode(EvtPara_Lis tOfValuesAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").It em("EventParameters").SetAttributeNode(EvtPara_Low DiffLimitAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").It em("EventParameters").SetAttributeNode(EvtPara_Low LimitAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").It em("EventParameters").SetAttributeNode(EvtPara_Ref PropIncrAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").It em("EventParameters").SetAttributeNode(EvtPara_Tim eDelayAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").It em("EventParameters").SetAttributeNode(EvtPara_Tim eIntervalAttrNode)

Dim SetPointRef_ObjKeyAttrNode As XmlAttribute =
xDoc.CreateAttribute("ObjectKey")
SetPointRef_ObjKeyAttrNode.Value = ""
Dim SetPointRef_PropNameAttrNode As XmlAttribute =
xDoc.CreateAttribute("PropertyName")
SetPointRef_PropNameAttrNode.Value = ""
EvtEnrollElem.Item("EventEnrollmentProperties").It em("EventParameters").Item("SetpointReference").Se tAttributeNode(SetPointRef_ObjKeyAttrNode)

EvtEnrollElem.Item("EventEnrollmentProperties").It em("EventParameters").Item("SetpointReference").Se tAttributeNode(SetPointRef_PropNameAttrNode)

Dim GP_AttrNode As XmlAttribute = xDoc.CreateAttribute("Attr")
GP_AttrNode.Value = "0"
Dim GP_InstNumAttrNode As XmlAttribute =
xDoc.CreateAttribute("InstanceNumber")
GP_InstNumAttrNode.Value = "3744"
Dim GP_IsConfigAttrNode As XmlAttribute =
xDoc.CreateAttribute("IsConfigured")
GP_IsConfigAttrNode.Value = "0"
Dim GP_ObjNameAttrNode As XmlAttribute =
xDoc.CreateAttribute("ObjectName")
GP_ObjNameAttrNode.Value = "EventEnrollment"
Dim GP_ObjTypeAttrNode As XmlAttribute =
xDoc.CreateAttribute("ObjectType")
GP_ObjTypeAttrNode.Value = "9"
Dim GP_SchemaVerAttrNode As XmlAttribute =
xDoc.CreateAttribute("SchemaVer")
GP_SchemaVerAttrNode.Value = "1.4"
Dim GP_TraceOptionsAttrNode As XmlAttribute =
xDoc.CreateAttribute("TraceOptions")
GP_TraceOptionsAttrNode.Value = "0"
EvtEnrollElem.Item("GeneralProperties").SetAttribu teNode(GP_AttrNode)

EvtEnrollElem.Item("GeneralProperties").SetAttribu teNode(GP_InstNumAttrNode)

EvtEnrollElem.Item("GeneralProperties").SetAttribu teNode(GP_IsConfigAttrNode)

EvtEnrollElem.Item("GeneralProperties").SetAttribu teNode(GP_ObjNameAttrNode)

EvtEnrollElem.Item("GeneralProperties").SetAttribu teNode(GP_ObjTypeAttrNode)

EvtEnrollElem.Item("GeneralProperties").SetAttribu teNode(GP_SchemaVerAttrNode)

EvtEnrollElem.Item("GeneralProperties").SetAttribu teNode(GP_TraceOptionsAttrNode)

newEvtEnrollElem.AppendChild(EvtEnrollElem)

End If

Dim wrtr As XmlTextWriter = New XmlTextWriter("C:\" + str2 + ".xml",
Encoding.Unicode)

xDoc.WriteTo(wrtr)
wrtr.Close()
MessageBox.Show("Added new eventenrollment element")
Jun 27 '06 #1
2 1095
dotnetnoob wrote:
i'm working on a windows application that will edit and create xml files from
another application. the original file is 83k, the one created by my vb.net
program is 153k but all i add is a new xmlelement when i use the other
program and add a xmlelement is only increased the file to 85k. how come my
application increased 70k in size and also added the <?xml version="1.0"?>
when i didn't tell it to. Dim wrtr As XmlTextWriter = New XmlTextWriter("C:\" + str2 + ".xml",
Encoding.Unicode)


You are saving your XML as Unicode aka UTF-16, which takes 2 bytes per
character. Use UTF-8, which takes 1 byte per ASCII character and 2 (or
more) bytes for others.

--
Oleg Tkachenko [XML MVP, MCPD]
http://blog.tkachenko.com | http://www.XmlLab.Net | http://www.XLinq.Net
Jun 29 '06 #2
Thank. i get rid of using Xmltextwriter to save/dup xml file and just use
xmldocument(DOM) to save the file.

"Oleg Tkachenko [MVP]" wrote:
dotnetnoob wrote:
i'm working on a windows application that will edit and create xml files from
another application. the original file is 83k, the one created by my vb.net
program is 153k but all i add is a new xmlelement when i use the other
program and add a xmlelement is only increased the file to 85k. how come my
application increased 70k in size and also added the <?xml version="1.0"?>
when i didn't tell it to.

Dim wrtr As XmlTextWriter = New XmlTextWriter("C:\" + str2 + ".xml",
Encoding.Unicode)


You are saving your XML as Unicode aka UTF-16, which takes 2 bytes per
character. Use UTF-8, which takes 1 byte per ASCII character and 2 (or
more) bytes for others.

--
Oleg Tkachenko [XML MVP, MCPD]
http://blog.tkachenko.com | http://www.XmlLab.Net | http://www.XLinq.Net

Jun 30 '06 #3

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

Similar topics

7
by: Patrick Useldinger | last post by:
Hi, I think I found a bug in the write method of file objects. It seems as if before writing each block, a check was done in order to verifiy that there is enough space left for the *whole*...
4
by: Joe | last post by:
Hello, I have IIS 6.0 running on w2k3 Enterprise. I have three upload forms 1 to have restricted uploads .asp 2 to upload plain .asp any extension 3 a FP form upload non .asp
2
by: zambak | last post by:
Hi I have decompression function which opens compressed input file, grabs the header containing the original file size and the date compressed and starts decompressing data into output file.......
6
by: allanc | last post by:
i tried using a borderless form + picturebox, which works fine for dimensions smaller than the actual screen dimensions, but for larger sizes the window seems to clip. programs like acdsee seem...
3
by: Goncalo | last post by:
Hi. You can limit the uploaded file size by changing the httpRuntime's maxRequestLength in web.config, right? So, my question is, how can you tell in CodeBehind that the file 'uploaded' is...
8
by: Vijay | last post by:
Hi , I am doing a small project in c. I have a Hexadecimal file and want to convert into ascii value. (i.e., Hexadecimal to Ascii conversion from a file). Could anyone help me? Thanks in...
2
by: Chris Gilpin | last post by:
Hey everybody. While running a Query, Access crashed (The 'Send Error Report' window came up) I clicked the option to have access repair and reopen my database. Now in the database folder, I...
3
by: TonyJ | last post by:
Hello! I supposed to modify some text files. In the file(s) which consist of different section. In one section you might have Path = <Installation_path>. The program will then replace the text...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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...
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...

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.