本文介绍了在 C# 中更改 xml 元素值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改元素值,例如我想更改 cbc: ProfileID, cbc: ID schemeID="VKN">1288331521 </cbc:ID >, Papatya Caddesi Yasemin Sokak

i want to change element values for example i want to change cbc: ProfileID, cbc: ID schemeID="VKN">1288331521 < /cbc:ID >, < cbc: StreetName>Papatya Caddesi Yasemin Sokak< /cbc: StreetName>

我该怎么做?

这是我的xml文件

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="general.xslt"?>
<Invoice xsi:schemaLocation="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2 ../xsdrt/maindoc/UBL-Invoice-2.1.xsd" xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:n4="http://www.altova.com/samplexml/other-namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2">
    <ext:UBLExtensions>
        <ext:UBLExtension>
            <ext:ExtensionContent>
                <n4:auto-generated_for_wildcard/>
            </ext:ExtensionContent>
        </ext:UBLExtension>
    </ext:UBLExtensions>
    <cbc:UBLVersionID>2.1</cbc:UBLVersionID>
    <cbc:CustomizationID>TR1.2</cbc:CustomizationID>
    <cbc:ProfileID>TEMELFATURA</cbc:ProfileID>
    <cbc:ID>GIB20090000000001</cbc:ID>
    <cbc:CopyIndicator>false</cbc:CopyIndicator>
    <cbc:UUID>F47AC10B-58CC-4372-A567-0E02B2C3D479</cbc:UUID>
    <cbc:IssueDate>2009-01-05</cbc:IssueDate>
    <cbc:IssueTime>14:42:00</cbc:IssueTime>
    <cbc:InvoiceTypeCode>SATIS</cbc:InvoiceTypeCode>
    <cbc:DocumentCurrencyCode>TRY</cbc:DocumentCurrencyCode>
    <cbc:LineCountNumeric>1</cbc:LineCountNumeric>
    <cac:InvoicePeriod>
        <cbc:StartDate>2008-12-05</cbc:StartDate>
        <cbc:EndDate>2009-01-05</cbc:EndDate>
    </cac:InvoicePeriod>
    <cac:Signature>
        <cbc:ID schemeID="VKN_TCKN">1288331521</cbc:ID>
        <cac:SignatoryParty>
            <cac:PartyIdentification>
                <cbc:ID schemeID="VKN">1288331521</cbc:ID>
            </cac:PartyIdentification>
            <cac:PostalAddress>
                <cbc:StreetName>Papatya Caddesi Yasemin Sokak</cbc:StreetName>
                <cbc:BuildingNumber>21</cbc:BuildingNumber>
                <cbc:CitySubdivisionName>Beşiktaş</cbc:CitySubdivisionName>
                <cbc:CityName>İstanbul</cbc:CityName>
                <cbc:PostalZone>34100</cbc:PostalZone>
                <cac:Country>
                    <cbc:Name>Türkiye</cbc:Name>
                </cac:Country>
            </cac:PostalAddress>
        </cac:SignatoryParty>
        <cac:DigitalSignatureAttachment>
            <cac:ExternalReference>
                <cbc:URI>#Signature</cbc:URI>
            </cac:ExternalReference>
        </cac:DigitalSignatureAttachment>
    </cac:Signature>
    <cac:AccountingSupplierParty>
        <cac:Party>
            <cbc:WebsiteURI>http://www.aaa.com.tr/</cbc:WebsiteURI>
            <cac:PartyIdentification>
                <cbc:ID schemeID="VKN">1288331521</cbc:ID>
            </cac:PartyIdentification>
            <cac:PartyName>
                <cbc:Name>AAA Anonim Şirketi</cbc:Name>
            </cac:PartyName>
            <cac:PostalAddress>
                <cbc:ID>1234567890</cbc:ID>
                <cbc:StreetName>Papatya Caddesi Yasemin Sokak</cbc:StreetName>
                <cbc:BuildingNumber>21</cbc:BuildingNumber>
                <cbc:CitySubdivisionName>Beşiktaş</cbc:CitySubdivisionName>
                <cbc:CityName>İstanbul</cbc:CityName>
                <cbc:PostalZone>34100</cbc:PostalZone>
                <cac:Country>
                    <cbc:Name>Türkiye</cbc:Name>
                </cac:Country>
            </cac:PostalAddress>
            <cac:PartyTaxScheme>
                <cac:TaxScheme>
                    <cbc:Name>Büyük Mükellefler</cbc:Name>
                </cac:TaxScheme>
            </cac:PartyTaxScheme>
            <cac:Contact>
                <cbc:Telephone>(212) 925 51515</cbc:Telephone>
                <cbc:Telefax>(212) 925505015</cbc:Telefax>
                <cbc:ElectronicMail>[email protected]</cbc:ElectronicMail>
            </cac:Contact>
        </cac:Party>
    </cac:AccountingSupplierParty>
    <cac:AccountingCustomerParty>
        <cac:Party>
            <cbc:WebsiteURI/>
            <cac:PartyIdentification>
                <cbc:ID schemeID="TCKN">1234567890</cbc:ID>
            </cac:PartyIdentification>
            <cac:PartyIdentification>
                <cbc:ID schemeID="TESISATNO">1234567</cbc:ID>
            </cac:PartyIdentification>
            <cac:PartyIdentification>
                <cbc:ID schemeID="SAYACNO">12345678</cbc:ID>
            </cac:PartyIdentification>
            <cac:PostalAddress>
                <cbc:ID>ATATÜRK MAH.</cbc:ID>
                <cbc:Room>1</cbc:Room>
                <cbc:StreetName>6. Sokak</cbc:StreetName>
                <cbc:BuildingNumber>1</cbc:BuildingNumber>
                <cbc:CitySubdivisionName>Beşiktaş</cbc:CitySubdivisionName>
                <cbc:CityName>İstanbul</cbc:CityName>
                <cbc:PostalZone>34100</cbc:PostalZone>
                <cac:Country>
                    <cbc:Name>Türkiye</cbc:Name>
                </cac:Country>
            </cac:PostalAddress>
            <cac:Contact>
                <cbc:ElectronicMail>[email protected]</cbc:ElectronicMail>
            </cac:Contact>
            <cac:Person>
                <cbc:FirstName>Ali</cbc:FirstName>
                <cbc:FamilyName>YILMAZ</cbc:FamilyName>
            </cac:Person>
        </cac:Party>
    </cac:AccountingCustomerParty>
    <cac:PaymentTerms>
        <cbc:Note>BBB Bank Otomatik Ödeme</cbc:Note>
        <cbc:PaymentDueDate>2009-01-20</cbc:PaymentDueDate>
    </cac:PaymentTerms>
    <cac:TaxTotal>
        <cbc:TaxAmount currencyID="TRY">2.73</cbc:TaxAmount>
        <cac:TaxSubtotal>
            <cbc:TaxableAmount currencyID="TRY">15.15</cbc:TaxableAmount>
            <cbc:TaxAmount currencyID="TRY">2.73</cbc:TaxAmount>
            <cac:TaxCategory>
                <cac:TaxScheme>
                    <cbc:TaxTypeCode>0015</cbc:TaxTypeCode>
                </cac:TaxScheme>
            </cac:TaxCategory>
        </cac:TaxSubtotal>
    </cac:TaxTotal>
    <cac:LegalMonetaryTotal>
        <cbc:LineExtensionAmount currencyID="TRY">15.15</cbc:LineExtensionAmount>
        <cbc:TaxExclusiveAmount currencyID="TRY">15.15</cbc:TaxExclusiveAmount>
        <cbc:TaxInclusiveAmount currencyID="TRY">17.88</cbc:TaxInclusiveAmount>
        <cbc:PayableAmount currencyID="TRY">17.88</cbc:PayableAmount>
    </cac:LegalMonetaryTotal>
    <cac:InvoiceLine>
        <cbc:ID>1</cbc:ID>
        <cbc:InvoicedQuantity unitCode="KWH">101</cbc:InvoicedQuantity>
        <cbc:LineExtensionAmount currencyID="TRY">15.15</cbc:LineExtensionAmount>
        <cac:AllowanceCharge>
            <cbc:ChargeIndicator>false</cbc:ChargeIndicator>
            <cbc:MultiplierFactorNumeric>0.0</cbc:MultiplierFactorNumeric>
            <cbc:Amount currencyID="TRY">0</cbc:Amount>
            <cbc:BaseAmount currencyID="TRY">15.15</cbc:BaseAmount>
        </cac:AllowanceCharge>
        <cac:TaxTotal>
            <cbc:TaxAmount currencyID="TRY">2.73</cbc:TaxAmount>
            <cac:TaxSubtotal>
                <cbc:TaxableAmount currencyID="TRY">15.15</cbc:TaxableAmount>
                <cbc:TaxAmount currencyID="TRY">2.73</cbc:TaxAmount>
                <cbc:Percent>18.0</cbc:Percent>
                <cac:TaxCategory>
                    <cac:TaxScheme>
                        <cbc:Name>KDV</cbc:Name>
                        <cbc:TaxTypeCode>0015</cbc:TaxTypeCode>
                    </cac:TaxScheme>
                </cac:TaxCategory>
            </cac:TaxSubtotal>
        </cac:TaxTotal>
        <cac:Item>
            <cbc:Name>Elektrik Tüketim Bedeli</cbc:Name>
        </cac:Item>
        <cac:Price>
            <cbc:PriceAmount currencyID="TRY">0.15</cbc:PriceAmount>
        </cac:Price>
    </cac:InvoiceLine>
</Invoice>

推荐答案

试试看:

var document = new XmlDocument();
document.Load("d:\\xmlfile.xml"); //or use LoadXml for a xml string
document.ChildNodes[2]["cbc:ProfileID"].InnerXml = "Foo value";

PS: "cbc:ProfileID" 这只是一个例子.您可以使用其他属性.

PS: "cbc:ProfileID" it's just a example. You can use other properties.

这篇关于在 C# 中更改 xml 元素值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 11:54