This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > Microsoft XML > April 2007 > Performance question.
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Performance question.
|
|
| Jürgen Germonpré 2007-04-17, 6:28 pm |
| Hi all,
I'm a beginner in this matter.
I need to import an XML file which contains a header an a first reply which
is slighty different from the replies included here.
So far so good. All next replies (t.i. from 2 to undefined) have the same
structure (see end of post).
What I need to extract is the Xpath (with this query I'm getting information
out of another XML file), all related Message (attribute code and severity)
and MessageContent (attribute key and value).
Now I'm accessing the data using statements as the following. Basically I
use the same technique, I just change the xpath expressions in the
selectNodes method:
Dim oElement, oElement3, oElement4 As IXMLDOMElement
Set oElement3 = oElement.selectNodes(".//Replies/Reply[@seq != '1']")
For Each oElement4 In oElement3
'DoSomething with oElement4
myVar = oElement4.Text
...
'Another loop
oElements = oElement4.selectNodes(".//Replies/Reply/Messages")
For Each oElement5 in oElements
...
Next
Next
....
However I think there might be a more performant solution... than mine?
I will have to treat large files with my app so i need all the speed and
stability i can get.
Any clues ?
Thanks.
JG
SAMPLE XML
----------------
<Header>
Here goes info which is unique within the file
</Header>
<Replies>
<Reply seq="2">
<XPath>/Request/Create[@seq="1"]/Addresses/Address[@seq="1"]</XPath>
<Positions>
<Position Name="Item" attName="seq" attValue="1"/>
</Positions>
<Messages>
<Message code="ERR-A030" severity="INFO">
<MessageContents>
<MessageContent key="hwE" value="R2"/>
</MessageContents>
</Message>
</Messages>
</Reply>
<Reply seq="3">
<XPath>/Request/Create[@seq="1"]/Addresses/Address[@seq="2"]</XPath>
<Positions>
<Position Name="Item" attName="seq" attValue="2"/>
</Positions>
<Messages>
<Message code="ERR-A030" severity="INFO">
<MessageContents>
<MessageContent key="hwE" value="M2"/>
</MessageContents>
</Message>
</Messages>
and so on......
</Replies>
| |
| Martin Honnen 2007-04-17, 6:28 pm |
| Jürgen Germonpré wrote:
> Set oElement3 = oElement.selectNodes(".//Replies/Reply[@seq != '1']")
> oElements = oElement4.selectNodes(".//Replies/Reply/Messages")
> For Each oElement5 in oElements
> ...
> Next
> Next
> ...
>
> However I think there might be a more performant solution... than mine?
> I will have to treat large files with my app so i need all the speed and
> stability i can get.
Doing .// is expensive as it requires the XPath processor to look for
all descendant elements at all levels. If you know the structure of the
XML and the structure is not recursive then giving a precise path
accessing the level you are looking for should suffice and perform
better e.g.
/Root/Replies/Reply[@seq != '1']
With the structure of the sample XML you posted I don't understand why
you do the inner
oElement4.selectNodes(".//Replies/Reply/Messages")
I would rather expect you simply want
oElement4.selectNodes("Messages")
as the Messages elements are children of the Reply elements.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
| |
| Jürgen Germonpré 2007-04-18, 6:16 am |
| > Doing .// is expensive as it requires the XPath processor to look for all
> descendant elements at all levels. If you know the structure of the XML
> and the structure is not recursive then giving a precise path accessing
> the level you are looking for should suffice and perform better e.g.
> /Root/Replies/Reply[@seq != '1']
>
> With the structure of the sample XML you posted I don't understand why you
> do the inner
> oElement4.selectNodes(".//Replies/Reply/Messages")
> I would rather expect you simply want
> oElement4.selectNodes("Messages")
> as the Messages elements are children of the Reply elements.
>
Dear Martin,
I took into account your guidlines. At first view it seems to go faster,
although I got to do more extensive testing.
As i'm just a beginner, i tend to go the quick & dirty way to get results
fast.... help on finetuning is much appreciated.
Thanks.
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|