2016-08-30 55 views
0

我需要刪除第一個元素。 我有這個XML的XmlDocument文檔。只需要知道如何刪除第一個元素「?xml version =」1.0「encoding =」US-ASCII「?」。如何使用c#刪除XML的第一個元素?

這必須

<?xml version="1.0" encoding="US-ASCII"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
      version="1.0"> 
<xsl:template match="/*"> 
    <xsl:apply-templates select="*[1]"/> 
</xsl:template> 
<xsl:template match="@*|node()"><!--identity for all other nodes--> 
    <xsl:copy> 
    <xsl:apply-templates select="@*|node()"/> 
    </xsl:copy> 
</xsl:template> 
</xsl:stylesheet> 

這樣

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
      version="1.0"> 
<xsl:template match="/*"> 
    <xsl:apply-templates select="*[1]"/> 
</xsl:template> 
<xsl:template match="@*|node()"><!--identity for all other nodes--> 
    <xsl:copy> 
    <xsl:apply-templates select="@*|node()"/> 
    </xsl:copy> 
</xsl:template> 
</xsl:stylesheet> 
+0

我需要在base64中進行編碼後,我刪除該行併發送請求。 – xenos

+2

這不是一個元素,這是處理指令。看到重複。 –

回答

1

如果你有一個包含XML的XmlDocument對象,那麼你就可以得到XML沒有XML聲明是這樣的:

string xml = doc.DocumentElement.OuterXml; 

或者,您可以刪除XmlDeclaration completel y:

if (doc.FirstChild is XmlDeclaration) 
    doc.RemoveChild(doc.FirstChild); 
string xml = doc.OuterXml; 
+0

這個作品謝謝你。 – xenos

相關問題