Victor Charles
asked on
Help with removing data from an xml file.
How do I loop through both Item and LinkTotalA.xml files and delete ItemTable element from Item.xml if the Item_ID in LinkTotalA.xml is not found in Item.xml?
.Item.xml
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<ItemTable>
<Item_ID>1</Item_ID>
<Item>BMW</Date_ID>
</ItemTable>
<ItemTable>
<Item_ID>2</Item_ID>
<Item>Toyota</Date_ID>
</ItemTable>
<ItemTable>
<Item_ID>3</Item_ID>
<Item>Honda</Date_ID>
</ItemTable>
</Root>
LinkTotalA.xml
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<LinkTotalTable>
<LinkTotal_ID>1</LinkTotal _ID>
<Location_ID>3</LocationA_ ID>
<Item_ID>1</Item_ID>
</LinkTotalTable>
<LinkTotalTable>
<LinkTotal_ID>2</LinkTotal _ID>
<Location_ID>2</LocationA_ ID>
<Item_ID>1</Item_ID>
</LinkTotalTable>
<LinkTotalTable>
<LinkTotal_ID>3</LinkTotal _ID>
<Location_ID>2</LocationA_ ID>
<Item_ID>2</Item_ID>
</LinkTotalTable>
Give the example of xml files above, after running the code my Item.xml should be as follows:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<ItemTable>
<Item_ID>1</Item_ID>
<Item>BMW</Date_ID>
</ItemTable>
<ItemTable>
<Item_ID>2</Item_ID>
<Item>Toyota</Date_ID>
</ItemTable>
</Root>
Becuase Item_ID = 3 was not found in the LinkTotalA.xml file.
Thanks,
V.
.Item.xml
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<ItemTable>
<Item_ID>1</Item_ID>
<Item>BMW</Date_ID>
</ItemTable>
<ItemTable>
<Item_ID>2</Item_ID>
<Item>Toyota</Date_ID>
</ItemTable>
<ItemTable>
<Item_ID>3</Item_ID>
<Item>Honda</Date_ID>
</ItemTable>
</Root>
LinkTotalA.xml
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<LinkTotalTable>
<LinkTotal_ID>1</LinkTotal
<Location_ID>3</LocationA_
<Item_ID>1</Item_ID>
</LinkTotalTable>
<LinkTotalTable>
<LinkTotal_ID>2</LinkTotal
<Location_ID>2</LocationA_
<Item_ID>1</Item_ID>
</LinkTotalTable>
<LinkTotalTable>
<LinkTotal_ID>3</LinkTotal
<Location_ID>2</LocationA_
<Item_ID>2</Item_ID>
</LinkTotalTable>
Give the example of xml files above, after running the code my Item.xml should be as follows:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<ItemTable>
<Item_ID>1</Item_ID>
<Item>BMW</Date_ID>
</ItemTable>
<ItemTable>
<Item_ID>2</Item_ID>
<Item>Toyota</Date_ID>
</ItemTable>
</Root>
Becuase Item_ID = 3 was not found in the LinkTotalA.xml file.
Thanks,
V.
ASKER
Unfortunately, I am only allowed to use XML, how do i modify the code below to go through all the records in LinkTotal.xml and compare to each record in Item.xml and if you arrive at the last record in LinkTotal.xml and there is no match with Item_ID then delete the record in Item.xml.
Code below only loops through Item.xml, need to include portion which loops through LinkTotal.xml.
Dim dkF As New XmlDocument
dkF.Load(Server.MapPath("~ /App_DataA /Item.xml" ))
Dim pizF As XmlElement = dkF.DocumentElement
For Each topping As Xml.XmlNode In pizF.SelectNodes("/Root/It emTable[It em_ID<>'" & LinkTotal_ID & "']")
topping.ParentNode.RemoveC hild(toppi ng)
dkF.Save(Server.MapPath("~ /App_DataA /Item.xml" ))
Exit For
Next
Code below only loops through Item.xml, need to include portion which loops through LinkTotal.xml.
Dim dkF As New XmlDocument
dkF.Load(Server.MapPath("~
Dim pizF As XmlElement = dkF.DocumentElement
For Each topping As Xml.XmlNode In pizF.SelectNodes("/Root/It
topping.ParentNode.RemoveC
dkF.Save(Server.MapPath("~
Exit For
Next
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, I will test it and get back to you.
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
inXml => Process => outXml
XML is a transportmedium, not a DB table. so preferable you have to put the xml in tables do your job and create new XML files. If you draw the process, it's clear that this is the way.
Changing data directly in xml without a DB process, is actually the same a removeing the red pixels from a *.bmp without paint. It's doable but not the right way.