Re: interacting with xml

Tech-Archive recommends: Fix windows errors by optimizing your registry



You're welcome!!! :D Happy Programming

Regards,


--
Angel J. Hernández M.
MCP - MCAD - MCSD - MCDBA
http://groups.msn.com/desarrolladoresmiranda
http://www.consein.com


"Sharon" <Sharon669@xxxxxxxxxxx> escribió en el mensaje
news:%23i4wSK9YFHA.2508@xxxxxxxxxxxxxxxxxxxxxxx
> Thank you Angel
>
> After changing from this line:
> node1 = doc.SelectSingleNode("Catalog/Cd[@category='rock']/Artist");
> to this :
>
> node1 = doc.SelectSingleNode("Catalog/Cd[@category=\"rock\"]/Artist");
>
> It's working great!!!
>
> Thank you very much
>
> Sharon
>
>
>
> Angel J. Hernández M." <angeljesus14@xxxxxxxxxxx> wrote in message
> news:eHqDK25YFHA.4088@xxxxxxxxxxxxxxxxxxxxxxx
>
>> Hi there... you can do it like this...
>>
>> System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); // Used to
>> load the xml document
>> System.Xml.XmlNode node1, node2; // Used to store information about those
>> nodes you're interested in
>> string node1_value, node2_value; // Used to store and read the values
>> from the nodes
>> doc.Load(@"c:\sample.xml"); // Loading of xml document
>> node1 = doc.SelectSingleNode("Catalog/Cd[@category='rock']/Artist"); //
>> Select the node by using a XPath query
>> node1_value = node1["First_Name"].InnerText; // Store the value of the
>> first node
>> node1["First_Name"].InnerXml = "Angel"; // Change the value... I wrote my
>> name ;-)
>> node2 = doc.SelectSingleNode("Catalog/Cd[@category='pop']"); // Select
>> the node once again by using XPath
>> node2_value = node2.Attributes["category"].InnerText; // Get the value
>> for the attribute
>> node2.Attributes["category"].InnerXml="jazz"; // Set the new value for
>> the attribute
>> doc.Save(@"c:\modified.xml"); // Save the modified document
>>
>> and that's it! The catalog's closing tag is missing in the xml you send
>> so you need to write it first in order to test the code.
>> Hope this may help you... Have a nice day! :D
>>
>> Regards,
>>
>>
>> --
>> Angel J. Hernández M.
>> MCP - MCAD - MCSD - MCDBA
>> http://groups.msn.com/desarrolladoresmiranda
>> http://www.consein.com
>>
>>
>> "Sharon" <Sharon669@xxxxxxxxxxx> escribió en el mensaje
>> news:OmKdhS1YFHA.2508@xxxxxxxxxxxxxxxxxxxxxxx
>>>
>>> hi guys , I'm mew to system.xml my question is :
>>> what is the right way to read / write value to the "First_Name" node ?
>>> and same question : how do I read/ write to the category property
>>> (inside the CD node) ?
>>>
>>> thank you very much
>>> Sharon
>>>
>>> <Catalog>
>>> <Cd category="rock">
>>> <Title>Empire Burlesque</Title>
>>> <Artist>
>>> <First_Name>Bob</First_Name>
>>> <Last_Name>Dylan</Last_Name>
>>> </Artist>
>>> <Country>Usa</Country>
>>> <Company>Columbia</Company>
>>> <Price>10.90</Price>
>>> <Year>1985</Year>
>>> </Cd>
>>> <Cd category="pop">
>>> <Title>Hide Your Heart</Title>
>>> <Artist>
>>> <First_Name>Bonnie</First_Name>
>>> <Last_Name>Tyler</Last_Name>
>>> </Artist>
>>> <Country>Uk</Country>
>>> <Company>Cbs Records</Company>
>>> <Price>9.90</Price>
>>> <Year>1988</Year>
>>> </Cd>
>>>
>>
>>
>
>


.



Relevant Pages