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><Description/></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").SetAttributeNode(EvtEnrollProp_AckRequiredAttrNode)
            
EvtEnrollElem.Item("EventEnrollmentProperties").SetAttributeNode(EvtEnrollProp_EvtEnabledAttrNode)
            
EvtEnrollElem.Item("EventEnrollmentProperties").SetAttributeNode(EvtEnrollProp_EvtTypeAttrNode)
            
EvtEnrollElem.Item("EventEnrollmentProperties").SetAttributeNode(EvtEnrollProp_NotifyClassAttrNode)
            
EvtEnrollElem.Item("EventEnrollmentProperties").SetAttributeNode(EvtEnrollProp_NotifyTypeAttrNode)
            
EvtEnrollElem.Item("EventEnrollmentProperties").SetAttributeNode(EvtEnrollProp_PresentValueAttrNode)
            
EvtEnrollElem.Item("EventEnrollmentProperties").SetAttributeNode(EvtEnrollProp_ToFaultTextAttrNode)
            
EvtEnrollElem.Item("EventEnrollmentProperties").SetAttributeNode(EvtEnrollProp_ToNormalTextAttrNode)
            
EvtEnrollElem.Item("EventEnrollmentProperties").SetAttributeNode(EvtEnrollProp_ToOffNormalTextAttrNode)

            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").Item("EnabledReference").SetAttributeNode(EnRef_ObjKeyAttrNode)
            
EvtEnrollElem.Item("EventEnrollmentProperties").Item("EnabledReference").SetAttributeNode(EnRef_PropName)

            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").Item("EventParameters").SetAttributeNode(EvtPara_BitMaskAttrNode)
            
EvtEnrollElem.Item("EventEnrollmentProperties").Item("EventParameters").SetAttributeNode(EvtPara_DeadbandAttrNode)
            
EvtEnrollElem.Item("EventEnrollmentProperties").Item("EventParameters").SetAttributeNode(EvtPara_HighDiffLimitAttrNode)
            
EvtEnrollElem.Item("EventEnrollmentProperties").Item("EventParameters").SetAttributeNode(EvtPara_HighLimitAttrNode)
            
EvtEnrollElem.Item("EventEnrollmentProperties").Item("EventParameters").SetAttributeNode(EvtPara_ListOfBitStringValuesAttrNode)
            
EvtEnrollElem.Item("EventEnrollmentProperties").Item("EventParameters").SetAttributeNode(EvtPara_ListOfValuesAttrNode)
            
EvtEnrollElem.Item("EventEnrollmentProperties").Item("EventParameters").SetAttributeNode(EvtPara_LowDiffLimitAttrNode)
            
EvtEnrollElem.Item("EventEnrollmentProperties").Item("EventParameters").SetAttributeNode(EvtPara_LowLimitAttrNode)
            
EvtEnrollElem.Item("EventEnrollmentProperties").Item("EventParameters").SetAttributeNode(EvtPara_RefPropIncrAttrNode)
            
EvtEnrollElem.Item("EventEnrollmentProperties").Item("EventParameters").SetAttributeNode(EvtPara_TimeDelayAttrNode)
            
EvtEnrollElem.Item("EventEnrollmentProperties").Item("EventParameters").SetAttributeNode(EvtPara_TimeIntervalAttrNode)

            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").Item("EventParameters").Item("SetpointReference").SetAttributeNode(SetPointRef_ObjKeyAttrNode)
            
EvtEnrollElem.Item("EventEnrollmentProperties").Item("EventParameters").Item("SetpointReference").SetAttributeNode(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").SetAttributeNode(GP_AttrNode)
            
EvtEnrollElem.Item("GeneralProperties").SetAttributeNode(GP_InstNumAttrNode)
            
EvtEnrollElem.Item("GeneralProperties").SetAttributeNode(GP_IsConfigAttrNode)
            
EvtEnrollElem.Item("GeneralProperties").SetAttributeNode(GP_ObjNameAttrNode)
            
EvtEnrollElem.Item("GeneralProperties").SetAttributeNode(GP_ObjTypeAttrNode)
            
EvtEnrollElem.Item("GeneralProperties").SetAttributeNode(GP_SchemaVerAttrNode)
            
EvtEnrollElem.Item("GeneralProperties").SetAttributeNode(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")


0
dotnetnoob (31)
6/27/2006 7:24:01 PM
dotnet.xml 7266 articles. 0 followers. Follow

2 Replies
1055 Views

Similar Articles

[PageSpeed] 0

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
0
some2113 (163)
6/29/2006 2:53:44 PM
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
> 
0
dotnetnoob (31)
6/30/2006 2:26:01 AM
Reply:

Similar Artilces: