checking for xml tag/xml data??? 
Author Message
 checking for xml tag/xml data???

Presently I am working with VB 6.0 SP5, MSXML3.0, Win 2000 Server

My problem is:

I need to query a XML struture (which is successfully loaded within my XML
DOM object), to deteremine if the tag structure exist, prior to performing
my xPath Query.

for example using XML structure:

<top>
    <one>test data</one>
    <two>test data</two>
    <three>test data</three>
    <four>test data</four>
</top>

suppose I want to set some variable equal to the data from tag-set
"<five></five>" (which does not exist within this particular XML structure,
but might be in the next xml file my component will process).

How do I first check to see if the structure exist to avoid issuing a XPath
query which will render an error. (See sample code below):
---------------------------------------
dim xmlDataStructure as String
dim xmlDoc as New DOMDocument
dim xQuery as String
dim xmlData as String

xmlDataStructure = "c:\test\test-xml.xml"
xmlDoc.load (xmlDataStructure)

xQuery = "top/five"

'-- Check to see if tag exist prior to issuing xPath Query to avoid Error

if (isNull(xmlDoc.selectSingleNode(xQuery))) then
    msgbox ("tree structure NOT Found")
else
    xmlData = xmlDoc.selectSingleNode(xPath).text
end if

--------------------------------------------

Problem:
My application fails on the "isNull" test. I KNOW the xml tag-set for
"<five></five>" does not exist in this particular xml file but it might
exist on the following (hence the reason for testing prior to setting my
variable equal to this value)

I am able to get an error code of "0" but no "reason" when executing the
following commands:
msgbox(xmlDoc.parseError.errorCode) ----> 0
msgbox(xmlDoc.parseError.reason) ---->

what is the proper way to check and determine if this structure exists so
that I can execute the query appropriately and NOT have the error I am
currently recieving.

Any help is GREATLY APPRECIATED!
vix



Tue, 23 Dec 2003 02:14:16 GMT  
 checking for xml tag/xml data???
Despite the way that the documentation reads, the selectSingleNode function
doesn't return Null if it doesn't find a matching node, it returns Nothing.

Try

    If xmlDoc.selectSingleNode(xQuery) Is Nothing Then

instead.

Hope this helps.

Best regards,

Ade.

Quote:

> Presently I am working with VB 6.0 SP5, MSXML3.0, Win 2000 Server

> My problem is:

> I need to query a XML struture (which is successfully loaded within my XML
> DOM object), to deteremine if the tag structure exist, prior to performing
> my xPath Query.

> for example using XML structure:

> <top>
>     <one>test data</one>
>     <two>test data</two>
>     <three>test data</three>
>     <four>test data</four>
> </top>

> suppose I want to set some variable equal to the data from tag-set
> "<five></five>" (which does not exist within this particular XML
structure,
> but might be in the next xml file my component will process).

> How do I first check to see if the structure exist to avoid issuing a
XPath
> query which will render an error. (See sample code below):
> ---------------------------------------
> dim xmlDataStructure as String
> dim xmlDoc as New DOMDocument
> dim xQuery as String
> dim xmlData as String

> xmlDataStructure = "c:\test\test-xml.xml"
> xmlDoc.load (xmlDataStructure)

> xQuery = "top/five"

> '-- Check to see if tag exist prior to issuing xPath Query to avoid Error

> if (isNull(xmlDoc.selectSingleNode(xQuery))) then
>     msgbox ("tree structure NOT Found")
> else
>     xmlData = xmlDoc.selectSingleNode(xPath).text
> end if

> --------------------------------------------

> Problem:
> My application fails on the "isNull" test. I KNOW the xml tag-set for
> "<five></five>" does not exist in this particular xml file but it might
> exist on the following (hence the reason for testing prior to setting my
> variable equal to this value)

> I am able to get an error code of "0" but no "reason" when executing the
> following commands:
> msgbox(xmlDoc.parseError.errorCode) ----> 0
> msgbox(xmlDoc.parseError.reason) ---->

> what is the proper way to check and determine if this structure exists so
> that I can execute the query appropriately and NOT have the error I am
> currently recieving.

> Any help is GREATLY APPRECIATED!
> vix



Tue, 23 Dec 2003 03:19:03 GMT  
 checking for xml tag/xml data???
Many thanks to you Adrian, you suggestion solved my problem!!
Thanks!

vix


Quote:
> Despite the way that the documentation reads, the selectSingleNode
function
> doesn't return Null if it doesn't find a matching node, it returns
Nothing.

> Try

>     If xmlDoc.selectSingleNode(xQuery) Is Nothing Then

> instead.

> Hope this helps.

> Best regards,

> Ade.




- Show quoted text -

Quote:
> > Presently I am working with VB 6.0 SP5, MSXML3.0, Win 2000 Server

> > My problem is:

> > I need to query a XML struture (which is successfully loaded within my
XML
> > DOM object), to deteremine if the tag structure exist, prior to
performing
> > my xPath Query.

> > for example using XML structure:

> > <top>
> >     <one>test data</one>
> >     <two>test data</two>
> >     <three>test data</three>
> >     <four>test data</four>
> > </top>

> > suppose I want to set some variable equal to the data from tag-set
> > "<five></five>" (which does not exist within this particular XML
> structure,
> > but might be in the next xml file my component will process).

> > How do I first check to see if the structure exist to avoid issuing a
> XPath
> > query which will render an error. (See sample code below):
> > ---------------------------------------
> > dim xmlDataStructure as String
> > dim xmlDoc as New DOMDocument
> > dim xQuery as String
> > dim xmlData as String

> > xmlDataStructure = "c:\test\test-xml.xml"
> > xmlDoc.load (xmlDataStructure)

> > xQuery = "top/five"

> > '-- Check to see if tag exist prior to issuing xPath Query to avoid
Error

> > if (isNull(xmlDoc.selectSingleNode(xQuery))) then
> >     msgbox ("tree structure NOT Found")
> > else
> >     xmlData = xmlDoc.selectSingleNode(xPath).text
> > end if

> > --------------------------------------------

> > Problem:
> > My application fails on the "isNull" test. I KNOW the xml tag-set for
> > "<five></five>" does not exist in this particular xml file but it might
> > exist on the following (hence the reason for testing prior to setting my
> > variable equal to this value)

> > I am able to get an error code of "0" but no "reason" when executing the
> > following commands:
> > msgbox(xmlDoc.parseError.errorCode) ----> 0
> > msgbox(xmlDoc.parseError.reason) ---->

> > what is the proper way to check and determine if this structure exists
so
> > that I can execute the query appropriately and NOT have the error I am
> > currently recieving.

> > Any help is GREATLY APPRECIATED!
> > vix



Tue, 23 Dec 2003 03:41:16 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Extracting data from embedded XML tags in Outlook e-mails

2. Need to loop through xml tags and put the data into an email

3. XML Tag look up VB.net?

4. XML - Multiple tags

5. Finding line breaks in XML putting in HTML tags

6. XML, Converting Word doc's to XML files (O'2000)

7. How to create a secure connection, send an xml msg and receive and xml response

8. Render XML+XSL into PrintDocument (not XML) ?

9. XML Newbie question, getting a value from an XML string

10. Parsing XML from an ASP page that Creates XML fails

11. Trying to append a simple XML document as a node in an XML document

 

 
Powered by phpBB® Forum Software