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

LVL 3
Neil ThompsonSenior Systems DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
0
Neil ThompsonSenior Systems DeveloperAuthor Commented:
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
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
that is indeed a "pure xml" way to do it.
however, I must presume that it is likely not as efficient as the simple string replace method.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Neil ThompsonSenior Systems DeveloperAuthor Commented:
Thanks Guy, Appreciate the assistance
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.