|
-
Nov 10th, 2005, 01:23 PM
#1
Thread Starter
No place like 127.0.0.1
[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.
-
Nov 10th, 2005, 01:53 PM
#2
Re: Remove A Node from an XML document
Why do you want to remove that particular node?
-
Nov 10th, 2005, 02:05 PM
#3
Thread Starter
No place like 127.0.0.1
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.
-
Nov 10th, 2005, 03:02 PM
#4
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.
-
Nov 10th, 2005, 03:19 PM
#5
Thread Starter
No place like 127.0.0.1
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.
-
Nov 10th, 2005, 05:15 PM
#6
Hyperactive Member
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...
-
Nov 10th, 2005, 05:38 PM
#7
Thread Starter
No place like 127.0.0.1
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.
-
Nov 10th, 2005, 06:28 PM
#8
Re: Remove A Node from an XML document
 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.
-
Nov 10th, 2005, 09:48 PM
#9
Thread Starter
No place like 127.0.0.1
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.
-
Apr 13th, 2011, 02:36 AM
#10
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|