Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Xml convert invalid
Message
 
À
17/11/2005 04:49:34
Information générale
Forum:
Visual FoxPro
Catégorie:
XML, XSD
Versions des environnements
Visual FoxPro:
VFP 9
OS:
Windows 2000 SP4
Network:
Windows 2000 Server
Database:
Visual FoxPro
Divers
Thread ID:
01069625
Message ID:
01070080
Vues:
14
TRY it with DOM:
* UT_XMLDOM_DEMO.PRG
* What you have here may require a two file solution. You have order
* information and it seems you anticipate order items with the 
* <OrderStart /> <OrderEnd /> tags. But those could be something 
* else and this XML is as it appears - a one item order. Typically
* we see an order header record and a set of order item (child)
* records (rows)

* My First mistake was using a clipboard copy and then assigning
* _cliptext to a string (How many times have I done that). But,
* actuality XML does not have crlfs between tags. What it did
* is force me to adress the noses as "item" elements - eg could
* not XPath very deep. SO REMEMBER KIDDES, don't paste a posted
* XML Sample to string. You'll start romantasizing about how much
* fun you had as a low on the totem bus boy/girl!

*Cheap DOM Demo
lcXML=; && The XML String
+[<?xml version="1.0" encoding="Windows-1252"?><PPSExport ];
+[xmlns:xsd="http://www.w3.org/2001/XMLSchema" ];
+[xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Version="1.1">];
+[<ProductionOrderFeedback><ProductionOrder OrderNo="AuftrPPS60">];
+[<PartNo>Fuellteil</PartNo><DesiredQuantity>0</DesiredQuantity>];
+[<ProcessedParts>0</ProcessedParts><ProcessingTime>0</ProcessingTime>];
+[<TimeStamp>06.09.2005 14:38:29</TimeStamp>];
+[<OrderStart /><OrderEnd /><ReturnCode>-99</ReturnCode><Description />];
+[</ProductionOrder></ProductionOrderFeedback></PPSExport>]
* This is 4.0 - drop it down if needed
oXML=CREATEOBJECT("MSXML2.DOMDocument.4.0")
oXML.async=.f.
oXML.setProperty("SelectionLanguage","XPath")
oXML.loadXML(lcXML)

llDoItWith_XPath=.t.
IF llDoItWith_Xpath
   ?[DOING IT WITH XPATH TO PARSE THE NODES YOU PSYCHOPATHS]
   oXMLPPSExport=oXML.selectSingleNode("PPSExport")
   ?oXMLPPSExport.nodename + [ / ],oXMLPPSExport.text
   * Production Order Feed Back
   oXMLProductionOrderFeedBack=oXML;
       .selectSingleNode("PPSExport");
       .selectSingleNode("ProductionOrderFeedback")
   ?oXMLProductionOrderFeedBack.nodename+[ / ],;
       oXMLProductionOrderFeedBack.text
   * Production order
   oXMLProductionOrder=oXML;
       .selectSingleNode("PPSExport");
       .selectSingleNode("ProductionOrderFeedback");
       .selectSingleNode("ProductionOrder")
   ?oXMLProductionOrder.nodename+[ / ],;
       oXMLProductionOrder.text
   * Order number ATTRIBUTE 
   oXMLOrderNo=oXMLProductionOrder.attributes(0)
   ?oXMLOrderNo.nodename+[ / ],oXMLOrderNo.nodevalue
   * PartNo x SelectSingleNode    
   oXMLPartNo=oXMLProductionOrder.selectSingleNode("PartNo")
   ?oXMLPartNo.nodename+[ / ],oXMLPartNo.text
   * PartNo x getElementsByTagName
   oTAGPartNo=oXMLProductionOrderFeedBack;
       .getElementsByTagName("PartNo")
   * Note we had to back up one ancestor
   ?[by tag: ]+oTAGPartNo.item(0).nodename+[ / ],;
               oTAGPartNo.item(0).text
   * Desired Quantity
   oXMLDesiredQuantity=oXMLProductionOrder;
       .selectSingleNode("DesiredQuantity")
   ?oXMLDesiredQuantity.nodename+[ / ],oXMLDesiredQuantity.text
   * Procesed parts
   oXMLProcessedParts=oXMLProductionOrder;
       .selectSingleNode("ProcessedParts")
   ?oXMLProcessedParts.nodename+[ / ],oXMLProcessedParts.text
   *Processing time
   oXMLProcessingTime=oXMLProductionOrder;
       .selectSingleNode("ProcessingTime")
   ?oXMLProcessingTime.nodename+[ / ],oXMLProcessingTime.text
   *Time Stamp
   oXMLTimeStamp=oXMLProductionOrder;
       .selectSingleNode("TimeStamp")
   ?oXMLTimeStamp.nodename+[ / ],oXMLTimeStamp.text
   *OrderStart   
   oXMLOrderStart=oXMLProductionOrder;
       .selectSingleNode("OrderStart")
   ?oXMLOrderStart.nodename+[ / ],oXMLOrderStart.text
   *If this were an order items collection then loop here
   *OrderEnd
   oXMLOrderEnd=oXMLProductionOrder;
       .selectSingleNode("OrderEnd")
   ?oXMLOrderEnd.nodename+[ / ],oXMLOrderEnd.text
   * Return code 
   * Sometimes XMLs won't include empty tags. If you
   * anticpate tags that are not there, you need 
   * to check
   IF VARTYPE(oXMLProductionOrder.selectSingleNode("ReturnCode"))==[O]
      oXMLReturnCode=oXMLProductionOrder;
          .selectSingleNode("ReturnCode")
      ?oXMLReturnCode.nodename+[ / ],oXMLReturnCode.text
   ELSE 
      * Error condition
   ENDIF 
   * Force error by changing "ReturnCode" to "ReturnID"
   IF VARTYPE(oXMLProductionOrder.selectSingleNode("ReturnID"))==[O]
      oXMLReturnCode=oXMLProductionOrder;
          .selectSingleNode("ReturnID")
      ?oXMLReturnID.nodename+[ / ],oXMLReturnID.text
   ELSE 
      ? [******BOO BOO Node "ReturnID: was not found*****]
   ENDIF 
   *Description
   oXMLDescription=oXMLProductionOrder;
       .selectSingleNode("Description")
   ?oXMLDescription.nodename+[ / ],oXMLDescription.text
   * Cheap llop trick
   oXMLProductionOrderItems=oXMLProductionOrder.childnodes
   ?[****************************]
   ?[Cheap loop trick]
   FOR c = 0 TO oXMLProductionOrderItems.length - 1
   ?[ProductionOrder.childnodes(]+TRANSFORM(c);
                                 +[) ]+oXMLProductionOrderItems.item(c).nodename;
                                 +[ / ],oXMLProductionOrderItems.item(c).text
   ENDFOR 
ELSE && Just CildNodes
   ?[Using Child Node Indexing to Parse the node]
   ?oXML.childNodes(1).nodeName+[ / ]
      ?? oXML.childNodes(1).text
   ?oXML.childNodes(1).childNodes(0).nodeName+[ / ]
      ??oXML.childNodes(1).childNodes(0).text
   ?oXML.childNodes(1).childNodes(0).childNodes(0).nodeName+[ / ]
      ??oXML.childNodes(1).childNodes(0).childNodes(0).text
   * The productor Order Group for the ProductionOrder Loop 
   oXMLProdOrder=oXML.childNodes(1).childNodes(0).childNodes(0)
   ?[The Loop out of Production Order Child Nodes!]
   FOR c = 0 TO oXMLProdOrder.childnodes.length-1
   ?oXMLProdOrder.childnodes(c).nodename+[ / ]
      ??oXMLProdOrder.childnodes(c).text
   ENDFOR 
ENDIF    
?[**********************************************************]
?[And that's why I don't do two shows a night - I just won't]
?[**********************************************************]
Imagination is more important than knowledge
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform