Menu

Namespaces and XpathExtract

Help
Bob C
2005-02-22
2013-04-16
  • Bob C

    Bob C - 2005-02-22

    We are unable to get XpathExtract to work when the instance document includes a default namespace.

    This works:
    <Enrollment @recipientName="ConnecticutYankee">
    </Enrollment>

    XPath = /Enrollment/@recipientName

    This does not work (large stack trace):
    <Enrollment xsi:schemaLocation="http://ns.hr-xml.org/2004-08-02 http://ns.hr-xml.org/2_3/HR-XML-2_3/Enrollment/Enrollment.xsd" recipientName="Flexben" xmlns="http://ns.hr-xml.org/2004-08-02" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

     
    • Sherman Wood

      Sherman Wood - 2005-02-22

      It looks like the XpathExtract stage does not handle namespaces. You will need to look into the XPathAPI to see what is needed there, and extend the XpathExtract stage with additional parameters to provide namespace parameters.

      Sherman

       
    • Bob C

      Bob C - 2005-02-23

      Thanks. Have you extended or written a pipeline stage? How difficult is it? I wil be writing at least a couple of them, and I just wanted to get a feel for how much effort is required.

      Thanks again,
      Bob

       
      • Sherman Wood

        Sherman Wood - 2005-02-23

        We have created about 25 custom pipeline stages of varying levels of complexity over 2 years. If you look into the Babeldoc source, you will see how easy it is. Just set up your stage parameters in the stage constructor, override process() and validate the stage parameters. Creating your own module is easy - based on looking at the examples like sql.

        Babeldoc has been "good enough" for us - the framework never got in the way of getting things done.

        Sherman

         
    • Bob C

      Bob C - 2005-02-23

      Thanks Sherman. That is great advice. I'm going to give it a try today. Just a couple of more questions. I'm not sure what you mean by 'validate the stage parameters'. and, after you write a new stage, do you just add the class to the jar, or do you re-ant the whole application?

      Thanks,
      Bob

       
      • Sherman Wood

        Sherman Wood - 2005-02-24

        There are two ways to go. You can add a new pipeline stage class into an existing module (say babeldoc core) which is quick but not 'clean', or you can create a new module, which is a little more effort, but a lot cleaner.

        To add a pipeline stage to an existing module, put the new class in the module source tree with the other pipeline stages in the module. Add a line in the module config/services/query.properties, like:

        PipelineStage.NewPipelineStage=com.mycompany.mymodule.pipeline.stage.NewPipelineStage

        In your pipeline, you can then have a pipeline step refer to:

        <stage-type>NewPipelineStage</stage-type>.

        For a new module, have a look at the crypto module. It is very small. That will give you a template for your own module - required classes and config file etc.

        My comment about validating parameters is about the way pipeline stages are called. If you look at the SignerPipelineStage in the crypto module, you will see at the start of the process method that there are getOptions(String) calls. These pull in the data in the pipeline definition.

        Sherman

         
    • bruce mcdonald

      bruce mcdonald - 2005-02-24

      Sherman is correct.  Avoid the core module if you don't want your stuff vaporized at the next release.

      If anyone has a fix (no new functionality) please submit a patch or copy-paste... 

      1.2 has to go...

      Go to the other forum and read further announcement there...

       
    • Bob C

      Bob C - 2005-02-24

      Thanks Bruce and Sherman for the great advice.. We have a workaround for the namespace issue. Since we are just starting out with babeldoc, we decided to go with that for now instead of adding a new module. We are just running a tranform stage where we copy the namespace we are targeting into the instance document, and then call the xPathExtract, after which we call another transform stage. Here is the xsl we use, courtesy of Buddy Kresge

      <?xml version="1.0"?>

      <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

                                                      xmlns:hrxml="http://ns.hr-xml.org/2004-08-02"

                                                      version="1.0">

                  <xsl:output method="xml"/>

          <xsl:template match="*">

            <xsl:element name="{name(.)}" namespace="{namespace-uri(.)}">

                <xsl:copy-of select="namespace::*" />

                <xsl:for-each select="@*">

                    <xsl:attribute name="{name(.)}" namespace="{namespace-uri(.)}">

                          <xsl:value-of select="."/>

                    </xsl:attribute>

                </xsl:for-each>

                <xsl:apply-templates/>

            </xsl:element>

          </xsl:template>

      </xsl:stylesheet>

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.