1 2 3 Previous Next 32 Replies Latest reply on Feb 18, 2016 4:58 AM by DanielShanahan

    xPath for BE_XPath

    DanielShanahan

      I'm trying to get information on text objects from the DDR in .xml.  I think using an XSLT would be the best way to go but the learning curve is steep.  For the moment I'm using the Base Elements plugin, specifically, the BE_XPath ( xml ; xpath {; namespaceList ; asText } ) function.

       

      I'm not clear on how to write the second parameter, xpath.  The example on the documentation page is too obscure for me.

       

      I'm trying to get the info in the TextObj (see image).  I've tried the following:

      FMPReport/File/LayoutCatalog/Layout/Object/TextObj/

      /FMPReport/File/LayoutCatalog/Layout/Object/TextObj/

      FMPReport/File/LayoutCatalog/Layout/Object/TextObj

      /FMPReport/File/LayoutCatalog/Layout/Object/TextObj

      /////TextObj/

      FMPReport:File:LayoutCatalog:Layout:Object/TextObj

       

      Also, I'm presuming that the first parameter - xml - can be reference to an external document.  My calculation looks like this:

       

      Let ( [

        _xml = Get ( DesktopPath ) & "InventoryDDR/" & "inventory_fmp12.xml" ;

        _xpath = "FMPReport/File/LayoutCatalog/Layout/Object/TextObj/"

      ] ;

       

      BE_XPath ( _xml ; _xpath )

       

      )  // end Let

       

      I'd like to be able to grab all the TextObj from all the layouts.  I don't need all the namespaces, so I'd like to use the namespaceList parameter.  But the complexity - at least for me - is such that I thought it best to start simple, so I'm just focused on getting all the data from the TextObj.

       

      Here is an image of the .xml with the TextObj highlighted:

      TextObj_info.png

       

      The calc is in the Data Viewer but doesn't return anything.  Can anyone tell me what I'm doing wrong?

        • 1. Re: xPath for BE_XPath
          beverly

          note that the example uses the root of the document "/" and the namespaces can make a difference (also in the example).

           

          To get the paths, you might look at this:

               http://jensteich.de/fmfaq/export/universal-xslt-fur-den-import-beliebiger-xml-daten/

          It will import your XML and give you the paths as well as the values!

           

          beverly

          • 2. Re: xPath for BE_XPath
            electon

            1) Are you sure it accepts a path to a file or does it need to be a text ( raw xml data ) input?

             

            Documentation example says:

            BE_XPath ( $$XML ; "/abc:checkUserResponse/abc:result/abc:accountDetails/@type")


            Your path does not start with a forward slash /. The forward slash represents an absolute path to the node starting with the root element.

             

            There's also a tutorial here XPath 1.0 Tutorial @ZVON.org

            Not related to the BaseElements plugin.

             



            • 3. Re: xPath for BE_XPath
              DanielShanahan

              beverly wrote:

               

              note that the example uses the root of the document "/" and the namespaces can make a difference (also in the example).

               

               

              Thanks Beverly.  I did try "/FMPReport/File/LayoutCatalog/Layout/Object/TextObj/" - I'm not sure if that's what you mean.

               

              beverly wrote:

               

              To get the paths, you might look at this:

                   http://jensteich.de/fmfaq/export/universal-xslt-fur-den-import-beliebiger-xml-daten/

              It will import your XML and give you the paths as well as the values!

               

              Thanks.  That is very interesting.  I had seen this before but hadn't tried it.  Encouraged by your link, I copied it and used it to import the DDR.  Works like a charm!

               

              However, it's not exactly what I want.  I don't mind testing, trying, learning, etc.  What I'd like to import from the DDR is something like this:

               

              Layout|Data|Bounds|Font Family|Font Size|Face|Font Color|

              Company Info|Company Name|298,15,318,250|verdana,sans-serif|14|0|#000000

              Company Info|Header|406,15,426,168|verdana,sans-serif|14|0|#000000

              Company Info|Footer|514,15,535,149|verdana,sans-serif|14|0|#000000

              Company Info|Company Info|18,15,39,140|verdana,sans-serif|15|256|#E6E6E6

              Company Info|<<Logo Placeholder>>|139,37,159,282|verdana,sans-serif|14|0|#000000

               

              (This is from the FileMaker Inventory Starter Solution)

              • 4. Re: xPath for BE_XPath
                DanielShanahan

                electon wrote:

                 

                1) Are you sure it accepts a path to a file or does it need to be a text ( raw xml data ) input?

                Nope.  Not sure at all.  The documentation simply has $$XML.  I don't know if that global variable refers to a field or a file.  I tried both.

                 

                 

                Your path does not start with a forward slash /. The forward slash represents an absolute path to the node starting with the root element.

                I did try "/FMPReport/File/LayoutCatalog/Layout/Object/TextObj/" - I'm not sure if that's what you mean.

                 

                 

                There's also a tutorial here XPath 1.0 Tutorial @ZVON.org

                Not related to the BaseElements plugin.

                Thanks electon.  I'm familiar with the tutorial at w3schools, but hadn't come across not the one you mentioned.  It's a great tutorial - I've bookmarked it.

                • 5. Re: xPath for BE_XPath
                  user19752

                  The document says

                  the XML text to use

                  then 1st parameter should be field or XML itself, not file.

                   

                  There may be another function getting text contents from file path, can be used there.

                  • 6. Re: xPath for BE_XPath
                    user19752

                    For example

                    BE_XPath ( BE_ReadTextFromFile ( "C:\Users\a\Documents\snapshot4.fmpsl" ) ; "//UniversalPathList" )

                     

                    the path need to be OS path, not file path in FM syntax.

                    • 7. Re: xPath for BE_XPath
                      beverly

                      Yes, the XSLT was mostly to help you get the correct path(s). I haven't used the BE plug-in for XML, so don't know what problems you may have. I do know that an XSLT may be used to import. Export a sample record _from_ your database table as XML to see the format/grammar. This is what I use as a basis for most of my XSLT to import back in.

                       

                      beverly

                      • 8. Re: xPath for BE_XPath
                        beverly

                        Wouldn't the Get ( DesktopPath ) give you the OS Path? Or do you say the "/" is incorrect and should be "\"?

                        nickorr needs to chime in at some point, if possible!

                        beverly

                        • 9. Re: xPath for BE_XPath
                          electon

                          Daniel,

                          At the moment my testing produces results only when I delete the ?xml first line from the text.

                           

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

                          <FMPReport creationTime="22:43:54" creationDate="15-02-2016" type="Summary" version="14.0.4">

                            <File link=".//test_fmp12.xml" name="test.fmp12" path="/Volumes/Macintosh HD/Users/Electon/Downloads/">

                            <BaseTables count="3"/>

                            <Tables count="5"/>

                            <Relationships count="4"/>

                            <Accounts count="2"/>

                            <Privileges count="3"/>

                            <ExtendedPrivileges count="6"/>

                            <FileAccess count="0"/>

                            <Layouts count="3"/>

                            <Scripts count="1"/>

                            <ValueLists count="0"/>

                            <CustomFunctions count="0"/>

                            <FileReferences count="0"/>

                            <CustomMenuSets count="0"/>

                            <CustomMenus count="0"/>

                            </File>

                          </FMPReport>

                           

                          When I get rid of the first line:

                           

                          BE_XPath ( test::xml ; "/FMPReport/File/Tables/@count" )

                           

                          Notice the text is in a field. It gives me the count attribute of the Tables node.

                           

                           

                          HTH.

                          • 10. Re: xPath for BE_XPath
                            user19752

                            changing it to encoding="UTF-8" worked.

                            • 11. Re: xPath for BE_XPath
                              user19752

                              Separator can be both "/" and "\", but Get() results have unneeded preceding "/".

                              • 12. Re: xPath for BE_XPath
                                beverly

                                it shouldn't have to be changed to UTF-8. And the entire XML declaration should not have to be deleted. Is it a flaw of the plug-in?

                                beverly

                                • 13. Re: xPath for BE_XPath
                                  user19752

                                  I don't know the reason but the plug-in take (maybe) all text as UTF-8 internally.

                                  There was trouble in getting cmd.exe result using the plug-in.

                                  • 14. Re: xPath for BE_XPath
                                    DanielShanahan

                                    Thanks all.  I put the xml into a field and grabbed the path from the results of the XSLT that beverly recommended (see comment #1 above).  I am still unsuccessful in grabbing anything from the DDR's XML:

                                     

                                    BE_XML_Parse ( XMLINFO::xmlPath )  Returns "?"

                                    BE_XPath ( XMLINFO::xml ; XMLINFO::xmlPath ) Returns NULL

                                    BE_XPathAll ( XMLINFO::xml ; XMLINFO::xmlPath ) Returns NULL

                                     

                                     

                                    I'll try a different approach.  Thanks anyway.

                                    1 2 3 Previous Next