Link to home
Start Free TrialLog in
Avatar of Neil Thompson
Neil ThompsonFlag for United Kingdom of Great Britain and Northern Ireland

asked on

remove 2 empty XML nodes

Hi

I have the following XML which I need to remove the 2 elements that are empty, can someone provide the code to achieve this please?

I'm using ASP XMLDoc if that matters?

These need to go:
<WorksheetId></WorksheetId>
<M3JobType></M3JobType>


<?xml version="1.0" encoding="UTF-8"?>
<fod:Doc xmlns:fod="http://www.northgate-is.com/FrontOffice/BiztalkQuery">
  <fod:root>
    <record>
    <EntityId>25769877666</EntityId>
    [b]<WorksheetId></WorksheetId>
    <M3JobType></M3JobType>[/b]
    <WorksheetId>WK/201500181</WorksheetId>
    <M3JobType>Missed Bin</M3JobType>
    <WorksheetId>WK/201500182</WorksheetId>
    <M3JobType>Missed Bin</M3JobType>
</record>
</fod:root>
</fod:Doc>

Open in new window

Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

why do you want to remove them?
and is the XML the first place to start with, or is it on the generation of the XML you may want to skip them being created?

in vbscript, using the xml "plain string", I would eventually do a plain "replace" of
"<WorksheetId></WorksheetId>" by "" and "<M3JobType></M3JobType>" by "" ...
http://www.w3schools.com/vbscript/func_replace.asp
Avatar of Neil Thompson

ASKER

The XML is coming from another system so I cannot stop them being created unfortunately so need to work on the XML itself before I pump it on.

I've found out this is the way to do it:

	Set myNode = XMLDoc.SelectSingleNode("//WorksheetId")
        myNode.ParentNode.RemoveChild(myNode)
	
	Set myNode = XMLDoc.SelectSingleNode("//M3JobType")
        myNode.ParentNode.RemoveChild(myNode)

Open in new window


Regards
Neil
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Guy, Appreciate the assistance