Question Commenting out a node

skaliam

New member
Joined
Mar 14, 2013
Messages
3
Programming Experience
5-10
Hi,

I need to use vb.net to read an xml file, then find specific nodes and comment them out.
I am able to load and read the nodes, but I'm not sure what to do about commenting a node.
I have the following xml structure:

VB.NET:
<Main>
   <Services>
    <Service name="01">
     <Uses>
      <Use type="front">
       <Member name="01"/>
      </Use>
     </Uses>
    </Service>
   </Services>
   <Adaptors>
    <Adaptor name="cash" start="true"/>
   </Adaptors>
 </Main>

I would like to comment out the "Adaptor" node "cash".
Can anyone help?
 
One option is to use the ReplaceWith method, as show here:
        Dim doc = XDocument.Load("data.xml")
        Dim node = doc...<Member>.First

        node.ReplaceWith(New XComment(node.ToString))

        doc.Save("newdata.xml")
 
Thanks, but I'm not sure what the "..." is supposed to be?
It is just an example selecting a node, in this case the first descendant Member node in document.
 
So if i had another adaptor say
VB.NET:
<adaptor name="card" start="false"/>

How would i select a single node to comment?
i.e i want to comment the adaptor "card" or many more
 
You can select any nodes from XDocument object or a subset of this, using its properties and methods, you can also use Linq to Xml to query for nodes.
 
Back
Top