Foro de elhacker.net

Programación => Programación General => Mensaje iniciado por: Eleкtro en 9 Junio 2013, 12:04 pm



Título: [Resuelto] ¿Como escapar un CDATA en un XML?
Publicado por: Eleкtro en 9 Junio 2013, 12:04 pm
Necesito ayuda con este xml para escapar el CDATA de la variable del RegEx (No quiero usar comillas dobles porque en otros códigos no puedo hacerlo),
no sé nada de XML y estoy perdido, muy perdido, no sé si esto tiene solución, ¿Que puedo hacer?:

Código
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  3.  <CodeSnippet Format="1.0.0">
  4.    <Header>
  5.      <SnippetTypes>
  6.        <SnippetType>Expansion</SnippetType>
  7.      </SnippetTypes>
  8.      <Title>
  9.         Regex match htm html
  10.      </Title>
  11.      <Author>Elektro H@cker</Author>
  12.      <Description>
  13.         Expresión regular para encontrar urls.htm
  14.      </Description>
  15.      <HelpUrl>
  16.      </HelpUrl>
  17.      <Shortcut>
  18.      </Shortcut>
  19.    </Header>
  20.    <Snippet>
  21.      <Declarations>
  22.        <Literal Editable="true">
  23.          <ID>aaaaaaaaa</ID>
  24.          <ToolTip>sfsdf</ToolTip>
  25.          <Default>
  26.          </Default>
  27.          <Function>sdfsdf</Function>
  28.        </Literal>
  29.      </Declarations>
  30.      <Code Language="vb"><![CDATA[
  31.  
  32.  
  33.  
  34.  
  35.  
  36.        Dim RegEx As New System.Text.RegularExpressions.Regex( _
  37.        <a><![CDATA[(http://|https://|www).*\.html?]]></a>.Value)
  38.  
  39.  
  40.  
  41.  
  42.  
  43. ]]></Code>
  44.    </Snippet>
  45.  </CodeSnippet>
  46. </CodeSnippets>


Según esto al final del comentario a mi no me ha quedado muy claro si hay algún "trick" para mezclar los CDATA y que funcione :S : http://stackoverflow.com/questions/223652/is-there-a-way-to-escape-a-cdata-end-token-in-xml

...¿Alguna ayuda?


Título: Re: ¿Como escapar un CDATA en un XML?
Publicado por: Eleкtro en 9 Junio 2013, 14:05 pm
Ya lo pude solucionar (bueno, más bien me lo solucionaron):

Código
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  3.  <CodeSnippet Format="1.0.0">
  4.    <Header>
  5.      <SnippetTypes>
  6.        <SnippetType>Expansion</SnippetType>
  7.      </SnippetTypes>
  8.      <Title>
  9.         Regex match htm html
  10.      </Title>
  11.      <Author>Elektro H@cker</Author>
  12.      <Description>
  13.         Expresión regular para encontrar urls.htm
  14.      </Description>
  15.      <HelpUrl>
  16.      </HelpUrl>
  17.      <Shortcut>
  18.      </Shortcut>
  19.    </Header>
  20.    <Snippet>
  21.      <Declarations>
  22.        <Literal Editable="true">
  23.          <ID>aaaaaaaaa</ID>
  24.          <ToolTip>sfsdf</ToolTip>
  25.          <Default>
  26.          </Default>
  27.          <Function>sdfsdf</Function>
  28.        </Literal>
  29.        <Literal Editable="false">
  30.          <ID>cdataend</ID>
  31.          <ToolTip>Part of the CDATA end tag.</ToolTip>
  32.          <Default>&gt;</Default>
  33.        </Literal>
  34.      </Declarations>
  35.      <Code Language="vb"><![CDATA[
  36.  
  37. #Region " RegEx Match htm-html "
  38.  
  39.    ' [ RegEx Match htm-html Function ]
  40.    '
  41.    ' // By Elektro H@cker
  42.    '
  43.    ' Examples :
  44.    ' Dim str As String = <a><![CDATA[href="http://www.mp3crank.com/the-rolling-stones/deluxe-edition.htm"]]$cdataend$</a>.Value
  45.    ' MsgBox(RegEx_Match_htm_html(str)) ' Result: http://www.mp3crank.com/the-rolling-stones/deluxe-edition.htm
  46.  
  47.    Private Function RegEx_Match_htm_html(ByVal str As String, Optional ByVal Group As Int32 = 0) As String
  48.  
  49.        ' Match criteria:
  50.        '
  51.        ' http://text.htm
  52.        ' http://text.html
  53.        ' https://text.htm
  54.        ' https://text.html
  55.        ' www.text.htm
  56.        ' www.text.html
  57.  
  58.        Dim RegEx As New System.Text.RegularExpressions.Regex( _
  59.        <a><![CDATA[(http://|https://|www).*\.html?]]$cdataend$</a>.Value)
  60.  
  61.        Return RegEx.Match(Str).Groups(Group).ToString
  62.  
  63.    End Function
  64.  
  65. #End Region
  66.  
  67. ]]></Code>
  68.    </Snippet>
  69.  </CodeSnippet>
  70. </CodeSnippets>

Saludos