2017-10-14 59 views
2

如何使用後代方法將節點的內容從一個文件替換爲另一個文件。 我試過在c#中使用Descendants方法修改節點值?

XDocument refFile = Xdocument.Load(@"D:\MyPrjocets\Data\dt.xml"); 
       var content = (from v in refFile.Descendants("lbl") 
          select v).First().Value; 
       XDocument file2modify = Xdocument.Load(@"D:\14.10.2017\xyz.xml"); 
       file2modify.Descendants("label").First().SetElementValue("label",content); 
       file2modify.Save(@"D:\14.10.2017\xyz.xml"); 

但數據被修改,像<label>(1)<label>A.</label></label>它應該像<label>A.</label>即其追加到節點不刪除與新的前值。我該如何解決? 的refFile是結構像

<?xml version="1.0" encoding="utf-8"?> 
    <metadata> 
     <abstract> 
     <lbl>A.</lbl> 
     <p>Ram is a good boy</p> 
     <doi-x>10.14/10.317.1</doi-x> 
     <author type="address"> 
      <Street>7A Cox Street</Street> 
      <City>Acampo</City> 
      <State>CA</State> 
      <Zip>95220</Zip> 
      <Country>USA</Country> 
     </author> 
........ ......... 
     </abstract> 
    </metadata> 

和file2modify就像

<?xml version="1.0" encoding="utf-8"?> 
<!DOCTYPE article PUBLIC "-//NLM//DTD Journal Publishing DTD v3.0 20080202//EN" 
"journalpublishing3.dtd"> 
<article 
article-type="research-article" 
dtd-version="3.0" xml:lang="en" 
xmlns:mml="http://www.w3.org/1998/Math/MathML" 
xmlns:xlink="http://www.w3.org/1999/xlink" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
> 
<front> 
<journal-meta> 
<journal-id journal-id-type="pmc">pnas</journal-id> 
<journal-id journal-id-type="pubmed">Proc Natl Acad Sci U S A</journal-id> 
<journal-id journal-id-type="publisher">PNAS</journal-id> 
<issn>0027-8424</issn> 
<publisher> 
<publisher-name>The National Academy of Sciences</publisher-name> 
</publisher> 
</journal-meta> 
<article-meta> 
<article-id pub-id-type="publisher-id">181325198</article-id> 
<article-id pub-id-type="publisher-id">3251</article-id> 
<article-id pub-id-type="doi">10.1073/pnas.181325198</article-id> 
<title-group> 
<article-title>The coreceptor mutation CCR5&#x0394;32 influences the dynamics of HIV epidemics and is selected for by HIV</article-title> 
</title-group> 
<contrib-group> 
<contrib contrib-type="author"> 
<name> 
<surname>Sullivan</surname> 
<given-names>Amy D.</given-names> 
</name> 
<xref ref-type="author-notes" rid="FN150">&#x002A;</xref> 
</contrib> 
<contrib contrib-type="author"> 
<name> 
<surname>Wigginton</surname> 
<given-names>Janis</given-names> 
</name> 
</contrib> 
</contrib-group> 
<aff>Department of Microbiology and Immunology, University of Michigan Medical School, Ann Arbor, MI 48109-0620</aff> 
<author-notes> 
<fn id="FN150"> 
<p>&#x002A; Present address: Centers for Disease Control and Prevention Epidemiology Program Office, State Branch Oregon Health Division, 800 NE Oregon Street, Suite 772, Portland, OR 97232.</p> 
</fn> 
<fn fn-type="com"> 
<p>Communicated by Avner Friedman, University of Minnesota, Minneapolis, MN</p> 
</fn> 
</author-notes> 
<pub-date pub-type="pub"> 
<day>28</day> 
<month>8</month> 
<year>2001</year> 
</pub-date> 
<pub-date pub-type="epub"> 
<day>21</day> 
<month>8</month> 
<year>2001</year> 
</pub-date> 
<volume>98</volume> 
<issue>18</issue> 
<fpage>10214</fpage> 
<lpage>10219</lpage> 
<history> 
<date date-type="received"> 
<day>30</day> 
<month>5</month> 
<year>2000</year> 
</date> 
</history> 
<permissions> 
<copyright-statement>Copyright &#x00A9; 2001, The National Academy of Sciences</copyright-statement> 
<copyright-year>2001</copyright-year> 
</permissions> 
<abstract> 
<label>(1)</label> 
<p>We explore the impact of a host genetic factor on heterosexual HIV epidemics by using a deterministic mathematical model. A protective allele unequally distributed across populations is exemplified in our models by the 32-bp deletion in the host-cell chemokine receptor CCR5, CCR5&#x0394;32. Individuals homozygous for CCR5&#x0394;32 are protected against HIV infection whereas those heterozygous for CCR5&#x0394;32 have lower pre-AIDS viral loads and delayed progression to AIDS. CCR5&#x0394;32 may limit HIV spread by decreasing the probability of both risk of infection and infectiousness. In this work, we characterize epidemic HIV within three dynamic subpopulations: CCR5&#x002F;CCR5 (homozygous, wild type), CCR5&#x002F;CCR5&#x0394;32 (heterozygous), and CCR5&#x0394;32&#x002F;CCR5&#x0394;32 (homozygous, mutant). Our results indicate that prevalence of HIV&#x002F;AIDS is greater in populations lacking the CCR5&#x0394;32 alleles (homozygous wild types only) as compared with populations that include people heterozygous or homozygous for CCR5&#x0394;32. Also, we show that HIV can provide selective pressure for CCR5&#x0394;32, increasing the frequency of this allele.</p> 
</abstract> 
<counts> 
<fig-count count="15"/> 
<table-count count="11"/> 
<equation-count count="5"/> 
<page-count count="1"/> 
</counts> 
</article-meta> 
</front> 
<body> 
<p>Nineteen million people have died of AIDS since the discovery of HIV in the 1980s. In 1999 alone, 5.4 million people were newly infected with HIV (ref. <xref ref-type="bibr" rid="B1">1</xref> and <ext-link ext-link-type="url" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.unaids.org/epidemicupdate/report/Epireport.html">http://www.unaids.org/epidemicupdate/report/Epireport.html</ext-link>). (For brevity, HIV-1 is referred to as HIV in this paper.) Sub-Saharan Africa has been hardest hit, with more than 20&#x0025; of the general population HIV-positive in some countries (<xref ref-type="bibr" rid="B2">2</xref>, <xref ref-type="bibr" rid="B3">3</xref>). In comparison, heterosexual epidemics in developed, market-economy countries have not reached such severe levels. Factors contributing to the severity of the epidemic in economically developing countries abound, including economic, health, and social differences such as high levels of sexually transmitted diseases and a lack of prevention programs. However, the staggering rate at which the epidemic has spread in sub-Saharan Africa has not been adequately explained. The rate and severity of this epidemic also could indicate a greater underlying susceptibility to HIV attributable not only to sexually transmitted disease, economics, etc., but also to other more ubiquitous factors such as host genetics (<xref ref-type="bibr" rid="B4">4</xref>, <xref ref-type="bibr" rid="B5">5</xref>).</p> 
<p>To exemplify the contribution of such a host genetic factor to HIV prevalence trends, we consider a well-characterized 32-bp deletion in the host-cell chemokine receptor CCR5, CCR5&#x0394;32. When HIV binds to host cells, it uses the CD4 receptor on the surface of host immune cells together with a coreceptor, mainly the CCR5 and CXCR4 chemokine receptors (<xref ref-type="bibr" rid="B6">6</xref>). Homozygous mutations for this 32-bp deletion offer almost complete protection from HIV infection, and heterozygous mutations are associated with lower pre-AIDS viral loads and delayed progression to AIDS (<xref ref-type="bibr" rid="B7">7</xref>&#x2013;<xref ref-type="bibr" rid="B14">14</xref>). CCR5&#x0394;32 generally is found in populations of European descent, with allelic frequencies ranging from 0 to 0.29 (<xref ref-type="bibr" rid="B13">13</xref>). African and Asian populations studied outside the United States or Europe appear to lack the CCR5&#x0394;32 allele, with an allelic frequency of almost zero (<xref ref-type="bibr" rid="B5">5</xref>, <xref ref-type="bibr" rid="B13">13</xref>). Thus, to understand the effects of a protective allele, we use a mathematical model to track prevalence of HIV in populations with or without CCR5&#x0394;32 heterozygous and homozygous people and also to follow the CCR5&#x0394;32 allelic frequency 
<fig id="fig1"> 
<caption><p>HD tv</p></caption> 
</fig>.</p> 
<p>We hypothesize that CCR5&#x0394;32 limits epidemic HIV by decreasing infection rates, and we evaluate the relative contributions to this by the probability of infection and duration of infectivity. To capture HIV infection as a chronic infectious disease together with vertical transmission occurring in untreated mothers, we model a dynamic population (i.e., populations that vary in growth rates because of fluctuations in birth or death rates) based on realistic demographic characteristics (<xref ref-type="bibr" rid="B18">18</xref>). This scenario also allows tracking of the allelic frequencies over time. This work considers how a specific host genetic factor affecting HIV infectivity and viremia at the individual level might influence the epidemic in a dynamic population and how HIV exerts selective pressure, altering the frequency of this mutant allele.</p> 
</body> 
</article> 

回答

2

你可以簡單地代替更新XElement.Value屬性:

... 
file2modify.Descendants("label").First().Value = content; 
file2modify.Save(@"D:\14.10.2017\xyz.xml"); 
+0

感謝您的答覆。順便說一句,我怎樣才能爲'Descendants'定義一個'Ancestor',以便更精確地導航到名爲**標籤**' –

+0

'file2modify.Descendants(「some-ancestor」)的節點。後代(「label」).. .' – har07

相關問題