We help IT Professionals succeed at work.

How to check the node exists in xml and returns the string values by reading CDATA values

tia_kamakshi
tia_kamakshi asked
on
456 Views
Last Modified: 2012-02-19
Hi Experts,

How to check the node exists in xml and returns the string values by reading CDATA values.

string strXML ="<?xml version="1.0"?>
<tcm:Error xmlns:tcm="http://www.tridion.com/ContentManager/5.0" ErrorCode="80040329" Category="17" Source="Kernel" Severity="2">
  <tcm:Line ErrorCode="80040329" Cause="false" MessageID="16137">
    <![CDATA[Unable to save Keyword (tcm:0-0-0).]]><tcm:Token>RESID_4574</tcm:Token><tcm:Token>RESID_15309</tcm:Token><tcm:Token>tcm:0-0-0</tcm:Token>
  </tcm:Line>
  <tcm:Line ErrorCode="80040329" Cause="true" MessageID="15200">
    <![CDATA[Name must be unique for items of type: Keyword within this Category and its BluePrint context. Source or sources  of conflict: tcm:236-215788-1024,tcm:237-215788-1024,tcm:241-215788-1024,tcm:243-215788-1024,tcm:423-215788-1024.]]><tcm:Token>RESID_15214</tcm:Token><tcm:Token>RESID_15309</tcm:Token><tcm:Token>RESID_15293</tcm:Token><tcm:Token>tcm:236-215788-1024,tcm:237-215788-1024,tcm:241-215788-1024,tcm:243-215788-1024,tcm:423-215788-1024</tcm:Token>
  </tcm:Line>
  <tcm:Details>
    <tcm:CallStack>
      <tcm:Location>UtilitiesBL.AssertUniqueTitle</tcm:Location>
      <tcm:Location>UtilitiesBL.AssertUniqueTitle</tcm:Location>
      <tcm:Location>KeywordBL.Create</tcm:Location>
      <tcm:Location>XMLState.Save</tcm:Location>
      <tcm:Location>Keyword.Save</tcm:Location>
    </tcm:CallStack>
  </tcm:Details>
</tcm:Error>"

Open in new window


Now I want to write a function which will first check whether string strXML has the xml node node in it, if there is no such node then return "valid" else my function will return the string values taken from above xml.

So my return result will be "Unable to save Keyword (tcm:0-0-0). Name must be unique for items of type: Keyword within this Category and its BluePrint context. Source or sources of conflict: tcm:236-215788-1024,tcm:237-215788-1024,tcm:241-215788-1024,tcm:243-215788-1024,tcm:423-215788-1024.", these text are there in XML.

Please suggest!!

Thanks.
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
You could use a LINQ-to-XML query to get the value, but with the namespaces, it is a little trickier.

Proof-of-concept:

http://blogs.msdn.com/b/wriju/archive/2008/05/29/linq-to-xml-querying-xml-with-namespaces.aspx

XNamespace ns = "myns-com";          

var query = from lst in XElement.Load(@"c:\NS.xml").Elements(ns+"product")

            select (int)lst.Attribute("ProductID");

Open in new window

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
With all the words on this page, there is too much noise, so if you expect everyone to see that one little piece of information, then you will continue to be disappointed.  

What you have should work, so go with it.

Author

Commented:
Good Solution as per requirement
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.