Wednesday, May 17, 2006

This was not a fun experiment. The key here is that we are using Visual Foxpro
to insert into a XML document. We do this by selecting the parent node, then insert
into the child nodes at a specific location. I dont see any other way to optimize this but I'm open for suggestions.





* OPEN MSXML Object
xmlDoc=CREATEOBJECT("Msxml2.DOMDocument.6.0")
xmlDoc.ASYNC="false"
xmlDoc.LOAD("xmltest.xml")
x=xmlDoc.documentElement

* INit document fragment
docFrag = xmlDoc.CreateDocumentFragment()

* Set the XML
docFrag.appendChild(xmlDoc.CreateElement("REF_J"))

* Obtain Original Node where children Exist
oNode=xmlDoc.selectnodes("/recordset/L.2000B/L.2300")
i=0
* Object Creation Of children nodes to iterate
objChildNodes = oNode.ITEM(0).childNodes
* Iterate through children, identify the node you want to insert before
FOR EACH strNode IN objChildNodes
** NODE IDENTIFIED, DO INSERT
IF strNode.nodename="REF_K"
* Inserting at the location of the node with children, insert before the location of the child node.
oNode.ITEM(0).insertBefore(docFrag, oNode.ITEM(0).childNodes.ITEM(i))
EXIT FOR
ENDIF
i=i+1
NEXT

* Save XML
xmlDoc.SAVE("xmltest-output.xml")



Comments:
Good news, I found a faster way to make it work.

oNode=xmlDoc.selectnodes("/recordset/L.2000B/L.2300")
oBNode=xmlDoc.selectnodes("/recordset/L.2000B/L.2300/REF_K")
oNode.ITEM(0).insertBefore(docFrag, oBNode.Item(0))

And this works too

oBNode=xmlDoc.selectnodes("/recordset/L.2000B/L.2300/REF_K")
oBNode.Item(0).parentnode.insertBefore(docFrag, oBNode.Item(0))
 
Post a Comment

Links to this post:

Create a Link

<< Home


Recent Posts


Linux: Dell Latitude LM, XWindows, Neomagic Magicg...
CIO Blogs - Could "Found Code" Cripple Your Compan...
Links for .NET security info
TechToolBlog 195 Free Online Programming Books
Convert String to Byte Array
Sql Server Row Size Limit - Rick Strahl's WebLog
Visual Studio Express
VB.NET: Base 36 Function
BLOGGER: You can use GeSHi in your blogger posts
LINUX: wget


Archives

01/01/2005 - 02/01/2005
02/01/2006 - 03/01/2006
03/01/2006 - 04/01/2006
04/01/2006 - 05/01/2006
05/01/2006 - 06/01/2006
09/01/2006 - 10/01/2006
10/01/2006 - 11/01/2006
11/01/2006 - 12/01/2006
12/01/2006 - 01/01/2007
04/01/2007 - 05/01/2007
05/01/2007 - 06/01/2007
01/01/2008 - 02/01/2008
02/01/2008 - 03/01/2008
05/01/2008 - 06/01/2008
06/01/2008 - 07/01/2008
08/01/2008 - 09/01/2008
09/01/2008 - 10/01/2008
11/01/2008 - 12/01/2008
12/01/2008 - 01/01/2009
01/01/2009 - 02/01/2009
02/01/2009 - 03/01/2009
04/01/2009 - 05/01/2009
05/01/2009 - 06/01/2009
07/01/2009 - 08/01/2009
01/01/2010 - 02/01/2010

My Software

Blinky - GBPVR Plugin
PhotoCopy - GBPVR Plugin
QTC - Quick Test Case
rBoop - Rob's Timers

Programming Links

C# Formatter
NSIS

Other Links

Damn Small Linux

Sites I Manage

Do it yourself SEO. Cheap.
Pet Supplies
Dog toy of the month club
SqueakerZ pet Deals
Geocaching Community
Hitch hiker Tracking