Fortunately, the xml parser is not a general parser that translates XML to an array. It just returns the text value of the node defined by the path.
To circumvent the issue, I decided to replicate the same functionality of the BaseElement plugin (BE_XPath() function). The function works like this. You pass it a XML and a path and it returns you the result. For exmaple, BE_XPath($xml;"//Data/myname") will return you the text value from the path. If there are more than one "Data" then you need to define it as a sort of array like Data[1].
It is not at all difficult to interpret the xml. There is just one step to do before parsing it. You need to add [Carriage Return] after every node. Usually the xml is returned as a continuous text without a carriage return character. What I need to do is just search for "><" and replace it with ">[CR]<". [CR] is the character code 13.
The result of doing such replacements means each node will be on a line ending with a carriage return. For example,
will be come
What you need to do is search for the path in the sequence for each line of the XML. My example uses Data and myname. So I just read each line and look for first. If it is found then I look for
If the path is Data[x], I just need to repeat the search for till the x occurrence is reached. It is as simple as that.
Once the node name is found, it is time to remove the xml node name. Well, it is quite simple. You simply replace the enclosing node names together with its XML markup as "". Don't worry as XML does not allow "<" and ">" to be part of node text.
Obviously, you need to look out for <myname/>
No comments:
Post a Comment