XML parser - no plugins - only NB actions
Moderator: Neosoft Support
XML parser - no plugins - only NB actions
I am getting ready for a project that will require control of XMLs and I decided to work through my own parser even though I know DEC has a plugin for this.
This sample shows how you can browse for an XML, display its root element and a list of all child elements and values. It allows you to export a section of the XML at the child level. It has no editing functions. It also does not validate the xml ( you would usually do this first but I am working in an environment where the files are already in production).
I parse to the 8th child level but you will see from the NB scripting that this can be easily expanded to whatever level you will be working.
This for me is more of a proof of concept than anything. Feel free to use the ideas for anything you would be using if you think it could be helpful.
It parses somewhat slowly in development mode but when compiled, it is fairly fast.
This is the NB pub file
This is the compiled file
This is a sample XML file you can test with.
Feedback is welcome. I am aware of small issue when a value is clicked.
David P.
This sample shows how you can browse for an XML, display its root element and a list of all child elements and values. It allows you to export a section of the XML at the child level. It has no editing functions. It also does not validate the xml ( you would usually do this first but I am working in an environment where the files are already in production).
I parse to the 8th child level but you will see from the NB scripting that this can be easily expanded to whatever level you will be working.
This for me is more of a proof of concept than anything. Feel free to use the ideas for anything you would be using if you think it could be helpful.
It parses somewhat slowly in development mode but when compiled, it is fairly fast.
This is the NB pub file
This is the compiled file
This is a sample XML file you can test with.
Feedback is welcome. I am aware of small issue when a value is clicked.
David P.
-
- Posts: 419
- Joined: Thu Oct 15, 2009 3:43 pm
omg
here is a function to parse XML DOM tree (tags with #text only) with any level of nesting.
[%1] - place this parameter for local or url path to xml
Call "XML" "Local or url path to xml"
results placed to tag named arrays.
here is a function to parse XML DOM tree (tags with #text only) with any level of nesting.
Code: Select all
On Error resume next
Dim i, xmlDoc
set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("[%1]")
Iteration(XMLDoc.documentElement)
Sub Iteration(theNode)
nodeinfo = theNode.NodeName
If theNode.NodeName = "#text" Then
chk=nbGetVar ("["&theNode.parentnode.NodeName&i&"]")
If Len(chk)>0 OR IsEmpty(i) then i=i+1
nbsetvar "["&theNode.parentnode.NodeName&i&"]", theNode.nodeValue
End if
Dim cnodes, citem, x
Set cnodes = theNode.ChildNodes
x = cnodes.length
If Not ( x < 1 ) Then
For Each citem In cnodes
Iteration(citem)
Next
End If
End Sub
Call "XML" "Local or url path to xml"
results placed to tag named arrays.
Thanks Tony,Tony Kroos wrote:omg
here is a function to parse XML DOM tree (tags with #text only) with any level of nesting..
There are times when you seek to gain a mastery of understanding, you start off doing something without the final product someone else made. This was that kind of project for me. In fact, our recent conversation on doing sorting caused me to think through how one would do sorting without the use of other tools in the NB tool set.
I consider my XML project a phase one effort. I plan to revisit it again and I will include such methods as you present.
David P.
-
- Posts: 419
- Joined: Thu Oct 15, 2009 3:43 pm
-
- Posts: 198
- Joined: Thu Apr 19, 2007 6:58 am
- Location: Brazil
Re:
Tony, I am picking up my XML parser again to improve it and clarify subroutines and possible formation of functions.Tony Kroos wrote:omg
here is a function to parse XML DOM tree (tags with #text only) with any level of nesting.
[%1] - place this parameter for local or url path to xmlCode: Select all
On Error resume next Dim i, xmlDoc set xmlDoc=CreateObject("Microsoft.XMLDOM") xmlDoc.async="false" xmlDoc.load("[%1]") Iteration(XMLDoc.documentElement) Sub Iteration(theNode) nodeinfo = theNode.NodeName If theNode.NodeName = "#text" Then chk=nbGetVar ("["&theNode.parentnode.NodeName&i&"]") If Len(chk)>0 OR IsEmpty(i) then i=i+1 nbsetvar "["&theNode.parentnode.NodeName&i&"]", theNode.nodeValue End if Dim cnodes, citem, x Set cnodes = theNode.ChildNodes x = cnodes.length If Not ( x < 1 ) Then For Each citem In cnodes Iteration(citem) Next End If End Sub
Call "XML" "Local or url path to xml"
results placed to tag named arrays.
I was able to implement your function but I notice that it does nothing with attributes or comments. It parses and appears to create a variable for each element's name with the with the value of that variable displayed. When I loaded very complex xml into it, it did not see all elements on each level. It stopped after following an extended set of child nodes.
Have you developed this at all? Or what are you using it for?
David P.
David Payer
Des Moines, Iowa
USA
Des Moines, Iowa
USA
-
- Posts: 419
- Joined: Thu Oct 15, 2009 3:43 pm
Re: XML parser - no plugins - only NB actions
It was just a very simple example of iteration procedure, if you apply this xml example and expected result I would try to improve it.
Re: XML parser - no plugins - only NB actions
Thanks.Tony Kroos wrote:It was just a very simple example of iteration procedure, if you apply this xml example and expected result I would try to improve it.
D
David Payer
Des Moines, Iowa
USA
Des Moines, Iowa
USA