Avatar of Neil Thompson
Neil Thompson
Flag 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

XMLVB Script

Avatar of undefined
Last Comment
Neil Thompson

8/22/2022 - Mon
Guy Hengel [angelIII / a3]

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
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
Guy Hengel [angelIII / a3]

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Neil Thompson

ASKER
Thanks Guy, Appreciate the assistance
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy