473,787 Members | 2,971 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Read nested nodes in XML file with ASP


Hello,
I have to read a XML file in ASP and save the values in a database. I
can get this work, but I cannot read some nested nodes of the xml file.

This is a part of the XML file:

<Interface>
<Product>
<CategoryFeatur eGroup ID="622" No="1">
<FeatureGroup ID="0">
<Name ID="5073" Value="Technica l details" langid="1" />
<Name ID="5074" Value="Technisc he details" langid="2" />
<Name ID="8345" Value="Détails techniques" langid="3" />
<Name ID="16114" Value="Technisc he Details" langid="4" />
<Name ID="20246" Value="Technica l details" langid="5" />
<Name ID="24378" Value="Technica l details" langid="6" />
</FeatureGroup>
</CategoryFeature Group>
<CategoryFeatur eGroup ID="42" No="60">
<FeatureGroup ID="3">
<Name ID="4863" Value="Memory" langid="1" />
<Name ID="4864" Value="Geheugen " langid="2" />
<Name ID="7176" Value="Mémoire vive" langid="3" />
<Name ID="16018" Value="Speicher " langid="4" />
<Name ID="20150" Value="Memory" langid="5" />
<Name ID="24282" Value="Memory" langid="6" />
</FeatureGroup>
</CategoryFeature Group>
</Product>
</Interface>
I read the node <CategoryFeatur eGroupwith the following code:

Set rootNode = xmlDoc.selectSi ngleNode("Inter face/Product")
For Each Node in rootNode.select Nodes("Category FeatureGroup")
Waarde(n) =
xmlDoc.getEleme ntsByTagName("C ategoryFeatureG roup").item(n). getAttribute("I D")
n=n+1
Next

Now I also have to read the values from <FeatureGroupan d the <Name>
elements within every <CategoryFeatur eGroup>. Can someone tell me how
to do this within the ASP code above?

Thanks for any help!
Nick

Sep 28 '06 #1
4 7901

"Pim75" <p.******@tisca li.nlwrote in message
news:11******** **************@ k70g2000cwa.goo glegroups.com.. .
>>>>
Hello,
I have to read a XML file in ASP and save the values in a database. I
can get this work, but I cannot read some nested nodes of the xml file.

This is a part of the XML file:

<Interface>
<Product>
<CategoryFeatur eGroup ID="622" No="1">
<FeatureGroup ID="0">
<Name ID="5073" Value="Technica l details" langid="1" />
<Name ID="5074" Value="Technisc he details" langid="2" />
<Name ID="8345" Value="Détails techniques" langid="3" />
<Name ID="16114" Value="Technisc he Details" langid="4" />
<Name ID="20246" Value="Technica l details" langid="5" />
<Name ID="24378" Value="Technica l details" langid="6" />
</FeatureGroup>
</CategoryFeature Group>
<CategoryFeatur eGroup ID="42" No="60">
<FeatureGroup ID="3">
<Name ID="4863" Value="Memory" langid="1" />
<Name ID="4864" Value="Geheugen " langid="2" />
<Name ID="7176" Value="Mémoire vive" langid="3" />
<Name ID="16018" Value="Speicher " langid="4" />
<Name ID="20150" Value="Memory" langid="5" />
<Name ID="24282" Value="Memory" langid="6" />
</FeatureGroup>
</CategoryFeature Group>
</Product>
</Interface>
I read the node <CategoryFeatur eGroupwith the following code:

Set rootNode = xmlDoc.selectSi ngleNode("Inter face/Product")
For Each Node in rootNode.select Nodes("Category FeatureGroup")
Waarde(n) =
xmlDoc.getEleme ntsByTagName("C ategoryFeatureG roup").item(n). getAttribute("I D
")
n=n+1
Next

Now I also have to read the values from <FeatureGroupan d the <Name>
elements within every <CategoryFeatur eGroup>. Can someone tell me how
to do this within the ASP code above?

Thanks for any help!
Nick

<<<<

You select each CategroyFeature Group into a Node variable but then don't use
the variable.

For Each Node in rootNode.select Nodes("Category FeatureGroup")
Waarde(n) = node.getAttribu te("ID")
n=n+1
Next

Why is this data ending up in an array?
Where do you want to put the other data?

It seems to me you want to build a whole bunch of arrays of variables to
then update a DB. Which Database are you using?

A good solution would avoid loading up a set of variables and arrays but
simply take the content of the XML more directly to the DB.
Anthony

Sep 28 '06 #2
Hello Anthony,

Thanks for your reply.
After collecting the data I want to insert in into different tables in
my MS SQL 2000 database. In my ASP script I use various sql statements
for this.

I know there's bulk load function in SQL server, but as the XML file is
a bit complex I can't get this done with bulk load. Constructing the
right xsd is pretty difficult for me, also because there are about 10
different tables where data has te be inserted.

Do you have any experience with this?
Your help is really welcome.

best regards,
Nick

Sep 28 '06 #3

"Pim75" <p.******@tisca li.nlwrote in message
news:11******** **************@ i42g2000cwa.goo glegroups.com.. .
Hello Anthony,

Thanks for your reply.
After collecting the data I want to insert in into different tables in
my MS SQL 2000 database. In my ASP script I use various sql statements
for this.

I know there's bulk load function in SQL server, but as the XML file is
a bit complex I can't get this done with bulk load. Constructing the
right xsd is pretty difficult for me, also because there are about 10
different tables where data has te be inserted.

Do you have any experience with this?
Yes plenty.

I suggest you take a look in SQL Server Books Online at the OPENXML
function.

In cases like this I simply pass the XML on to a SQL Server SP and do all
the work in there.

Here is the general idea:-
<%

Dim oDOM : Set oDOM = Server.CreateOb ject("MSXML2.DO MDocument.3.0")
oDOM.async = False
oDOM.load Request

' Code here to make any adjustments and validations of the XML

Dim sXML

sXML = oDOM.xml

Dim cmd : Set cmd = Server.CreateOb ject("ADODB.Com mand")

Set cmd.ActiveConne ction = GetConn()
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "SP_Process_XML "

cmd.parameters. append cmd.createparam eter("@xml", adLongVarWChar,
adParamInput, Len(sXML), sXML)

cmd.Execute

cmd.close

%>
CREATE PROCEDURE SP_Process_XML
@xml ntext,
AS

DECLARE @hdoc int

EXEC sp_xml_prepared ocument @hdoc OUTPUT, @xml

INSERT tblCatFeatureGr oup (tblCatFeatureG roup_ID, featNo)
SELECT [id], featNo
FROM OPENXML (@hdoc, '//CategoryFeature Group', 2)
WITH ([id] int '@ID', featNo int '@No') doc

INSERT tblFeatureGroup Name (tblFeatureGrou pName_ID, Feature_ID,
tblCatFeatureGr oup_ID, [Name])
SELECT [id], featID, catID, [name]
FROM OPENXML (@hdoc, '//FeatureGroup/Name', 2)
WITH ([id] int '@ID', featID int '../@ID', catID int '../../@ID', [name]
nvarchar(50) '@Value') doc
EXEC sp_xml_removedo cument @hdoc

Your help is really welcome.

best regards,
Nick

Sep 28 '06 #4
Tested with OPENXML and yes, this works really great :)
One thing... when I'm going to import more XML files after eachother,
there can be duplicate values for <category_featu re_group>.

What I discovered is that all values for <category_featu re_groupin
the XML file are skipped when there's one duplicate record found in the
corresponding table.

Is there a way to skip duplicate values and only add the values that
are not already in the table? At this moment I use the command:

INSERT INTO Category_featur e_group (category_featu re_group_id, catid,
feature_group_i d, no)
SELECT *
FROM OPENXML (@index, 'ICECAT-interface/Product/CategoryFeature Group')
WITH (ID int, ID int '../Category/@ID', ID int 'FeatureGroup/@ID', No
int)

Thanks again!

Sep 30 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
3983
by: Jeff Lanfield | last post by:
First of all, I apologize if coalescing is not the right term to describe my problem. I have a tree where each node has the same set of attributes (is the same entity) but child nodes should inherit attribute values from parent node. for example, say I have the following table: (nodeId int , color varchar, phone varchar) with two rows 5, "GREEN", "555-1212"
0
1535
by: GR33DY | last post by:
Hi every-one, I'm rather new to this, so I'll just jump in. I have an XML file that looks like this: _____________________________XML_________________________________ <root> <nextlevel>
3
1707
by: GR33DY | last post by:
Hi every-one, (Deleted and reposted to avoid sp@m) I have an XML file that looks like this: _____________________________XML_________________________________ <root> <nextlevel>
6
1560
by: Paul M | last post by:
hi there, i have an xml file, but am not too sure how to read all these elements using vb.net code. any help would be greatly appreciated:)) <---------CODE---------------> <?xml version="1.0" encoding="utf-8"?> <weatherFeed>
6
2179
by: jwvai316 | last post by:
I don't really know how to say it so I just say it a nested linklist. How do you make LinkLists inside LinkList? Can anyone help me for this? I think an example program will help me a lot. thank you.
5
2986
by: BMeyer | last post by:
I have been losing my mind trying to parse an XML document (with nested child elements, not all of which appear in each parent node) into a DataGrid object. What I want to do is "flatten" the XML document into a text document with a single row for each parent node (that has all of the values from all of the child nodes for that row) The DataView within VS 2005 IDE displays my 15 or so child tables - and knows that some parent rows...
4
16699
by: Gerrit | last post by:
It must be simple, but I don't find how I can read a XmlFile in an ArrayList. Sample of my XmlFile: <?xml version="1.0" encoding="utf-8" ?> <Relations> <Person> <FirstName>John</FirstName> <LastName>Smith</LastName>
2
2436
by: th3dude | last post by:
I am trying to pull out some nested XML using C# and XMLReader. Can't seem to extract the "Items" for each "Product" when i loop through file, i can loop over the "Product" notes just fine but everytime i perform a nested loop over the "Items" list i keep every item on the file listed for each "Product". Is there an easy approach to get the related Items for each Product ID instead of all the Items everytime?
6
7275
by: | last post by:
Hi, I'm steel trying to read and update my XML file with Visual Basic Express but i am unable to find the right way to read my xml file and update it if neccessary... Here is my problem : evry day, i store the number of children in my classroom in my XML file. For exemple, on monday, my app ask me something like this : msgbox ("Are the 28 children here today ?",vbyesno)
0
10169
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6749
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.