Link to home
Create AccountLog in
Avatar of saloj
salojFlag for Canada

asked on

xmldoc node add and delete

Hi EE,

I have following xml data and I would like to do following:
Delete:
 <Property FormalName="category" Value="N" />
    <Property FormalName="ern" Value="N.A." />
    <Property FormalName="distributor" Value="SSS" />

Add After (<Role FormalName="Main"/>)
<AdministrativeMetaData>
<Provider>
<Party FormalName="XYZ" />
</Provider>
</AdministrativeMetaData>

pls help
Thankx
<?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>  
      <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> <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 </p> <p class="TEST" style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 0pt; margin-left: 36pt"> </p> <p class="TEST" style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 10pt; margin-left: 36pt; text-indent: -18pt">· TEST TEXT TEST TEXT TEST TEXT TEST TEXT TEST TEXT TEST TEXT TEST TEXT TEST TEXT TEST TEXT </p> <p align="justify" class="TEST" style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 10pt; margin-left: 0cm"><a class="TEST" href="http://www.test.com/" target="_blank">Test</a> text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test.</p> <p align="justify" class="TEST" style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 10pt; margin-left: 0cm">Test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text. <a class="TEST" href="http://www.1.com/" target="_blank">www.1.com</a> <a class="TEST" href="mailto:test@1.com" target="_blank">test@1.com</a> </p> <p class="TEST" style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 10pt; margin-left: 0cm">Quelques caractères spéciaux €, à, é, è, ç, ï, ë, í, ñ, %, &amp;, §, #,;, «, »</p> <p class="TEST" style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 10pt; margin-left: 0cm">TABLEAU 1</p>                                                                     </body></html>
</DataContent>
      </ContentItem>
    </NewsComponent>
  </NewsItem>
</NewsML>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of saloj

ASKER

Hi Kaufmed,

Thanks for your help. I forgot to mention the following.
On my code after line no. 49 I would like to add

<NewsComponent xml:lang="en" Essential="no" EquivalentsList="no" Duid="NC00002">
<Role FormalName="Main"/>

(and put the nodes from Line no 50 to 92 between this new element)

</NewsComponent>

Many thanks
kaufmed has given you the solution, just try to understand it and add few lines on your own :)
Avatar of saloj

ASKER

Guys I am beginner on c# pls help.

Many Thanks
I am confused by http:#34440363 -- you already have one node called NewsComponent and you want to add another one (albeit with a different value for Duid), but you want to add it as a child node of the existing NewsComponent node. Is this correct?
Avatar of saloj

ASKER

Hi Kaufmed,

Thanks for the response.
I want to change to the my existing xml data to the following output.
yes, i already have Newscomponent but want to add another child Newscomponnet with different Duid value after node </DescriptiveMetadata> and move nodes <NewsLines><AdministrativeMetadata>.. under the new <NewsComponent>
eg.

</DescriptiveMetadata>                                                                                                                 (after)
      <NewsComponent xml:lang="en" Essential="no" EquivalentsList="no" Duid="NC00002"> (new addedd)
      <Role FormalName="Main Text" />                                                                                        (new added)

/* Moved the following Nodes under new NewsComponent*/

      <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/>
<ContentItem Duid="CI00001">.........


Many 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>  
      <Role FormalName="Main"/>      
      <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>
	<NewsComponent xml:lang="en" Essential="no" EquivalentsList="no" Duid="NC00002">
	<Role FormalName="Main Text" />
	<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/>
    
      <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> <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 </p> <p class="TEST" style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 0pt; margin-left: 36pt"> </p> <p class="TEST" style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 10pt; margin-left: 36pt; text-indent: -18pt">· TEST TEXT TEST TEXT TEST TEXT TEST TEXT TEST TEXT TEST TEXT TEST TEXT TEST TEXT TEST TEXT </p> <p align="justify" class="TEST" style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 10pt; margin-left: 0cm"><a class="TEST" href="http://www.test.com/" target="_blank">Test</a> text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test.</p> <p align="justify" class="TEST" style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 10pt; margin-left: 0cm">Test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text. <a class="TEST" href="http://www.1.com/" target="_blank">www.1.com</a> <a class="TEST" href="mailto:test@1.com" target="_blank">test@1.com</a> </p> <p class="TEST" style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 10pt; margin-left: 0cm">Quelques caractères spéciaux €, à, é, è, ç, ï, ë, í, ñ, %, &amp;, §, #,;, «, »</p> <p class="TEST" style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 10pt; margin-left: 0cm">TABLEAU 1</p>                                                                     </body></html>
</DataContent>
      </ContentItem>
    </NewsComponent>
    </NewsComponent>
  </NewsItem>
</NewsML>

Open in new window

>>  but want to add another child Newscomponnet with different Duid value after node </DescriptiveMetadata>

Ok, but <DescriptiveMetadata> is a child of <Newscomponent ... Duid="NC00001">. Placing the new node after <DescriptiveMetadata> will make it a child  of Duid="NC00001" also. Is this the intent? That seems a bit backwards to me. I would think you would want each <NewComponent> to be a sibling of the other--not a parent/child.
Example:
<root>
   <parent> --------------------------
        <child1 /> ---                |
                      | Siblings      | Siblings
        <child2 /> ---                |
   </parent>                          |
   <parent> --------------------------
        <child1 /> ---
                      | Siblings
        <child2 /> ---
   </parent>
</root>

Open in new window

Avatar of saloj

ASKER

Hi Kaufmed,
sorry, my previous comment was quite confusion. Actually what i want to do is, I have xml data on my question which I want to display as the following xml format.
comparing the two xml format, most of nodes are similar and also I need to create new <NewsComponent>

hope it helps you to understand what I want to do,  the xml data on my question want to make same as the following xml format.

Thank you


<?xml version="1.0" encoding="iso-8859-1" ?> 
- <NewsML>
  <Catalog Href="http://www.Testxyz.com/newsml/catalog.xml" /> 
- <NewsEnvelope>
  <TransmissionId>201101010357__xyz_Test5714</TransmissionId> 
  <DateAndTime>20110101T035700+0900</DateAndTime> 
  <NewsProduct FormalName="Test" /> 
  </NewsEnvelope>
- <NewsItem>
- <Identification>
- <NewsIdentifier>
  <ProviderId>xyz.net</ProviderId> 
  <DateId>20050322</DateId> 
  <NewsItemId>Test5714</NewsItemId> 
  <RevisionId PreviousRevision="0" Update="N">1</RevisionId> 
  <PublicIdentifier>urn:newsml:xyz.net:20050322:Test5714:1</PublicIdentifier> 
  </NewsIdentifier>
  </Identification>
- <NewsManagement>
  <NewsItemType FormalName="News" /> 
  <FirstCreated>20110101T035700+0900</FirstCreated> 
  <ThisRevisionCreated>20110101T035700+0900</ThisRevisionCreated> 
  <Status FormalName="Usable" /> 
  <Urgency FormalName="4" /> 
  <Property FormalName="Test.StyleGuideVersion" Value="2.0" /> 
  </NewsManagement>
- <NewsComponent xml:lang="en" Essential="no" EquivalentsList="no" Duid="NC00001">
  <TopicSet FormalName="TestTopicCodes" /> 
  <TopicSet FormalName="Companies" /> 
  <TopicSet FormalName="IndustryName" /> 
  <Role FormalName="Main" /> 
- <AdministrativeMetadata>
- <Provider>
  <Party FormalName="Test xyz" /> 
  </Provider>
  </AdministrativeMetadata>
- <DescriptiveMetadata>
  <Language FormalName="en" /> 
  </DescriptiveMetadata>
- <NewsComponent xml:lang="en" Essential="no" EquivalentsList="no" Duid="NC00002">
  <Role FormalName="Main Text" /> 
- <NewsLines>
  <HeadLine>aksfjasfkaj asf asf asf asf as asf asfsStocks</HeadLine> 
  <DateLine>Vancouver, BC, Jan 1, 2011</DateLine> 
  </NewsLines>
- <AdministrativeMetadata>
- <Source>
  <Party FormalName="Test xyz" /> 
  </Source>
  </AdministrativeMetadata>
- <DescriptiveMetadata>
  <OfInterestTo FormalName="Test xyz" /> 
  </DescriptiveMetadata>
- <ContentItem Duid="CI00001">
  <MediaType FormalName="Text" /> 
  <Format FormalName="XHTML" /> 
- <Characteristics>
  <Property FormalName="USN" Value="Test5714" /> 
  </Characteristics>
- <DataContent>
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
  <title>aksfjasfkaj asf asf asf asf as asf asfsStocks</title> 
  </head>
- <body>
  asfaslfksjafsakfjsafk asdfasdf process in the mining industry - more so as senior producers elect to explore less and less, letting the speculators absorb the exploration risk in the junior gold sector. Replacing ounces is expensive for a senior producer, making it more prudent to buy an asset that's ready to go into production, rather than incur a liability with residual risk that isn't going to add anything to the bottom line for several years. 
  <br /> 
  <br /> 
  Thus the trend is for an exploration project tobe almost at feasibility before the senior takes the plunge and goes all in. This means there are some big deposits around that are nearly maxed out in terms of discovery value, and the only option left in their life is a takeover or production. 
  <br /> 
  <br /> 
  The process taken by management, to negotiate the maximum price for their shareholders, is countered by the cagey senior acquirers, seeking to get the additional ounces as cheaply as possible. Thus there is many a Mexican stand-off underway, with thesenior signaling that it doesn't really need deposits it is interested in right now, and advanced deposit holders posturing to go into production without the major. So you end up with companies going through the motions of putting a deposit into production when really, their preferred exit would be to hand it over to a senior. 
  <br /> 
  <br /> 
  Trying to figure out which way a deposit is going to go and when can cause migraines. Far better to take a position in an advanced explorer (for the reduced risk portion of your portfolio) and forget about it. The deal will happen when it happens, and in the case of precious metals deposits, the investment will continue to appreciate in value in relative lock step to the increasing prices of gold and silver. 
  <br /> 
  <br /> 
  Chicken Littles who running around screaming that gold is a bubble are correct, but irrelevant, as the popping of this bubble will not occur until currency and capital supply is brought to heel, which likely won't happen until the next major leg down of the now collapsing U.S. dollar bubble. The collapsing of this bubble is difficult to perceive, unlike say, the tech bubble. That's because Bamboozle Ben Bernanke keeps fabricating more dollars out of thin air. But it is collapsing none the less, and so perhaps in three or four more years, the G7 leadership will finally admit that the jig is up, the paper is worthless, and agree to a new global currency whose value is officially determined in part by the price of gold. 
  <br /> 
  <br /> 
  <br /> 
  Copyright 2011 Test xyz. All rights reserved. 
  </body>
  </html>
  </DataContent>
  </ContentItem>
  </NewsComponent>
  </NewsComponent>
  </NewsItem>
  </NewsML>

Open in new window

Avatar of saloj

ASKER

Hi Kaufmed,
is my question puzzled you? let me know if i need to more clarify.

my xml is on this format http:#26702289 but want to display on this format http:#34473934