2017-04-03 98 views
0

喜以下XML是該XML我需要單獨刪除根標籤我輸入XML如何刪除根標籤的XML C#

<?xml version="1.0" encoding="utf-8"?> 
     <units xmlns="http://www.elsevier.com/xml/ani/ani" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ce="http://www.elsevier.com/xml/ani/common" xsi:schemaLocation="http://www.elsevier.com/xml/ani/ani http://www.elsevier.com/xml/ani/ani512-input-CAR.xsd"> 
<unit type="journal" xmlns=""> 
<unit-info> 
    <timestamp>2017-01-08T02:03:14Z</timestamp> 
    <order-id>12535892</order-id> 
    <parcel-id>none</parcel-id> 
    <unit-id>4756202</unit-id> 
</unit-info> 
<unit-content> 
    <bibrecord> 
    <item-info> 
     <status state="new" stage="S300" /> 
    </item-info> 
    <head> 
     <citation-info> 
     <citation-type code="jo" /> 
     <citation-language xmllang="ENG" /> 
     <abstract-language xmllang="ENG" /> 
     <author-keywords> 
      <author-keyword>Stroke</author-keyword> 
      <author-keyword> cerebral ischaemia</author-keyword> 
      <author-keyword> Neuro-protection</author-keyword> 
      <author-keyword> Neuro-protective agents</author-keyword> 
     </author-keywords> 
     </citation-info> 
     <citation-title xmllang="ENG" original="y"> 
     <titletext>PATHOGENESIS AND NEURO-PROTECTIVE AGENTS OF STROKE</titletext> 
     </citation-title> 
     <abstracts> 
     <abstract> 
      <cepara>ABSTRACT: Stroke remains worlds second leading cause of mortality; and globally most frequent cause of long-lasting disabilities. The ischaemic pathophysiologic cascade leading to neuronal damage consists of peri-infarct depolarization, excitotoxicity, inflammation, oxidative stress, and apoptosis. Despite plethora of experimental evidences and advancement into the development of treatments, clinical treatment of acute stroke still remains challenging. Neuro-protective agents, as novel therapeutic strategy confer neuro-protection by targeting the pathophysiologic mechanism of stroke. The aim of this review is discussion of summary of the literature on stroke pathophysiology, current preclinical research findings of neuroprotective agents in stroke and possible factors that were responsible for the failure of these agents to translate in human stroke therapies.</cepara> 
     </abstract> 
     </abstracts> 
     <correspondence> 
     <person> 
      <ceinitials>M.</ceinitials> 
      <cesurname>Mubarak</cesurname> 
     </person> 
     <affiliation> 
      <organization> Bayero University Kano</organization> 
      <organization> Nigeria. Email: [email protected]</organization> 
     </affiliation> 
     </correspondence> 
     <root> 
     <author Seq="0"> 
      <Inital>A.El</Inital> 
      <Surname>Khattabi</Surname> 
      <Givenname>Abdelkrim</Givenname> 
     </author> 
     </root> 
    </head> 
    </bibrecord> 
</unit-content> 

,但我需要所有的子元素

 <author Seq="0"> 
      <Inital>A.El</Inital> 
      <Surname>Khattabi</Surname> 
      <Givenname>Abdelkrim</Givenname> 
     </author> 

如何單獨刪除根標籤。爲此,我遵循以下代碼

XDocument CarXML = new XDocument(); 
     CarXML.Add(Root); 
     CarXML.Descendants("root").Remove(); 
     CarXML.Save(@"CAR.XML"); 

但此代碼刪除所有xml標記。如何單獨刪除根元素。我需要的子元素

+1

可能的重複[如何刪除C#中的根元素/](http://stackoverflow.com/questions/17503619/how-to-remove-root-element-in-c) –

回答

0
CarXML.ReplaceNodes(CarXML.Descendants("author").FirstOrDefault()); 

這取代了XML的名爲author第一傳人的全部內容。