darkstrike20
Member
- Joined
- Jul 17, 2014
- Messages
- 7
- Programming Experience
- Beginner
Hi i'm trying to remove the NewDataSet node from an exsiting xml file but i receive an error during my runtime - Illegal char in path
Example of my xml document :-
<?xml version="1.0" standalone="yes"?><NewDataSet>
<trs_bills>
<ID>145</ID>
<TrsOutlet>V001</TrsOutlet>
<TrsDate>2014-07-03T00:00:00+08:00</TrsDate>
<DateCreated>2014-07-03T17:16:05+08:00</DateCreated>
<TerminalCode>001</TerminalCode>
<TrsNo>V001#001#20140703171605#CSH#1000169</TrsNo>
<BillNo>1000169</BillNo>
<ReceiptNo>001-1000101</ReceiptNo>
<StaffCode>666</StaffCode>
<StaffName />
<AccountCode>NON</AccountCode>
<AccountName>Chan</AccountName>
<AgentCode>666</AgentCode>
<AgentName />
<TrsTime>1899-12-30T17:17:00+08:00</TrsTime>
<SubTotal>43.0000</SubTotal>
<ItemDiscAmt>0.0000</ItemDiscAmt>
<Tax1Amt>2.5800</Tax1Amt>
<Tax2Amt>4.3000</Tax2Amt>
<GrossAmt>43.0000</GrossAmt>
<BillDiscAmt>0.0000</BillDiscAmt>
<NetAmt>49.8800</NetAmt>
<RoundedDiff>0.02</RoundedDiff>
<RoundedAmt>49.90</RoundedAmt>
<ValueDiscAmt>0.00</ValueDiscAmt>
<EndTotalAmt>49.90</EndTotalAmt>
<PaidStatus>1</PaidStatus>
</NewDataSet>
Dim doc2 As XmlDocument = New XmlDocument()
Dim xtr As XmlTextReader = New XmlTextReader("D:\XMLfiles\" + KMsg + ".xml")
doc2.Load(xtr)
xtr.Close()
'Get the <NewDataSet> node
Dim node As XmlNode = doc2.GetElementsByTagName("NewDataSet")(0)
Dim nodelistParent As XmlNode = node.ParentNode
Dim tmpnodelist As XmlNodeList = node.ChildNodes
nodelistParent.RemoveChild(node)
Dim newdoc As XmlDocument = New XmlDocument()
'Error here - Illegal characters in path.
newdoc.Load(doc2.InnerXml)
'Append all the child nodes of <NewDataSet> to its parentnode
While tmpnodelist.Count > 0
nodelistParent.AppendChild(tmpnodelist(0))
End While
'Insert the remaining portion into newdoc
Dim newnode As XmlNode = newdoc.GetElementsByTagName(nodelistParent.Name)(0)
newnode.InnerXml = nodelistParent.InnerXml
'Save document
newdoc.Save("D:\" + KMsg + ".xml")
Example of my xml document :-
<?xml version="1.0" standalone="yes"?><NewDataSet>
<trs_bills>
<ID>145</ID>
<TrsOutlet>V001</TrsOutlet>
<TrsDate>2014-07-03T00:00:00+08:00</TrsDate>
<DateCreated>2014-07-03T17:16:05+08:00</DateCreated>
<TerminalCode>001</TerminalCode>
<TrsNo>V001#001#20140703171605#CSH#1000169</TrsNo>
<BillNo>1000169</BillNo>
<ReceiptNo>001-1000101</ReceiptNo>
<StaffCode>666</StaffCode>
<StaffName />
<AccountCode>NON</AccountCode>
<AccountName>Chan</AccountName>
<AgentCode>666</AgentCode>
<AgentName />
<TrsTime>1899-12-30T17:17:00+08:00</TrsTime>
<SubTotal>43.0000</SubTotal>
<ItemDiscAmt>0.0000</ItemDiscAmt>
<Tax1Amt>2.5800</Tax1Amt>
<Tax2Amt>4.3000</Tax2Amt>
<GrossAmt>43.0000</GrossAmt>
<BillDiscAmt>0.0000</BillDiscAmt>
<NetAmt>49.8800</NetAmt>
<RoundedDiff>0.02</RoundedDiff>
<RoundedAmt>49.90</RoundedAmt>
<ValueDiscAmt>0.00</ValueDiscAmt>
<EndTotalAmt>49.90</EndTotalAmt>
<PaidStatus>1</PaidStatus>
</NewDataSet>
Dim doc2 As XmlDocument = New XmlDocument()
Dim xtr As XmlTextReader = New XmlTextReader("D:\XMLfiles\" + KMsg + ".xml")
doc2.Load(xtr)
xtr.Close()
'Get the <NewDataSet> node
Dim node As XmlNode = doc2.GetElementsByTagName("NewDataSet")(0)
Dim nodelistParent As XmlNode = node.ParentNode
Dim tmpnodelist As XmlNodeList = node.ChildNodes
nodelistParent.RemoveChild(node)
Dim newdoc As XmlDocument = New XmlDocument()
'Error here - Illegal characters in path.
newdoc.Load(doc2.InnerXml)
'Append all the child nodes of <NewDataSet> to its parentnode
While tmpnodelist.Count > 0
nodelistParent.AppendChild(tmpnodelist(0))
End While
'Insert the remaining portion into newdoc
Dim newnode As XmlNode = newdoc.GetElementsByTagName(nodelistParent.Name)(0)
newnode.InnerXml = nodelistParent.InnerXml
'Save document
newdoc.Save("D:\" + KMsg + ".xml")