EN
Ce contenu n’est pas disponible dans votre langue. Voici la version anglaise.
Ce sujet n'a pas encore été évalué - Évaluez ce sujet

XmlWriter.WriteAttributeString Method (String, String)

April 12, 2014

When overridden in a derived class, writes out the attribute with the specified local name and value.

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)
public void WriteAttributeString(
	string localName,
	string value
)

Parameters

localName
Type: System.String
The local name of the attribute.
value
Type: System.String
The value of the attribute.
ExceptionCondition
InvalidOperationException

The state of writer is not WriteState.Element or writer is closed.

ArgumentException

The xml:space or xml:lang attribute value is invalid.

WriteAttributeString does the following:

  • If the attribute value includes double or single quotes, they are replaced with " and ' respectively.

  • If writing an xml:space attribute, the writer verifies the attribute value is valid. (Valid values are preserve or default.)

  • If writing an xml:lang attribute, the writer does not verify that the attribute value is valid according to the W3C XML 1.0 recommendation.



StringBuilder output = new StringBuilder();

XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
using (XmlWriter writer = XmlWriter.Create(output, settings))
{
    // Write the root element.
    writer.WriteStartElement("order");

    // Write an element with attributes.
    writer.WriteStartElement("item");
    writer.WriteAttributeString("date", "2/19/01");
    writer.WriteAttributeString("orderID", "136A5");

    // Write a full end element. Because this element has no
    // content, calling WriteEndElement would have written a
    // short end tag '/>'.
    writer.WriteFullEndElement();

    writer.WriteEndElement();

    // Write the XML to file and close the writer
}


OutputTextBlock.Text = output.ToString();


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Cela vous a-t-il été utile ?
(1500 caractères restants)
Merci pour vos suggestions.
Afficher:
© 2014 Microsoft. Tous droits réservés.