Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Best Method to Process XML
Message
General information
Forum:
Visual FoxPro
Category:
XML, XSD
Miscellaneous
Thread ID:
01136959
Message ID:
01137358
Views:
24
In addition to Pinto's reply, yiou can address the XML in other ways that might be helpful - or might be more confusing.

With VFP we can drive, plug AND play with an XML object until our fingers get
blisters on them:)
*One approach might be (assuming you have an XML organized [something]
*like this:
(xml)
  (table}
    (rows)
      (row) . some data as additional nodes or attributes . (/row)
      (row) . some data as additional nodes or attributes . (/row)
      (row) . some data as additional nodes or attributes . (/row)
    (/rows)
  (/table)

*Okay - let's say you're only interested in the "row" elements that are *children the (rows) element.
*Start your XML
oXML=CREATEOBJECT("MSXML2.DOMDocument.4.0") &&Try an implicit connect to 4.0
oXML.async=.f.
oXML.setProperty("SelectionLanguage","XPath")
oXML.load(GETFILE()) && You may need to be local to the folder
                     && to assure the XSD's merge
                     && ALso note that 4.0 will merge XSD's that
                     && Earlier XML objects "will not" merge.
* Now create a reference to the (rows) element:
oRows=oXML.selectSingleNode("*//*[local-name()='rows']")
* Ho many (row) are in (rows)
?oRows.length
* To point to a "row"
oRow=oRows.item(n)
* If the fields are stored as tags
oFields=oRow.childNodes
* If the fields are stored as attributes
oFields=oRow.attributes
* You could then address the nodenames and node texts or values using
* a loop, or "literally" request the node names (in either case).
* With attributes, some may be missing, you might need to verify they are
* of the parent element:
IF TYPE('oFields.getAttribute("txtSomeAttributeName")')==[C]
* returns a "True", the attribute is there.
* I am not sure about elements - I think I have written XMLs with an empty 
* element "(row)(/row). 
* You can also get a different result (a more exclusive set - fewer items) 
* depending on your XML heirarchy (i dont know why):
oRow=oRows.selectNodes("*[local-name()='row']")
There are features that associated with the tag when addressed as a "childNodes" and features that are associated when item(s) are addressed.
I would like the big picture - but have not fount it.
You may want to take note as to how the first XPath (local-name()) address the manifest as opposed to th e way local-name() is address at the bottom of the sample.

HTH


>Thats working. I just have alot of coding ahead of me to pull the info into variables then put that into tables.
>
>Thanks,
>John G.
>
>>If you're using the DOM, then Intellisense is your friend. I had to process an XML file this way, and used mainly two functions: SelectSingleNode and SelectNodes.
>>Here are some lines that will give you an idea...
>>loXml = CreateObject("Microsoft.XMLDOM")
>>loXml.Load ( YourXMLString )
>>loRoot = loXML.documentElement
>>IF ISNULL( loRoot )
>>   RETURN 'Invalid XML'
>>ENDIF
>>loElement = loRoot.selectSingleNode( "CustomerName" )
>>lCustomerName = iif(!ISNULL(loElement),allt(loElement.Text),"" )
>>
>>lOrderNumbers = loRoot.selectNodes ("Orders/OrderNumber")
>>for each loElement in lOrderNumbers
>>   ? loElement.Text
>>endfor
>>
>>** you can also try loRoot.selectNodes ( "Orders/Blabla/Blablabla" )
>>
>>
>>I hope you get the drill :-)
>>Jaime
>>
>>>I've been beating my head looking for the best way to process XML files in VFP 9.0.
>>>
>>>XMLADAPTER does not work because it uses MSXML 4.0. The XML files I am getting only work with MSXML 6.0.
>>>
>>>So I was looking at using XPath to navigate through the XML. But now I'm looking at just using the DOM to do so.
>>>
>>>I am new to doing this so any help on the best direction to take and learning resources to use would be well appreciated.
>>>
>>>The XML files that will be processed are fairly complex and have many nodes. They represent purchase orders and sales orders.
>>>
>>>Thanks!
Imagination is more important than knowledge
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform