Results 1 to 10 of 10

Thread: [RESOLVED] Remove A Node from an XML document

  1. #1

    Thread Starter
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Resolved [RESOLVED] Remove A Node from an XML document

    This may seem like a really basic question, but how do I remove a node from an XML document? I know the name and position of the node (its at the top of the document and is a single node meaning it doesn't have a cloding tag).

    I tried a few things, but I was only guessing about which methods/properties to use. Can anyone tell me how to do this the right way?

    Here is the XML:
    Code:
    <?xml version="1.0" encoding="UTF-16"?>
    <PropertyBag>
    	<frmMain>
    		<FormMain.WindowState>0</FormMain.WindowState>
    		<FormMain.Top>2610</FormMain.Top>
    		<FormMain.Left>2985</FormMain.Left>
    		<FormMain.Height>6300</FormMain.Height>
    		<FormMain.Width>9390</FormMain.Width>
    		<Toolbars.Menus>True</Toolbars.Menus>
    	</frmMain>
    </PropertyBag>
    ... and I need to remove this line "<?xml version="1.0" encoding="UTF-16"?>"

    Any help would be appriciated.
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  2. #2

  3. #3

    Thread Starter
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Re: Remove A Node from an XML document

    Because the XML is generated from a class I am using. Then I feed it into the XSL indention code you wrote and it adds that line to the top for some reason. When I try to feed it back into the class that wrote it, it won't read it because the top level node its looking for isn't the same.

    I know it is more "proper" to keep that line in because it helps describe the data better, but it causes my code to stop working.
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Remove A Node from an XML document

    There may be a way to remove it via XML but you could certainly remove it by reading the file as a text file, but if your class can't read the file as is then I'd have to say that there is something wrong with the class and that is what you should fix.

  5. #5

    Thread Starter
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Re: Remove A Node from an XML document

    Of course there is a way to remove it. That is the point of this thread. I have played around with RemoveNode and other methods, but I can't get them to work right. I'd rather remove it using MSXML.

    The class wasn't made by me and there is nothing wrong with it. It is a DLL and one of its dependencies is MSXML 3.0. It can read files just fine. The problem is when I modify the XML outside of the class (using the IndentXML module that you and I came up with). When I call IndentXML() it automatically adds that line to the XML and I want to remove it so the class can function properly.
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  6. #6
    Hyperactive Member eranfox's Avatar
    Join Date
    May 2001
    Posts
    492

    Re: Remove A Node from an XML document

    Hello eyeRmonkey,
    I'm Not sure about that ,but i think the Node you are trying to delete is not actually a part of the XML nodes.

    your XML Root node is <PropertyBag>
    the node you are trying to delete is a description Node - it say that this is XML document and the XML version and the encoding="UTF-16".

    if you are using the DOM then i dont think it reads this node anyway...

    so basically what MartinLiss wrote sounds like the best thing to do.

    Best Regards,
    ERAN
    Eran Fox
    ASSEMBLER,C,C++,VB6,SQL...

  7. #7

    Thread Starter
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Re: Remove A Node from an XML document

    You are incorrect on that point. I have been able to select the node using .FirstNode and other methods that cycle through the nodes. I know it is recognized. The problem is when I try to do things like .RemoveNode it doesn't return anything or it doesn't return the right thing.
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  8. #8
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Remove A Node from an XML document

    Quote Originally Posted by eyeRmonkey
    You are incorrect on that point. I have been able to select the node using .FirstNode and other methods that cycle through the nodes. I know it is recognized. The problem is when I try to do things like .RemoveNode it doesn't return anything or it doesn't return the right thing.
    Please post the code that you use to select the encoding node.

  9. #9

    Thread Starter
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Re: Remove A Node from an XML document

    Don't worry about it. I just did it using Replace$() like you guys mentioned. I was just hoping there would be an easy way to do it using the proper methods. Thanks anyway.
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  10. #10
    Lively Member
    Join Date
    Jul 2008
    Posts
    73

    Re: [RESOLVED] Remove A Node from an XML document

    i am aslo facing the same issue
    a xml file is created thr' code using vb6.0 & parsed for validation using sax parser
    when paarsing due to line formating
    <?xml version="1.0" encoding="utf-8" standalone="yes" ?> gets appended to the existing data at the start of the file ie the first line
    is there any way that it culd be deleted programatically

    i dont need the above line as per the format specified by the client

    i tried using

    Dim xmldom1 As MSXML2.DOMDocument40
    xmldom1.Load FileName

    Dim toRemove As String
    toRemove = "UTF-16"
    Set nodeTemp = xmldom1.selectSingleNode("xml version/encoding[@standalone = '" + toRemove + "']")
    nodeInvoiceItems.parentNode.removeChild (nodeTemp)

    wit reference to the links i trried to delete but not getting

Posting Permissions

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



Click Here to Expand Forum to Full Width