Message
 
To
09/05/2017 08:29:22
General information
Forum:
Visual FoxPro
Category:
XML, XSD
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2008 R2
Network:
Windows Server 2008 R2
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01650938
Message ID:
01651912
Views:
96
Thanks for the help so far. tried a few things but hitting a wall on this.
I tried the code and it worked if the xml file was a string in the program. I tried the code by copying the contents of the file that I was trying to import and it worked okay. So I then tried pointing to the file directly as this is what I will need to do, but I started getting problems. I've included the code below. When I do the original xml to cursor I get the document header information which I can then validate etc. I then try to use the second half to get the detail lines. This worked if the code referenced the OriginalFile string, however it will not work if I use FileToStr of the xml file or similar variations. The fact that it worked when part of the file but not when passed as a variable has me baffled. Any further help appreciated.

Edit: despite lcXMLFile having data, when I do the command m.XML.loadXML(lcXMLFile) it returns no data.
LOCAL lcFilename, lcFolder
lcFolder = SYS(5) + SYS(2003) + "\"
lcFilename = lcFolder + "Orders-120620171535_9401-2.xml"

LOCAL OriginalFile AS String

TEXT TO m.OriginalFile NOSHOW
<?xml version="1.0" encoding="utf-16"?>
<Orders xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	..... All relevant fieldsa
</Orders>
ENDTEXT

* this will do for the top level
*XMLTOCURSOR(m.OriginalFile, "Orders")
XMLTOCURSOR(lcFilename, "Orders", 512)


BROWSE

* to fetch the orders details, we'll have to transform into another XML document
* this will fetch also, as columns, the order ID that applies to the detail, and
* the Item Type Number (whatever that may be)
LOCAL GetOrderDetailsStylesheet AS String

TEXT TO m.GetOrderDetailsStylesheet NOSHOW
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  version="1.0" exclude-result-prefixes="xsd xsi">
  
  <xsl:output method="xml"/>

  <xsl:template match="/">
    <xsl:element name="OrderLines">
      <xsl:apply-templates select="Orders/Order"/>
    </xsl:element>
  </xsl:template>

  <xsl:template match="Order">
    <xsl:variable name="orderID" select="OrderID"/>
    <xsl:for-each select="OrderLines/OrderLine">
      <xsl:element name="OrderLine">
        <xsl:element name="OrderID">
          <xsl:value-of select="$orderID"/>
        </xsl:element>
        <xsl:element name="ItemTypeName">
          <xsl:value-of select="@ItemTypeName"/>
        </xsl:element>
        <xsl:copy-of select="*"/>
      </xsl:element>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>
ENDTEXT

LOCAL XML AS MSXML2.DOMDocument60
LOCAL XSLT AS MSXML2.DOMDocument60

m.XML = CREATEOBJECT("MSXML2.DOMDocument.6.0")
m.XML.async = .F.
m.XML.loadXML(m.OriginalFile)
* This isn't working
*lcXMLFile = FILETOSTR(lcFilename)
*m.XML.loadXML(lcXMLFile)

m.XSLT = CREATEOBJECT("MSXML2.DOMDocument.6.0")
m.XSLT.async = .F.
m.XSLT.loadXML(m.GetOrderDetailsStylesheet)

XMLTOCURSOR(m.XML.transformNode(m.XSLT), "OrderLines")

SELECT OrderLines

BROWSE
~M
Go raibh maith agat

~M
Previous
Next
Reply
Map
View