Removing an xml element from a file

Results 1 to 2 of 2

Thread: Removing an xml element from a file

  1. #1
    Join Date
    Dec 1969

    Default Removing an xml element from a file

    This should be a fairly simple problem, but I seems to be missing something. I am trying to remove an xml element from a file through the Dom. The code below works fine if the element is already present in the file, but throws an error if nothing is there. Is there any way to catch this error, or to rewrite the code so as to prevent the error from occuring.<BR><BR>Thanx in advance. (using VBScript)!<BR><BR>dim objDom, preprint, fm &#039;as object<BR>dim source &#039;as string<BR><BR>set objDom = Server.CreateObject("MSXML2.DOMDocument.3.0")<BR>s ource = server.MapPath("article.xml")<BR>objDom.async = false<BR>objDom.load(source)<BR><BR>&#039;for the preprint element<BR>set fm = objDom.documentElement.selectSingleNode("/art/fm")<BR><BR>set preprint = fm.selectSingleNode("preprint")<BR><BR><BR>&#039;o n error resume next<BR>if preprint.text &#060;&#062; "" then<BR> fm.removeChild(preprint)<BR><BR> Response.Write(" preprint done <BR>")<BR>else<BR> Response.Write("preprint problem")<BR> <BR>end if

  2. #2
    Join Date
    Dec 1969

    Default RE: Removing an xml element from a file

    Test preprint to see if it&#039;s null. Null is the return value of selectSingleNode, if no nodes match the query.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts