本文整理汇总了C#中System.Xml.XmlWriter.LookupPrefix方法的典型用法代码示例。如果您正苦于以下问题:C# XmlWriter.LookupPrefix方法的具体用法?C# XmlWriter.LookupPrefix怎么用?C# XmlWriter.LookupPrefix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlWriter
的用法示例。
在下文中一共展示了XmlWriter.LookupPrefix方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteXmlSchemaType
public override void WriteXmlSchemaType(XmlWriter xw, string xmlns)
{
xw.WriteStartElement("complexType", XmlSchemaUtil.SCHEMA_NS);
if (Name != null) xw.WriteAttributeString("name", Name);
xw.WriteStartElement("sequence", XmlSchemaUtil.SCHEMA_NS);
foreach (MemberDef member in Members)
{
xw.WriteStartElement("element", XmlSchemaUtil.SCHEMA_NS);
xw.WriteAttributeString("name", member.Name);
TypeDef td = ParentTypeSet.GetTypeDef(member.TypeName);
if (td.IsSimpleType)
{
xw.WriteAttributeString("type", "xs:" + td.Name);
if (member.IsRequired)
xw.WriteAttributeString("nillable", "false");
}
else
{
if (string.IsNullOrEmpty(xmlns))
xw.WriteAttributeString("type", td.Name);
else
{
string prf = xw.LookupPrefix(xmlns);
xw.WriteAttributeString("type", string.Format("{0}:{1}", prf, td.Name));
}
}
xw.WriteAttributeString("minOccurs", member.IsRequired ? "1" : "0");
xw.WriteAttributeString("maxOccurs", member.IsArray ? "unbounded" : "1");
xw.WriteEndElement();
}
xw.WriteEndElement();
xw.WriteEndElement();
}
示例2: ToQName
internal static string ToQName(this PrintSchemaName self, XmlWriter writer)
{
var prefix = writer.LookupPrefix(self.NamespaceName);
if (prefix == null)
{
throw new InternalException($"Namespace declaration not found: {self.Namespace}");
}
else if (prefix == string.Empty)
{
return self.LocalName;
}
else
{
return prefix + ":" + self.LocalName;
}
}
示例3: WriteTo
/// <summary>
/// Saves the current node to the specified XmlWriter.
/// </summary>
/// <param name="xmlWriter">
/// The XmlWriter to which to save the current node.
/// </param>
public override void WriteTo(XmlWriter xmlWriter)
{
if (xmlWriter == null)
{
throw new ArgumentNullException("xmlWriter");
}
if (this.XmlParsed)
{
//check the namespace mapping defined in this node first. because till now xmlWriter don't know the mapping defined in the current node.
string prefix = LookupNamespaceLocal(this.NamespaceUri);
//if not defined in the current node, try the xmlWriter
if (this.Parent != null && string.IsNullOrEmpty(prefix))
{
prefix = xmlWriter.LookupPrefix(this.NamespaceUri);
}
//if xmlWriter didn't find it, it means the node is constructed by user and is not in the tree yet
//in this case, we use the predefined prefix
if (string.IsNullOrEmpty(prefix))
{
prefix = NamespaceIdMap.GetNamespacePrefix(this.NamespaceId);
}
xmlWriter.WriteStartElement(prefix, this.LocalName, this.NamespaceUri);
// fix bug #225919, write out all namespace into to root
WriteNamespaceAtributes(xmlWriter);
this.WriteAttributesTo(xmlWriter);
if (this.HasChildren || !string.IsNullOrEmpty(this.InnerText))
{
this.WriteContentTo(xmlWriter);
xmlWriter.WriteFullEndElement();
}
else
{
xmlWriter.WriteEndElement();
}
}
else
{
xmlWriter.WriteRaw(this.RawOuterXml);
}
}
示例4: WriteContentTo
void WriteContentTo (XmlWriter writer)
{
if (writer.LookupPrefix (Namespaces.Atom10) == null)
writer.WriteAttributeString ("xmlns", "a10", Namespaces.Xmlns, Namespaces.Atom10);
if (writer.LookupPrefix (Version) == null)
writer.WriteAttributeString ("xmlns", "app", Namespaces.Xmlns, Version);
// xml:lang, xml:base, workspace*
if (Document.Language != null)
writer.WriteAttributeString ("xml", "lang", Namespaces.Xml, Document.Language);
if (Document.BaseUri != null)
writer.WriteAttributeString ("xml", "base", Namespaces.Xml, Document.BaseUri.ToString ());
Document.WriteAttributeExtensions (writer, Version);
Document.WriteElementExtensions (writer, Version);
foreach (var ws in Document.Workspaces) {
writer.WriteStartElement ("app", "workspace", Version);
// xml:base, title, collection*
if (ws.BaseUri != null)
writer.WriteAttributeString ("xml", "base", Namespaces.Xml, ws.BaseUri.ToString ());
ws.WriteAttributeExtensions (writer, Version);
ws.WriteElementExtensions (writer, Version);
if (ws.Title != null)
ws.Title.WriteTo (writer, "title", Namespaces.Atom10);
foreach (var rc in ws.Collections) {
writer.WriteStartElement ("app", "collection", Version);
// accept*, xml:base, category, @href, title
if (rc.BaseUri != null)
writer.WriteAttributeString ("xml", "base", Namespaces.Xml, rc.BaseUri.ToString ());
if (rc.Link != null)
writer.WriteAttributeString ("href", rc.Link.ToString ());
rc.WriteAttributeExtensions (writer, Version);
if (rc.Title != null)
rc.Title.WriteTo (writer, "title", Namespaces.Atom10);
foreach (var s in rc.Accepts) {
writer.WriteStartElement ("app", "accept", Version);
writer.WriteString (s);
writer.WriteEndElement ();
}
foreach (var cat in rc.Categories)
cat.Save (writer);
writer.WriteEndElement ();
}
writer.WriteEndElement ();
}
}
示例5: WriteTo
/// <summary>
/// Saves the current <see cref="AtomTextConstruct"/> to the specified <see cref="XmlWriter"/>.
/// </summary>
/// <param name="writer">The <see cref="XmlWriter"/> to which you want to save.</param>
/// <param name="elementName">The local name of the text construct being written.</param>
/// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
/// <exception cref="ArgumentNullException">The <paramref name="elementName"/> is a null reference (Nothing in Visual Basic).</exception>
/// <exception cref="ArgumentNullException">The <paramref name="elementName"/> is an empty string.</exception>
public void WriteTo(XmlWriter writer, string elementName)
{
//------------------------------------------------------------
// Validate parameter
//------------------------------------------------------------
Guard.ArgumentNotNull(writer, "writer");
Guard.ArgumentNotNullOrEmptyString(elementName, "elementName");
//------------------------------------------------------------
// Write XML representation of the current instance
//------------------------------------------------------------
writer.WriteStartElement(elementName, AtomUtility.AtomNamespace);
AtomUtility.WriteCommonObjectAttributes(this, writer);
if (this.TextType == AtomTextConstructType.Xhtml && String.IsNullOrEmpty(writer.LookupPrefix(AtomUtility.XhtmlNamespace)))
{
writer.WriteAttributeString("xmlns", "xhtml", null, AtomUtility.XhtmlNamespace);
}
if (this.TextType != AtomTextConstructType.None)
{
writer.WriteAttributeString("type", AtomTextConstruct.ConstructTypeAsString(this.TextType));
}
if (this.TextType == AtomTextConstructType.Xhtml)
{
writer.WriteStartElement("div", AtomUtility.XhtmlNamespace);
writer.WriteString(this.Content);
writer.WriteEndElement();
}
else
{
writer.WriteString(this.Content);
}
//------------------------------------------------------------
// Write the syndication extensions of the current instance
//------------------------------------------------------------
SyndicationExtensionAdapter.WriteExtensionsTo(this.Extensions, writer);
writer.WriteEndElement();
}
示例6: AddOtherNamespaces
/// <summary>
/// add the spreadsheet NS
/// </summary>
/// <param name="writer">The XmlWrite, where we want to add default namespaces to</param>
protected override void AddOtherNamespaces(XmlWriter writer)
{
base.AddOtherNamespaces(writer);
if (writer == null)
{
throw new ArgumentNullException("writer");
}
string strPrefix = writer.LookupPrefix(GDataSpreadsheetsNameTable.NSGSpreadsheets);
if (strPrefix == null)
{
writer.WriteAttributeString("xmlns", GDataSpreadsheetsNameTable.Prefix, null, GDataSpreadsheetsNameTable.NSGSpreadsheets);
}
}
示例7: WriteStartElement
/// <summary>
/// Starts writing an element for the given DomNode</summary>
/// <param name="node">DomNode to write</param>
/// <param name="writer">The XML writer. See <see cref="T:System.Xml.XmlWriter"/></param>
protected void WriteStartElement(DomNode node, XmlWriter writer)
{
// It's possible to create DomNodes with no ChildInfo, and if the DomNode is never
// parented, then its ChildInfo property will still be null. We could try to search
// for a compatible root element in the m_typeCollection, but that's more code.
if (node.ChildInfo == null)
throw new InvalidOperationException(
"Please check your document's creation method to ensure that the root DomNode's" +
" constructor was given a ChildInfo.");
// writes the start of an element
m_elementNS = m_typeCollection.TargetNamespace;
int index = node.ChildInfo.Type.Name.LastIndexOf(':');
if (index >= 0)
m_elementNS = node.ChildInfo.Type.Name.Substring(0, index);
m_elementPrefix = string.Empty;
// is this the root DomNode (the one passed to Write)?
if (IsRootNode(node))
{
m_elementPrefix = m_typeCollection.GetPrefix(m_elementNS);
if (m_elementPrefix == null)
m_elementPrefix = GeneratePrefix(m_elementNS);
writer.WriteStartElement(m_elementPrefix, node.ChildInfo.Name, m_elementNS);
// define the xsi namespace
writer.WriteAttributeString("xmlns", "xsi", null, XmlSchema.InstanceNamespace);
// define schema namespaces
foreach (XmlQualifiedName name in m_typeCollection.Namespaces)
if (name.Name != m_elementPrefix) // don't redefine the element namespace
writer.WriteAttributeString("xmlns", name.Name, null, name.Namespace);
}
else
{
ChildInfo actualChildInfo = node.ChildInfo;
var substitutionGroupRule = node.ChildInfo.Rules.OfType<SubstitutionGroupChildRule>().FirstOrDefault();
if (substitutionGroupRule != null)
{
var substituteChildInfo = substitutionGroupRule.Substitutions.FirstOrDefault(x => x.Type == node.Type);
if (substituteChildInfo == null)
{
throw new InvalidOperationException("No suitable Substitution Group found for node " + node);
}
actualChildInfo = substituteChildInfo;
m_elementNS = m_typeCollection.TargetNamespace;
index = substituteChildInfo.Type.Name.LastIndexOf(':');
if (index >= 0)
m_elementNS = substituteChildInfo.Type.Name.Substring(0, index);
// It is possible that an element of this namspace has not
// yet been written. If the lookup fails then get the prefix from
// the type collection
m_elementPrefix = writer.LookupPrefix(m_elementNS);
if (m_elementPrefix == null)
{
m_elementPrefix = m_typeCollection.GetPrefix(m_elementNS);
}
}
else
{
// not the root, so all schema namespaces have been defined
m_elementPrefix = writer.LookupPrefix(m_elementNS);
}
if (m_elementPrefix == null)
m_elementPrefix = GeneratePrefix(m_elementNS);
writer.WriteStartElement(m_elementPrefix, actualChildInfo.Name, m_elementNS);
}
}
示例8: InvokeMethod
private void InvokeMethod(XmlWriter w, string methodName)
{
byte[] buffer = new byte[10];
switch (methodName)
{
case "WriteStartDocument":
w.WriteStartDocument();
break;
case "WriteStartElement":
w.WriteStartElement("root");
break;
case "WriteEndElement":
w.WriteEndElement();
break;
case "WriteStartAttribute":
w.WriteStartAttribute("attr");
break;
case "WriteEndAttribute":
w.WriteEndAttribute();
break;
case "WriteCData":
w.WriteCData("test");
break;
case "WriteComment":
w.WriteComment("test");
break;
case "WritePI":
w.WriteProcessingInstruction("name", "test");
break;
case "WriteEntityRef":
w.WriteEntityRef("e");
break;
case "WriteCharEntity":
w.WriteCharEntity('c');
break;
case "WriteSurrogateCharEntity":
w.WriteSurrogateCharEntity('\uDC00', '\uDBFF');
break;
case "WriteWhitespace":
w.WriteWhitespace(" ");
break;
case "WriteString":
w.WriteString("foo");
break;
case "WriteChars":
char[] charArray = new char[] { 'a', 'b', 'c', 'd' };
w.WriteChars(charArray, 0, 3);
break;
case "WriteRaw":
w.WriteRaw("<foo>bar</foo>");
break;
case "WriteBase64":
w.WriteBase64(buffer, 0, 9);
break;
case "WriteBinHex":
w.WriteBinHex(buffer, 0, 9);
break;
case "LookupPrefix":
string str = w.LookupPrefix("foo");
break;
case "WriteNmToken":
w.WriteNmToken("foo");
break;
case "WriteName":
w.WriteName("foo");
break;
case "WriteQualifiedName":
w.WriteQualifiedName("foo", "bar");
break;
case "WriteValue":
w.WriteValue(Int32.MaxValue);
break;
case "WriteAttributes":
XmlReader xr1 = ReaderHelper.Create(new StringReader("<root attr='test'/>"));
xr1.Read();
w.WriteAttributes(xr1, false);
break;
case "WriteNodeReader":
XmlReader xr2 = ReaderHelper.Create(new StringReader("<root/>"));
xr2.Read();
w.WriteNode(xr2, false);
break;
case "Flush":
w.Flush();
break;
default:
CError.Equals(false, "Unexpected param in testcase: {0}", methodName);
break;
}
}
示例9: WriteFaultCodeValue
private static void WriteFaultCodeValue(XmlWriter writer, XmlQualifiedName code, SoapFaultSubCode subcode) {
if (code == null) return;
writer.WriteStartElement(Soap12.Element.FaultCodeValue, Soap12.Namespace);
if (code.Namespace != null && code.Namespace.Length > 0 && writer.LookupPrefix(code.Namespace) == null)
writer.WriteAttributeString("xmlns", "q0", null, code.Namespace);
writer.WriteQualifiedName(code.Name, code.Namespace);
writer.WriteEndElement(); // </value>
if (subcode != null) {
writer.WriteStartElement(Soap12.Element.FaultSubcode, Soap12.Namespace);
WriteFaultCodeValue(writer, subcode.Code, subcode.SubCode);
writer.WriteEndElement(); // </subcode>
}
}
示例10: WriteXml
/// <summary>
/// Writes the internal data for this ContentLocator to the writer. This
/// method is used by an XmlSerializer to serialize a ContentLocator. Don't
/// use this method directly, to serialize a ContentLocator to Xml, use an
/// XmlSerializer.
/// </summary>
/// <param name="writer">the writer to write internal data to</param>
/// <exception cref="ArgumentNullException">writer is null</exception>
public void WriteXml(XmlWriter writer)
{
if (writer == null)
{
throw new ArgumentNullException("writer");
}
string prefix = writer.LookupPrefix(AnnotationXmlConstants.Namespaces.CoreSchemaNamespace);
if (prefix == null)
{
writer.WriteAttributeString(AnnotationXmlConstants.Prefixes.XmlnsPrefix, AnnotationXmlConstants.Prefixes.CoreSchemaPrefix, null, AnnotationXmlConstants.Namespaces.CoreSchemaNamespace);
}
prefix = writer.LookupPrefix(AnnotationXmlConstants.Namespaces.BaseSchemaNamespace);
if (prefix == null)
{
writer.WriteAttributeString(AnnotationXmlConstants.Prefixes.XmlnsPrefix, AnnotationXmlConstants.Prefixes.BaseSchemaPrefix, null, AnnotationXmlConstants.Namespaces.BaseSchemaNamespace);
}
// Write each ContentLocatorPart as its own element
foreach (ContentLocatorPart part in _parts)
{
prefix = writer.LookupPrefix(part.PartType.Namespace);
if (String.IsNullOrEmpty(prefix))
{
prefix = "tmp";
}
// ContentLocatorParts cannot write themselves out becuase the element
// name is based on the part's type. The ContentLocatorPart instance
// has no way (through normal serialization) to change the element
// name it writes out at runtime.
writer.WriteStartElement(prefix, part.PartType.Name, part.PartType.Namespace);
// Each name/value pair for the ContentLocatorPart becomes an attribute
foreach (KeyValuePair<string, string> pair in part.NameValuePairs)
{
writer.WriteStartElement(AnnotationXmlConstants.Elements.Item, AnnotationXmlConstants.Namespaces.CoreSchemaNamespace);
writer.WriteAttributeString(AnnotationXmlConstants.Attributes.ItemName, pair.Key);
writer.WriteAttributeString(AnnotationXmlConstants.Attributes.ItemValue, pair.Value);
writer.WriteEndElement();
}
writer.WriteEndElement();
}
}
示例11: WriteFault
internal override void WriteFault(XmlWriter writer, SoapException soapException, HttpStatusCode statusCode) {
if (statusCode != HttpStatusCode.InternalServerError)
return;
if (soapException == null)
return;
SoapServerMessage message = ServerProtocol.Message;
writer.WriteStartDocument();
writer.WriteStartElement(Soap.Prefix, Soap.Element.Envelope, Soap.Namespace);
writer.WriteAttributeString("xmlns", Soap.Prefix, null, Soap.Namespace);
writer.WriteAttributeString("xmlns", "xsi", null, XmlSchema.InstanceNamespace);
writer.WriteAttributeString("xmlns", "xsd", null, XmlSchema.Namespace);
if (ServerProtocol.ServerMethod != null)
SoapHeaderHandling.WriteHeaders(writer, ServerProtocol.ServerMethod.outHeaderSerializer, message.Headers, ServerProtocol.ServerMethod.outHeaderMappings, SoapHeaderDirection.Fault, ServerProtocol.ServerMethod.use == SoapBindingUse.Encoded, ServerType.serviceNamespace, ServerType.serviceDefaultIsEncoded, Soap.Namespace);
else
SoapHeaderHandling.WriteUnknownHeaders(writer, message.Headers, Soap.Namespace);
writer.WriteStartElement(Soap.Element.Body, Soap.Namespace);
writer.WriteStartElement(Soap.Element.Fault, Soap.Namespace);
writer.WriteStartElement(Soap.Element.FaultCode, "");
XmlQualifiedName code = TranslateFaultCode(soapException.Code);
if (code.Namespace != null && code.Namespace.Length > 0 && writer.LookupPrefix(code.Namespace) == null)
writer.WriteAttributeString("xmlns", "q0", null, code.Namespace);
writer.WriteQualifiedName(code.Name, code.Namespace);
writer.WriteEndElement();
// write faultString element with possible "lang" attribute
writer.WriteStartElement(Soap.Element.FaultString, "");
if (soapException.Lang != null && soapException.Lang.Length != 0) {
writer.WriteAttributeString("xml", Soap.Attribute.Lang, Soap.XmlNamespace, soapException.Lang);
}
writer.WriteString(ServerProtocol.GenerateFaultString(soapException));
writer.WriteEndElement();
// Only write an actor element if the actor was specified (it's optional for end-points)
string actor = soapException.Actor;
if (actor.Length > 0)
writer.WriteElementString(Soap.Element.FaultActor, "", actor);
// Only write a FaultDetail element if exception is related to the body (not a header)
if (!(soapException is SoapHeaderException)) {
if (soapException.Detail == null) {
//
writer.WriteStartElement(Soap.Element.FaultDetail, "");
writer.WriteEndElement();
}
else {
soapException.Detail.WriteTo(writer);
}
}
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndElement();
writer.Flush();
}
示例12: WriteAuthorityBinding
/// <summary>
/// Serialize a SamlAuthorityBinding.
/// </summary>
/// <param name="writer">XmlWriter to serialize the SamlAuthorityBinding</param>
/// <param name="authorityBinding">SamlAuthoriyBinding to be serialized.</param>
protected virtual void WriteAuthorityBinding(XmlWriter writer, SamlAuthorityBinding authorityBinding)
{
if (writer == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer");
}
if (authorityBinding == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("statement");
}
writer.WriteStartElement(SamlConstants.Prefix, SamlConstants.ElementNames.AuthorityBinding, SamlConstants.Namespace);
string prefix = null;
if (!string.IsNullOrEmpty(authorityBinding.AuthorityKind.Namespace))
{
writer.WriteAttributeString(String.Empty, SamlConstants.AttributeNames.NamespaceAttributePrefix, null, authorityBinding.AuthorityKind.Namespace);
prefix = writer.LookupPrefix(authorityBinding.AuthorityKind.Namespace);
}
writer.WriteStartAttribute(SamlConstants.AttributeNames.AuthorityKind, null);
if (string.IsNullOrEmpty(prefix))
{
writer.WriteString(authorityBinding.AuthorityKind.Name);
}
else
{
writer.WriteString(prefix + ":" + authorityBinding.AuthorityKind.Name);
}
writer.WriteEndAttribute();
writer.WriteAttributeString(SamlConstants.AttributeNames.Location, null, authorityBinding.Location);
writer.WriteAttributeString(SamlConstants.AttributeNames.Binding, null, authorityBinding.Binding);
writer.WriteEndElement();
}
示例13: WriteTo
public override void WriteTo(XmlWriter w)
{
string prefix = this.Prefix;
if (!string.IsNullOrEmpty(this.NamespaceURI))
prefix = w.LookupPrefix(this.NamespaceURI) ?? this.Prefix;
w.WriteStartElement(prefix, this.LocalName, this.NamespaceURI);
if (this.HasAttributes)
{
XmlAttributePreservingWriter preservingWriter = w as XmlAttributePreservingWriter;
if (preservingWriter == null || this.preservationDict == null)
this.WriteAttributesTo(w);
else
this.WritePreservedAttributesTo(preservingWriter);
}
if (this.IsEmpty)
{
w.WriteEndElement();
}
else
{
this.WriteContentTo(w);
w.WriteFullEndElement();
}
}
示例14: WriteTypeQualifier
private void WriteTypeQualifier(XmlWriter writer, ITypeSerializationInfo type)
{
if (type.NamespacePrefix != null)
{
if (writer.LookupPrefix(type.Namespace) != type.NamespacePrefix)
{
writer.WriteAttributeString("xmlns", type.NamespacePrefix, null, type.Namespace);
}
writer.WriteAttributeString(XMLSchemaInstancePrefix, TypeField, XMLSchemaInstanceNamespace,
type.NamespacePrefix + ":" + type.ElementName);
}
else
{
writer.WriteStartAttribute(XMLSchemaInstancePrefix, TypeField, XMLSchemaInstanceNamespace);
writer.WriteQualifiedName(type.ElementName, type.Namespace);
writer.WriteEndAttribute();
}
}
示例15: WriteXml
/// <summary>
/// Writes the internal data for this ContentLocatorGroup to the writer. This method
/// is used by an XmlSerializer to serialize a ContentLocatorGroup. To serialize a
/// ContentLocatorGroup to Xml, use an XmlSerializer.
/// </summary>
/// <param name="writer">the writer to write internal data to</param>
/// <exception cref="ArgumentNullException">writer is null</exception>
public void WriteXml(XmlWriter writer)
{
if (writer == null)
{
throw new ArgumentNullException("writer");
}
string prefix = writer.LookupPrefix(AnnotationXmlConstants.Namespaces.CoreSchemaNamespace);
if (prefix == null)
{
writer.WriteAttributeString(AnnotationXmlConstants.Prefixes.XmlnsPrefix, AnnotationXmlConstants.Prefixes.CoreSchemaPrefix, null, AnnotationXmlConstants.Namespaces.CoreSchemaNamespace);
}
foreach (ContentLocatorBase locator in _locators)
{
if (locator != null)
{
AnnotationResource.ListSerializer.Serialize(writer, locator);
}
}
}