Menu

declare variable drop input from xml

Help
gadido30
2007-06-21
2012-09-04
  • gadido30

    gadido30 - 2007-06-21

    Hi

    Thanx again for helping me, I am now face in new problem .

    I have some html file that has <input> , If I use xpath expression it work and I can see the input value.

    but when I try to get <inpu> value from [!CDATA[declare variable $doc as node() external; I don't see the input varible all other <div>,<b> it work.

    I am using let $textb := data($doc//*[td='test']/following::input)

    thanx
    Gadi

     
    • gadido30

      gadido30 - 2007-07-03

      Thanx, I have found other problem with data() and some input varible, I have past it in the forum.

      Thanx agin

       
    • gadido30

      gadido30 - 2007-06-24

      Hi

      I will try to expline , I am using html-xml , when I try to use xquery with cdata and node() I don't get the <input> from html (it seems that it drop it out) , how can I get those html varible inside xquery? do I need to use template , I will be glad for littel example.

      Thanx
      Gadi

       
      • Vladimir Nikic

        Vladimir Nikic - 2007-06-25

        Please check this thread:

        https://sourceforge.net/forum/message.php?msg_id=4074496

        I beleave that your problem is similar.

        Vladimir.

         
    • Vladimir Nikic

      Vladimir Nikic - 2007-06-25

      Can you please send the full example?

       
    • gadido30

      gadido30 - 2007-06-26

      Hi, Vladimir

      I have tryed out the example of sasa with out any lack, I try to use html-to-xml but I got error from xquery, I will be glad if you can post example also with html-to-xml.

      Thanx Again
      Gadi

       
      • Vladimir Nikic

        Vladimir Nikic - 2007-06-26

        Please send me your example that doesn't work in order to try to fix it.

         
    • gadido30

      gadido30 - 2007-06-26

      <config>
      <var-def name="searchEngine">
      testpage
      </var-def>

      <var-def name="startUrl">http://mytest.net/mytest.html</var-def>

      <file action="write" path="data/${searchEngine}_content.xml">

             &lt;var-def name=&quot;my_xpath&quot;&gt;//h1&lt;/var-def&gt;
             &lt;xquery&gt;
      
            &lt;xq-param name=&quot;item&quot;&gt;&lt;var name=&quot;item&quot;/&gt;&lt;/xq-param&gt; 
            &lt;xq-param name=&quot;my_xpath&quot;&gt;&lt;var name=&quot;my_xpath&quot;/&gt;
      
                      &lt;html-to-xml&gt;
                          &lt;http url=&quot;${startUrl}&quot;/&gt;
                      &lt;/html-to-xml&gt;
      
                  &lt;/xq-param&gt;
      
      &lt;xq-expression&gt;
      &lt;template&gt;
          &lt;![CDATA[
      
                            let $name := data($item{$my_xpath}) 
                return
      
              &lt;name&gt;{$name}&lt;/name&gt;
      
                      ]]&gt;
          &lt;/template&gt;
          &lt;/xq-expression&gt;
                  &lt;/xquery&gt;
      

      </file>

       
    • gadido30

      gadido30 - 2007-06-28

      Hi, Vladimir

      I post here in the forum an example, Can You please help me.

      Thanx
      Gadi

       
      • Vladimir Nikic

        Vladimir Nikic - 2007-06-28

        first problem:

        <xq-param name="item"><var name="item"/></xq-param>

        where you don't have item variable previously defined in the web-harvest execution context.

         
    • gadido30

      gadido30 - 2007-06-28

      Hi , Vladimir

      I also had var-def to item and still I got xquery error?

      Thanx Agai
      Gadi

       
      • Vladimir Nikic

        Vladimir Nikic - 2007-06-29

        :)

        The problem is in template processor around XQuery expression.
        template should replace my_xpath with something. However, syntax should be:
        ${my_xpath} instead of {$my_xpath}.

         
    • gadido30

      gadido30 - 2007-06-29

      Hi , Vladimir

      I still get xquery error, I think its somthing releted to $item , This is what I try to do:

      <?xml version="1.0" encoding="UTF-8"?>

      <config>

      <var-def name="url">
      <template> http://mytest.com/test.html</template>
      </var-def>

      <var-def name="referencias">
      <html-to-xml>
      <http url="${url}"/>
      </html-to-xml>
      </var-def>

      <file action="write" path="test/test.xml" charset="UTF-8">
      <![CDATA[ <?xml version="1.0" encoding="UTF-8"?>
      <scholar>
      ]
      ]>

      <loop item="item" index="i">
      <list><var name="referencias"/></list>
      <body>
      <xquery>
      <xq-param name="item"><var name="item"/></xq-param>
      <xq-expression>
      <template>
      <![CDATA[
      let $title := data($item//h1)

      return
      <referencia>
      <title>{$title}</title>
      </referencia>
      ]]>
      </template>
      </xq-expression>
      </xquery>

      </body>
      </loop>
      <![CDATA[
      </scholar> ]
      ]>
      </file>

      </config>

      It give me error in xquery, In the back example my_path wored but still I got error from $item.

      Thanx Again
      Gadi

       
    • Rob Grzywinski

      Rob Grzywinski - 2007-07-03

      Just follow http://web-harvest.sourceforge.net/samples.php?num=5

      The error that you're getting "Variable $item has not been declared" tells you what's missing. Doing a visual delta from the example to what you have shows that you need:

      declare variable $item as node() external;

      So your xquery should look like:

      <xquery>
      <xq-param name="item"><var name="item"/></xq-param>
      <xq-expression>
      <template>
      <![CDATA[
      declare variable $item as node() external;
      let $title := data($item//h1)

      return
      <referencia>
      <title>{$title}</title>
      </referencia>
      ]]>
      </template>
      </xq-expression>
      </xquery>

      The "<xq-param name="item"><var name="item"/></xq-param>" part passes the variable "item" into the XQuery but then you have to declare the variable in XQuery. (Think of the difference between passing a variable to a function and the function declaration itself.)

      Hope this helps.

       

Log in to post a comment.