1

When I use "< a > < ! [ CDATA[]]> < / a >.Value" anywhere in my code and then I try to export and later import as Snippet then VisualStudio can't recognize the snippet because the tags are in confliction.

For example in this variable I use the tags:

Dim RegEx As New System.Text.RegularExpressions.Regex( _
<a><![CDATA[(http://|https://|www).*\.html?]]></a>.Value)

...So I can put it in a .Snippet file but I can't use it 'cause the tags are in confliction with the other tags of the snippet file so VS can't recognize the snippet file.

enter image description here

enter image description here

enter image description here

How I can resolve this?

PS: Is not a solution for me to use double-quotes "" instead "< a > < ! [CDATA[ ]] > < / a >.Value"

This is a sample snippet:

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
      <Title>
         Regex match htm html
      </Title>
      <Author>Elektro H@cker</Author>
      <Description>
         Expresión regular para encontrar urls.htm
      </Description>
      <HelpUrl>
      </HelpUrl>
      <Shortcut>
      </Shortcut>
    </Header>
    <Snippet>
      <Declarations>
        <Literal Editable="true">
          <ID>aaaaaaaaa</ID>
          <ToolTip>sfsdf</ToolTip>
          <Default>
          </Default>
          <Function>sdfsdf</Function>
        </Literal>
      </Declarations>
      <Code Language="vb"><![CDATA[

#Region " RegEx Match htm-html "

    ' [ RegEx Match htm-html Function ]
    '
    ' // By Elektro H@cker
    '
    ' Examples :
    ' Dim str As String = <a><![CDATA[href="http://www.mp3crank.com/the-rolling-stones/deluxe-edition.htm"]]></a>.Value
    ' MsgBox(RegEx_Match_htm_html(str)) ' Result: http://www.mp3crank.com/the-rolling-stones/deluxe-edition.htm

    Private Function RegEx_Match_htm_html(ByVal str As String, Optional ByVal Group As Int32 = 0) As String

        ' Match criteria:
        '
        ' http://text.htm
        ' http://text.html
        ' https://text.htm
        ' https://text.html
        ' www.text.htm
        ' www.text.html

        Dim RegEx As New System.Text.RegularExpressions.Regex( _
        <a><![CDATA[(http://|https://|www).*\.html?]]></a>.Value)

        Return RegEx.Match(Str).Groups(Group).ToString

    End Function

#End Region

]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>
4

1 回答 1

3

您可以使 CDATA 结束标记成为文字。尝试这个:

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
      <Title>
         Regex match htm html
      </Title>
      <Author>Elektro H@cker</Author>
      <Description>
         Expresión regular para encontrar urls.htm
      </Description>
      <HelpUrl>
      </HelpUrl>
      <Shortcut>
      </Shortcut>
    </Header>
    <Snippet>
      <Declarations>
        <Literal Editable="true">
          <ID>aaaaaaaaa</ID>
          <ToolTip>sfsdf</ToolTip>
          <Default>
          </Default>
          <Function>sdfsdf</Function>
        </Literal>
        <Literal Editable="false">
          <ID>cdataend</ID>
          <ToolTip>Part of the CDATA end tag.</ToolTip>
          <Default>&gt;</Default>
        </Literal>
      </Declarations>
      <Code Language="vb"><![CDATA[

#Region " RegEx Match htm-html "

    ' [ RegEx Match htm-html Function ]
    '
    ' // By Elektro H@cker
    '
    ' Examples :
    ' Dim str As String = <a><![CDATA[href="http://www.mp3crank.com/the-rolling-stones/deluxe-edition.htm"]]$cdataend$</a>.Value
    ' MsgBox(RegEx_Match_htm_html(str)) ' Result: http://www.mp3crank.com/the-rolling-stones/deluxe-edition.htm

    Private Function RegEx_Match_htm_html(ByVal str As String, Optional ByVal Group As Int32 = 0) As String

        ' Match criteria:
        '
        ' http://text.htm
        ' http://text.html
        ' https://text.htm
        ' https://text.html
        ' www.text.htm
        ' www.text.html

        Dim RegEx As New System.Text.RegularExpressions.Regex( _
        <a><![CDATA[(http://|https://|www).*\.html?]]$cdataend$</a>.Value)

        Return RegEx.Match(Str).Groups(Group).ToString

    End Function

#End Region

]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

现在应该可以工作了。

于 2013-06-09T10:52:17.247 回答