Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 2nd, 2006, 03:48 AM
Registered User
 
Join Date: Oct 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Retrieve Field Name & Value from XML in asp

Hello,

I am new to xml and I have a xml document that I am trying to parse data and display in a html page.

Here is some of the xml document I have:

<?xml version="1.0" ?>
- <Results>
<ResultCode>0</ResultCode>
<ResultDescription>OK</ResultDescription>
- <ResultData recordcount="18">
+ <Record>
- <field name="PackageTypeId">
<value>156</value>
</field>
- <field name="ResellerPackageType">
<value>0</value>
</field>
- <field name="ResellerAccountNumber">
<value>RS11</value>
</field>
- <field name="PackageTypeName">
<value>Basic Plan Monthly</value>
</field>
- <field name="DNSEnabled">
<value>-1</value>
</field>
- <field name="WebEnabled">
<value>-1</value>
</field>
- <field name="FTPEnabled">
<value>-1</value>
</field>
- <field name="MailEnabled">
<value>-1</value>
</field>
- <field name="StatsEnabled">
<value>-1</value>
</field>
- <field name="DNSResourceId">
<value>1</value>
</field>
- <field name="WebResourceId">
<value>2</value>
</field>
- <field name="FTPResourceId">
<value>4</value>
</field>
- <field name="MailResourceId">
<value>8</value>
</field>
- <field name="StatsResourceId">
<value>7</value>
</field>
- <field name="SetupFee">
<value>0</value>
</field>
- <field name="RecurringFee">
<value>4.95</value>
</field>
- <field name="RecurranceInterval">
<value>1</value>
</field>
- <field name="RecurranceIntervalType">
<value>M</value>
</field>
- <field name="DBEnabled">
<value>-1</value>
</field>
- <field name="DBResourceId">
<value>5</value>
</field>
- <field name="Active">
<value>-1</value>
</field>
- <field name="LastModified">
<value>2/28/2006 2:10:49 PM</value>
</field>
- <field name="NumPackages">
<value>4</value>
</field>
</Record>
- <Record>
- <field name="PackageTypeId">
<value>157</value>
</field>
- <field name="ResellerPackageType">
<value>0</value>
</field>
- <field name="ResellerAccountNumber">
<value>RS11</value>
</field>
- <field name="PackageTypeName">
<value>Basic Plan Yearly</value>
</field>
- <field name="DNSEnabled">
<value>-1</value>
</field>
- <field name="WebEnabled">
<value>-1</value>
</field>
- <field name="FTPEnabled">
<value>-1</value>
</field>
- <field name="MailEnabled">
<value>-1</value>


The question I have is how can I pull the field name and value and display in a table: for example:

PackageTypeId: 156
PackageTypeName: Basic Plan Monthly
Recurring Fee: 4.95
etc

Thanks in advance for any help provided.

Andie
 
Old October 2nd, 2006, 06:27 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Something like this:

<xsl:template match="Record">
  <table>
    <xsl:for-each select="field">
      <tr>
        <td><xsl:value-of select="@name"/></td>
        <td><xsl:value-of select="value"/></td>
      </tr>
    </xsl:for-each>
  </table>
</xsl:template>


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old October 3rd, 2006, 03:20 AM
Registered User
 
Join Date: Oct 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks,

How would I store the names and values in variables, I was looking at this post as it is similar to what I want to do, but I am a little lost as my xml layout I have as in my first post looks different in terms of the filed and value tags.

http://p2p.wrox.com/topic.asp?TOPIC_ID=37209

If you could give me a general pointer that would be much appreciated.


Andie

 
Old October 3rd, 2006, 03:28 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It's difficult to answer your question. I'm not sure what you want to put in variables, or why. Please explain what you actually want to achieve - putting something in a variable may or may not be part of the solution.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old October 3rd, 2006, 04:32 AM
Registered User
 
Join Date: Oct 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am wanting to import the xml info to a table in a database, I was thinking of using variables, and then using the variables in an sql statement to add to a database.

 
Old October 3rd, 2006, 06:05 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Sounds as if you're planning to read the document into a DOM from your ASP page and then write it to the database by constructing SQL statements, yes? Sorry, for some reason I thought you meant XSLT variables. I'm no expert on the ASP/DOM/SQL combination but there are plenty of books around in this space.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old October 3rd, 2006, 12:52 PM
Registered User
 
Join Date: Oct 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, I can do the other stuff, just need to know how I can put the name and value from the elements, this example does similar to what I am trying to do but the know the name of the elements.

http://p2p.wrox.com/topic.asp?TOPIC_ID=37209








Similar Threads
Thread Thread Starter Forum Replies Last Post
Retrieve Autonumber field and update it carrie09 Access VBA 3 November 2nd, 2007 07:32 AM
Retrieve different data from same table /field W052107 Visual Studio 2005 7 August 6th, 2007 10:40 AM
How to retrieve ID field of newly-created record Steve777 Classic ASP Professional 3 October 2nd, 2006 11:27 AM
Retrieve recordset field value tryntolearn Classic ASP Databases 1 August 8th, 2005 10:22 AM
sql & join tables & find a field in multiple table trangd Beginning PHP 2 January 29th, 2004 07:18 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.