Solved

xmldocument extract value

Posted on 2011-02-27
2
443 Views
Last Modified: 2012-05-11
Hi EE,

I need to get extract following values from "<TopicSet FormalName="ICBClasification">"
i. ICBIndustry
ii. ICBSupersector
iii. ICBSector

pls help.

Thanks

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE NewsML SYSTEM "http://www.iptc.org/std/NewsML/1.2/specification/NewsML_1.2.dtd">
<NewsML Version="1.2">
  <Catalog Href="http://www-test.com.catalog.xml" />
  <NewsEnvelope>
    <TransmissionId>1328088_</TransmissionId>
    <DateAndTime>20100930T110626+0200</DateAndTime>
    <NewsProduct FormalName="Regulatory Information Service"/>
  </NewsEnvelope>
  <NewsItem>
    <Identification>
      <NewsIdentifier>
        <ProviderId>test.com</ProviderId>
        <DateId>20100930</DateId>
        <NewsItemId>TEST1328088</NewsItemId>
        <RevisionId PreviousRevision="0" Update="N">1</RevisionId>
        <PublicIdentifier>urn:newsml:TEST.com:20100930:XX1328088:1</PublicIdentifier>
      </NewsIdentifier>
    </Identification>
    <NewsManagement>
      <NewsItemType FormalName="News"/>
      <FirstCreated>20100930T110626+0200</FirstCreated>
      <ThisRevisionCreated>20100930T110626+0200</ThisRevisionCreated>
      <Status FormalName="Usable"/>
      <Urgency FormalName="4"/>
      <Property FormalName="sst.3rdPartyStyleGuideVersion" Value="2.0" />
    <Property FormalName="category" Value="N" />
    <Property FormalName="ern" Value="N.A." />
    <Property FormalName="distributor" Value="SSS" />
    </NewsManagement>
    <NewsComponent xml:lang="en" Essential="no" EquivalentsList="no" Duid="NC00001">
      <TopicSet FormalName="Companies">
        <Topic Duid="T000001">
          <TopicType FormalName="Company"/>
          <FormalName Scheme="CompanyLongName"><![CDATA[Test Client]]></FormalName>
          <FormalName Scheme="CompanyShortName"><![CDATA[]]></FormalName>
      <FormalName Scheme="Country"><![CDATA[U.S.A.]]></FormalName>
      <FormalName Scheme="City"><![CDATA[Paris]]></FormalName>
          <FormalName Scheme="TIDM"></FormalName>
      <FormalName Scheme="USTIC"></FormalName>
          <FormalName Scheme="ISIN"></FormalName>
      <FormalName Scheme="ISIC"></FormalName>
          <FormalName Scheme="cRIC"></FormalName>
      <FormalName Scheme="CompanyUrl"></FormalName>
      <FormalName Scheme="GermanWkn"></FormalName>
      <FormalName Scheme="Sedol"></FormalName>
        </Topic>    
      </TopicSet>
	  	        <TopicSet FormalName="FSACategories">
        <Topic Duid="T00003">
          <TopicType FormalName="FSACategory"/>
          <FormalName Scheme="FSACategory"></FormalName>
        </Topic>
      </TopicSet>
      <TopicSet FormalName="MediumImportance">
        <Topic Duid="T00004">
          <TopicType FormalName="Geography" Scheme="RTT" />
          <FormalName Scheme="N2000">us</FormalName>
        </Topic>
      </TopicSet>
    
    <TopicSet FormalName="ICBClasification">
        <Topic Duid="ICB_IN">
          <TopicType FormalName="ICBIndustry"/>
          <FormalName Scheme="ICBIndustry">Financials</FormalName>
        </Topic>
    <Topic Duid="ICB_SU">
          <TopicType FormalName="ICBSupersector"/>
          <FormalName Scheme="ICBSupersector">Financial Services</FormalName>
        </Topic>
    <Topic Duid="ICB_SE">
          <TopicType FormalName="ICBSector"/>
          <FormalName Scheme="ICBSector">Financial Services</FormalName>
        </Topic>
      </TopicSet>
        
        <TopicSet FormalName="CustomTags">    
          <Topic Duid="CT#1">
          <TopicType FormalName="CustomTag"/>
          <FormalName Scheme="CustomTag">David Morgan, silver-investor, moneyandmines, Hong Kong2011, investmentpitch, investment pitch,</FormalName>
        </Topic>
              <Topic Duid="CT#2">
          <TopicType FormalName="CustomTag"/>
          <FormalName Scheme="CustomTag">silver, smallcap, small cap, video</FormalName>
        </Topic>
        
      </TopicSet>
            
        <TopicSet FormalName="ErnTagging">    
        </TopicSet> 
	  
      <Role FormalName="Main"/>
      <NewsLines>
        <HeadLine><![CDATA[TEST RELEASE]]></HeadLine>
        <DateLine>London, September, 30, 2010</DateLine>
      </NewsLines>
      <AdministrativeMetadata>
        <Creator>     
          <Party FormalName="Test Client"/>  
        </Creator>
        <Source>
          <Party FormalName="Test Client"/>
        </Source>
      </AdministrativeMetadata>

      <RightsMetadata/>

      <DescriptiveMetadata>
        <Language FormalName="en"/>
        <TopicOccurrence Topic="#T000001"/>

        <TopicOccurrence Topic="#T00003" HowPresent="FSACategories"/>
        <TopicOccurrence Topic="#T00004" HowPresent="MediumImportance"/>
    
              <SubjectCode Duid="SC#1" HowPresent="Related" >
        <Subject Duid="S#1" HowPresent="Related" FormalName="Economy, Business And Finance" />
              <SubjectMatter Duid="S#1_SM#1" HowPresent="Related" FormalName="Company Information" />
                  <SubjectDetail Duid="S#1_SM#1_SD#1" HowPresent="Related" FormalName="Contract" />
                  <SubjectDetail Duid="S#1_SM#1_SD#2" HowPresent="Related" FormalName="Earnings" />
                    </SubjectCode>
        
    <TopicOccurrence Topic="#ICB_IN" HowPresent="ICBClasification"/>
    <TopicOccurrence Topic="#ICB_SU" HowPresent="ICBClasification"/>
    <TopicOccurrence Topic="#ICB_SE" HowPresent="ICBClasification"/>
      </DescriptiveMetadata>
    
      <ContentItem Duid="CI00001">
        <MediaType FormalName="text"/>
        <Format FormalName="XHTML"/>
<DataContent>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:mce="mce"><head><style>* { font-family: Arial, Verdana, Helvetica; font-size: 13px;}
td { padding: 3px; }
}</style><title>TEST RELEASE</title></head><body class="TEST">   <p align="center" class="TEST" style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 10pt; margin-left: 0cm"><i class="TEST"><u class="TEST">You can disregard this test release. </u></i></p> <p class="TEST" style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 0pt; margin-left: 36pt; text-indent: -18pt">· TEST TEXT TEST TEXT TEST TEXT TEST TEXT TEST TEXT TEST TEXT TEST TEXT TEST TEXT TEST TEXT TEST TEXT </p> <p class="TEST" style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 0pt; margin-left: 36pt"> </p>                                                                     </body></html>
</DataContent>
      </ContentItem>
    </NewsComponent>
  </NewsItem>
</NewsML>

Open in new window

0
Comment
Question by:saloj
2 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 400 total points
ID: 34991071
The following will grab the nodes you are interested in and display their text value to a console window. Not that the XPath query is explicit, so it will ignore any extra child nodes if there happened to be any:
    class Program
    {
        static void Main(string[] args)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load("C:\\test.xml");

            XmlNodeList nodes = doc.SelectNodes("//TopicSet[@FormalName='ICBClasification']//FormalName[preceding-sibling::TopicType[@FormalName='ICBIndustry' or @FormalName='ICBSupersector' or @FormalName='ICBSector']]");
            foreach (XmlNode node in nodes)
            {
                Console.WriteLine(node.InnerText);
            }

            Console.ReadLine();
        }
    }

Open in new window

0
 
LVL 11

Assisted Solution

by:Sudhakar Pulivarthi
Sudhakar Pulivarthi earned 100 total points
ID: 34996122
Hi Saloj,
You can use this XPath query to dynamically get all the child nodes under the node 'ICBClasification'
"//TopicSet[@FormalName='ICBClasification']//FormalName[preceding-sibling::*]"
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
A short film showing how OnPage and Connectwise integration works.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now