Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: reading XML elements with asp

From: "Joe Fawcett" <joefawcett@-------.--->
To: NULL
Date: 7/2/2004 2:26:00 PM
"sismis" <zbosnjak@g...> wrote in message 
news:cc3n4e$q1m$1@l......
> Hi!
>
> I need to fill the database with selected elements from XML, but cant get
> them apart.
>
> items.xml file:
> <?xml version="1.0" encoding="UTF-8"?>
> <dataroot xmlns:od="urn:schemas-microsoft-com:officedata"
> xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="items.xsd">
> <item>
>    <class>2</class>
>    <type>0</type>
>    <code>0101002</code>
> </item>
> <item>
>    <class>3</class>
>    <type>0</type>
>    <code>0102008</code>
> </item>
> <item>
>    <class>4</class>
>    <type>0</type>
>    <code>0101018</code>
> </item>
> ...
> </dataroot>
>
>
>
>
> ASP file:
> <%
> Dim sourceFile, source, rootElement, HTMLCode
>  'define xml file
>  sourceFile = Server.MapPath("items.xml")
> ' Create an instance of the XML parser and load the XML into the DOM
>     Set source = Server.CreateObject("Microsoft.XMLDOM")
>     source.async = false
>     source.load sourceFile
>     Set rootElement = source.documentElement
>     ' list them out
>      For i = 0 To (rootElement.childNodes.length -1)
>      Response.Write(rootElement.childNodes(i).text & "<br>")
>            ' the misty part here
>      Next
>
> The question: how to get elements by name into variable, say just <type> 
> and
> <code>, getElementsByTagName("ntype").item(0).text or???
>
>
>
> Thnx
>
>
Firstly do not use "microsoft.xmldom". Find out what version your server 
has, hopefully version 4.0, and use the specific id, e.g. 
"MsXml2.DomDocument.4.0".
Next you're better placed if you use XPath to select the nodes you want 
rather than use the DOM:
Set source = Server.CreateObject("MsXml2.DomDocument.4.0")
source.async = false
source.load sourceFile
Set rootElement = source.documentElement
Set colNodes = rootElement.selectNodes("item")

For i = 0 To colNodes.length - 1
  Set nodeType = colNodes(i).selectSingleNode("type")
 Set nodeCode = colNodes(i).selectSingleNode("code")
 Response.Write i & ") Type: " & nodeType.text & ", Code: " & nodeCode.text 
& "<br>"
Next

-- 

Joe (MVP - xml)




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent