Hinzufügen von Knoten und Elementen in xml mit C#/Linq

Habe ich eine xml Datei wie diese,

<?xml version="1.0" encoding="utf-8" ?>
<root>  
  <FeaturedProductCategories>
    <FeaturedProductCategory>
      <FeaturedProducts>
        <FeaturedProduct>
          <ContentSelector datavalue_idtype="content:smartform" datavalue_displayvalue="«Smart Form:49»">49</ContentSelector>
        </FeaturedProduct>
      </FeaturedProducts>
    </FeaturedProductCategory>
  </FeaturedProductCategories>
</root>

Ich möchte es ändern, wie unter,

<?xml version="1.0" encoding="utf-8" ?>
<root>
  <Title>HomePage</Title>
  <FeaturedProductCategories>
    <FeaturedProductCategory>
      <FeaturedProducts>
        <FeaturedProduct>
          <Products>
            <Product>
              <ProductTitle>Product</ProductTitle>
              <ProductDate>03-08-2012 11:57:25</ProductDate>
              <ProductImage>
                <img src="ex1.jpg" />
              </ProductImage>
              <ProductThumbnailImage>
                <img src="ex2.jpg" />
              </ProductThumbnailImage>
              <ProductCaption>Product Caption</ProductCaption>
              <ProductImage>
                <img src="ex3.jpg" />
              </ProductImage>
              <ProductThumbnailImage>
                <img src="ex4.jpg" />
              </ProductThumbnailImage>
              <ProductCaption>Product Caption</ProductCaption>
            </Product>
          </Products>
        </FeaturedProduct>
      </FeaturedProducts>
    </FeaturedProductCategory>
  </FeaturedProductCategories>
</root>

Alle neuen Knoten und Werte ergänzt werden durch eine C# - Funktion. Lassen Sie uns annehmen, diese neuen Werte als statische Werte für jetzt.

Auch der Knoten "FeaturedProduct" ist nicht nur eine. Es gibt eine Menge von Knoten, die in diesem Namen. Ich möchte zum ändern der "FeaturedProduct" Knoten.

  • Cool. Also, was ist Ihre Frage?
  • Ich will den xml-Code ändern, wie gezeigt. Könnten Sie bitte empfehlen Sie mir, wie es zu tun?
Schreibe einen Kommentar