Traverse Child Nodes

I have an xml document that looks like:
<Areas>
<record><AREA_ID>1</AREA_ID><AREA>Yard</AREA></record>
<record><AREA_ID>2</AREA_ID><AREA>Street</AREA></record>
<record><AREA_ID>3</AREA_ID><AREA>Park</AREA></record>
<record><AREA_ID>4</AREA_ID><AREA>Area</AREA></record>
</Areas>

I want to turn that into four INSERT statements:
INSERT INTO Areas (AREA_ID, AREA) VALUES (1,'YARD');

So, I can get a node list of 4 nodes from the xpath 'Areas/record'
The innerXML is:  <AREA_ID>1</AREA_ID><AREA>Yard</AREA>
The outerXML is:  <record><AREA_ID>1</AREA_ID><AREA>Yard</AREA></record>

Now I don't want to use the actual names just the index because this will be 
generic.
So now I need to know ... how do I get those sub-nodes (AREA_ID and AREA)?

Thanks!
                                Tom 

0
tom4780 (3)
9/12/2007 4:40:08 AM
dotnet.xml 7266 articles. 0 followers. Follow

4 Replies
534 Views

Similar Articles

[PageSpeed] 5

* Tom Holmes Jr. wrote in microsoft.public.dotnet.xml:
>I have an xml document that looks like:
><Areas>
><record><AREA_ID>1</AREA_ID><AREA>Yard</AREA></record>
><record><AREA_ID>2</AREA_ID><AREA>Street</AREA></record>
><record><AREA_ID>3</AREA_ID><AREA>Park</AREA></record>
><record><AREA_ID>4</AREA_ID><AREA>Area</AREA></record>
></Areas>
>
>I want to turn that into four INSERT statements:
>INSERT INTO Areas (AREA_ID, AREA) VALUES (1,'YARD');
>
>So, I can get a node list of 4 nodes from the xpath 'Areas/record'
>The innerXML is:  <AREA_ID>1</AREA_ID><AREA>Yard</AREA>
>The outerXML is:  <record><AREA_ID>1</AREA_ID><AREA>Yard</AREA></record>
>
>Now I don't want to use the actual names just the index because this will be 
>generic.
>So now I need to know ... how do I get those sub-nodes (AREA_ID and AREA)?

You don't say what you are using to process the document; if you are
using a XmlDocument as your use of InnerXml and OuterXml would indi-
cate, you can iterate over the children of a node using the .Child-
Nodes property, or the .FirstChild / .NextSibling properties. You'll
have to check their type when doing so, and retrieve the name using
the .LocalName property. This is a very basic question though, you
might want to check out some DOM tutorials. I also note that this is
a simple transformation and you could easily use XSLT for the task.
-- 
Bj�rn H�hrmann � mailto:bjoern@hoehrmann.de � http://bjoern.hoehrmann.de
Weinh. Str. 22 � Telefon: +49(0)621/4309674 � http://www.bjoernsworld.de
68309 Mannheim � PGP Pub. KeyID: 0xA4357E78 � http://www.websitedev.de/ 
0
bjoern1 (135)
9/12/2007 4:54:48 AM
Tom Holmes Jr. wrote:

> Now I don't want to use the actual names just the index because this 
> will be generic.
> So now I need to know ... how do I get those sub-nodes (AREA_ID and AREA)?

Use relative XPath expressions in the form *[index] e.g.
   *[1]
   *[2]
and apply them (using SelectSingleNode for instance) on the record 
element nodes you have.
* selects all child elements, *[1] the first child element, *[2] the 
second and so one.


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1778)
9/12/2007 12:40:53 PM
Thanks Bjoern, I do very much appreciate the help.

I'm mostly a Java Developer and haven't touched VB in almost 10 years.
I've used DOM, SAX, JDOM, and a bunch of stuff in java for years, so I am an 
old hand there.

I am using XMLDocument like I did in the old days and I did use ChildNodes 
to iterate through them.
So, I got it working now.    And yeah, i could use XSLT, but damn ... that's 
not easy stuff sometimes.
If someone else wrote the XSLT I could use Java to do the transformation, 
but don't ask me to write that XSLT.

Thanks again very much!    :-)

                                                                  Tom

"Bjoern Hoehrmann" <bjoern@hoehrmann.de> wrote in message 
news:q0see3tmtrac22pp1q51qakt3m05q92m3l@hive.bjoern.hoehrmann.de...
>* Tom Holmes Jr. wrote in microsoft.public.dotnet.xml:
>>I have an xml document that looks like:
>><Areas>
>><record><AREA_ID>1</AREA_ID><AREA>Yard</AREA></record>
>><record><AREA_ID>2</AREA_ID><AREA>Street</AREA></record>
>><record><AREA_ID>3</AREA_ID><AREA>Park</AREA></record>
>><record><AREA_ID>4</AREA_ID><AREA>Area</AREA></record>
>></Areas>
>>
>>I want to turn that into four INSERT statements:
>>INSERT INTO Areas (AREA_ID, AREA) VALUES (1,'YARD');
>>
>>So, I can get a node list of 4 nodes from the xpath 'Areas/record'
>>The innerXML is:  <AREA_ID>1</AREA_ID><AREA>Yard</AREA>
>>The outerXML is:  <record><AREA_ID>1</AREA_ID><AREA>Yard</AREA></record>
>>
>>Now I don't want to use the actual names just the index because this will 
>>be
>>generic.
>>So now I need to know ... how do I get those sub-nodes (AREA_ID and AREA)?
>
> You don't say what you are using to process the document; if you are
> using a XmlDocument as your use of InnerXml and OuterXml would indi-
> cate, you can iterate over the children of a node using the .Child-
> Nodes property, or the .FirstChild / .NextSibling properties. You'll
> have to check their type when doing so, and retrieve the name using
> the .LocalName property. This is a very basic question though, you
> might want to check out some DOM tutorials. I also note that this is
> a simple transformation and you could easily use XSLT for the task.
> -- 
> Bj�rn H�hrmann � mailto:bjoern@hoehrmann.de � http://bjoern.hoehrmann.de
> Weinh. Str. 22 � Telefon: +49(0)621/4309674 � http://www.bjoernsworld.de
> 68309 Mannheim � PGP Pub. KeyID: 0xA4357E78 � http://www.websitedev.de/ 

0
tom4780 (3)
9/13/2007 1:21:57 AM
Thanks Martin, I also appreciate your help as well.

I finally found and used the child nodes to get the elements, and then I 
iterated through them.
I might revist my code and see if I can make it more efficient using the 
XPath expression.

Thanks again!
                                 Tom


"Martin Honnen" <mahotrash@yahoo.de> wrote in message 
news:OrpVtoT9HHA.1168@TK2MSFTNGP02.phx.gbl...
> Tom Holmes Jr. wrote:
>
>> Now I don't want to use the actual names just the index because this will 
>> be generic.
>> So now I need to know ... how do I get those sub-nodes (AREA_ID and 
>> AREA)?
>
> Use relative XPath expressions in the form *[index] e.g.
>   *[1]
>   *[2]
> and apply them (using SelectSingleNode for instance) on the record element 
> nodes you have.
> * selects all child elements, *[1] the first child element, *[2] the 
> second and so one.
>
>
> -- 
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/ 

0
tom4780 (3)
9/13/2007 1:23:28 AM
Reply:

Similar Artilces:

Which Controls to Build a Parent/Child Web Form
Hi there, I'm quite new to asp.net, but know exactly how to do this using classic ASP, but would like some pointers for aspnet2. I've got data being returned from an SP which looks like this: HeaderItem ChildItem A A1 A A2 A A3 B B1 etc I want to display the data like this A - This is the header record A1 A2 A3 B - Header 2 B1 etc. In classic ASP I'd write out my header row html when HeaderItem changes value and then write the Child Rows. As I've on...

maximizing Child View
HI all I am New user for VC, and i have just install MVS.NET. i try to make test application. and try MFC application. but wizard make child window not maximized . Will some one help me how to do it.? and how to hendel child window in MFC. Thanks. Amrit There is a ton of information including the answer to this question in this FAQ. http://ai.kaist.ac.kr/~ymkim/Program/mfc_faq.html Tom "Amrit" <cadd@wlink.com.np> wrote in message news:OYLUU11JJHA.920@TK2MSFTNGP05.phx.gbl... > HI all > I am New user for VC, and i have just install MVS.NET. > > i try to ...

Update XML config file with treeview nodes
hey! what i wanna do sounds very simple at first, but it turned out to be a real bone crusher... i want to check if a treeView node is checked and if a correspondent node in my xml config file exists just to sort of synchronize them by changing the xml nodes attribute(s). somehow i always catch an exception "blabla has an invalid token" but i cannot find a solution for this. maybe someone of you people can tell me how to do this correctly. thanks in advance! =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=...

Installing Exchange 2007 SP2 on passive SCC node
Am trying to install exchange 2007 sp2 on the passive node, removed antivirus and MOM agent, restarted Remote Registry and started the the upgrade command. the problem is the setup is stuck on 64% with no errors. anyone can help? environment: - 2 windows 2003 64 R2 sp2 - 2 Exchange SCC SP1 Is there anything interesting in the setup log? -- Ed Crowley MVP "There are seldom good technological solutions to behavioral problems." .. "Batayneh" <Batayneh@discussions.microsoft.com> wrote in message news:F5B63827-1C18-4A65-B859-AA5B5642D116@micros...

Remove Node Complete with XmlNode.RemoveAll
I am attempting to remove a full node. XML Example: <Videos> <Video> <Name>Crocodile Dundee 2</Name> <Media>DVD</Media> </Video> <Video> <Name>Terminator 6</Name> <Media>DVD</Media> </Video> </Videos> Here, seeing Terminator 6 doesn't exist, I want to remove the movie reference. After loading the XML document and running the following code: Dim xmlNodeList As System.Xml.XmlNodeList = xmlDoc.SelectNodes("/Videos/Video") xmlNodeList.Item(1).RemoveAll it just removes ...

Child window is not displayed when parent window is maximized
Hi, I developing an ActiveX control, i have made Microsoft PPT.exe window as the child of my OCX window using SetParent function. Now when my IE window is minimized and maximized, then OCX window is refreshed but the PPT window which is child window of OCX window is not displayed on maximization of IE window. Same behavior is there when some other window overlaps the OCX window. Thanks Vibhor Mahajan ...

Traversing XSD
Hi there, Is there a way to traverse an XSD using XPath. My research indicates no conventional way of doing it, but I was wondering if there was a work around. Thanks for your help and time. MMA wrote: > Is there a way to traverse an XSD using XPath. My research indicates no > conventional way of doing it, but I was wondering if there was a work around. XSD is XML with namespaces so using XPath on an XSD document is possible. If you need help with a particular XPath then let us know details of the schema. ..NET also provides an XML Schema Object Model (SOM) which allows you t...

Traversing Directories
Hello, Is there a function that can be used to check if there is a subdirectory in a directory? I know there is a FindNextFile() from CFTPFileFind but I don't think it checks if there is a dirctory. Is there something similar to FindNextDirectory()? Thank you, Victor. You have to create your Own logic for that, there is no direct function to achieve that! -- cheers, Alok Gupta Visit me at http://alok.bizhat.com "victorsk" <victorsk@discussions.microsoft.com> wrote in message news:8D39F69B-2B1E-45DA-93F0-E770B9FA7C6E@microsoft.com... > Hello, > > Is there a...

Adding a 2008R2 Child Domain to a 2003R2 forest
I have a 2003R2 forest with two root servers in the root domain, A, and no other servers in that domain. Under that I have two child domains B, and C. I want to add a third child domain, D to this which will have two 2008R2 DCs that are not DNS servers. My plan is to move all the DCs to 2008R2 over the next several months but we have a requirement for another child domain and this seems like a good time to start moving to 2008R2 for the DCs. All DCs are 2003R2 servers and the domain is 2003 Functional level. I've read various sources including these and have some quest...

Quote-like parent-child mail merge possible on custom entities?
I have a client on CRM Online who needs to be able to print out a form document for a CRM record that includes header information from the record as well as a listing of child records from a one to many child entity. The Report Wizard does not give us nearly enough control to print the document in the required form format. The Quote, Order, and Invoice mail merges in CRM do something very similar to what we are trying to accomplish, so apparently it is possible to get this done in CRM. Does anyone know how to accomplish a new mail merge template in CRM that merges a custom parent rec...

child view and menu
I have MDI application. Main window contains child windows and I want to create for every child window it's own menu. SetMenu() returns with error: ERROR_CHILD_WINDOW_MENU. Does exist way to create menu in child window, or it is not possible ? Thx! Peter The way this is done is that you have a CMultiDocTemplate which specifies the document class, view class, frame class, and the IDR_ symbol for the resources, which include the menu, icon, and specification string. You would create your views from this. Or do you mean you want a menu in EACH child window, and all are the same type? I...

Can parent's timer handler execute while child window is being moved/resized/shown?
Could parent window's handler be called while a child window is being resized/moved as a result of a call to MoveWindow() or ShowWindow()? Let's say that I have the following code: CParentWnd::OnTimer() { } CParentWnd::OnSomeMessage() { m_childWnd.MoveWindow() m_childWnd.ShowWindow() } Both windows are created on the same UI thread. MoveWindow() will result in WM_SIZE message(s) being sent to the child window. Is there a possibility that at the same time any pending timer messages for the parent window will be flushed and as a result parent's OnTimer() handler wil...

Order of Parent / Child WM_PAINT messages
I have a parent window (CFormView) that contains child controls (such as CEdit, CButton, etc...). I need to do some drawing in the parent window after all the child controls are painted. Currently, the parent receives WM_PAINT first, and then all of the child controls are painted over what I just drew in the parent window. How do I know when all of the child controls are done painting so I can then draw in the parent? Changing z order of the parent doesn't seem to help. Thanks. Timothy Dean They happen in some order. There is no reason to assume any order dependency exists...

Traversing folders and subfolders
Assuming I have some xls files in C:\Folder the code below will list them one by one in Sheet1 starting from cell A1. Set ListPointer = Sheets("Sheet1").Range("A1") FileName = Dir(Range("C:\Folder") & "\*.*") Do While FileName <> "" If Right(FileName, 4) = "." & Range("xls") Then ListPointer = FileName Set ListPointer = ListPointer.Offset(1, 0) End If FileName = Dir() Loop What if I have sub folders e.g. C:\Folder\SubFolder1 and C:\Folder\SubFolder2 with lots of .xls files below them. How can I write...

Adding a child to HKLM registry key
Hi, [beginner to windows/registries] I want to add a new subkey to the HKLM registry key. How do I do it? I tried RegCreateKeyEx. But it does not work. When I refer the documentation at http://msdn.microsoft.com/library/en-us/sysinfo/base/regcreatekeyex.asp It says "An application cannot create a key that is a direct child of HKEY_USERS or HKEY_LOCAL_MACHINE. An application can create subkeys in lower levels of the HKEY_USERS or HKEY_LOCAL_MACHINE trees." Can someone help? regards, Sudhakar. Sudhakar Govindavajhala wrote: > I want to add a new subkey to the HKLM regist...

Traversing shallow CTreeCtrl
I have succesfully loaded my CTreeCtrl in my dialog with hierarchical data. I want the user to check off the boxes next to the data he wants, and then when he clicks OK to compile a CList of that data to be acted apon. The data is only three levels deep (excluding the root), and only the 2nd and 3rd levels of data are significant when checked. I am having trouble traversing the tree. As near as I can see GetNextItem is not returning the next child. I haven't used a recursive function because the tree is so shallow,and I need to know what level of data I'm for compiling the CList. HT...

HowTo for creating child window dialogs that can be used as child controls?
Hello, Can someone point to some docs or a HowTo for creating child window dialogs using the resource editor that can be used as child controls in a dialog window or child window? I'm not sure what dialog window styles, etc to use and how to 'wire' the child window to its parent. Basically I want to be able to layout a few 'placeholder child windows' on a dialog and insert my child windows at runtime. This if for an unmanaged C++ app using VS.Net 2003 and MFC. Thanks for any help. -Randy I believe the child dialog will also need the WS_EX_CONTROLPARENT style in ...

Need help traversing a folder and/or identifying sub-folders
Hello, I am trying to write a vbscript that will tell me what, if any, versions of the Microsoft .NET framework is installed. I have found several, but none that will identify if .NET 3.5 or higher is installed. My thoughts on one method is that if folder a folder exists where the folder name starts with "v" followed by a number, then that version of .Net is installed. So, I get to the C:\windows\Microsoft.NET\Framework folder. First, how do I identify the folders and not the files? I think these folders become part of a collection. I then loop through the co...

eConnect GL Tax node
In importing GL Transactions with tax, a partner suggests to have a node for the Tax entry. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane. http://www.microsoft.com/Businesssolutions/Community/NewsGroups/dgbrowser/en-us/default.mspx?mid=7f7460cc-5b62-418c-827d-162853db...

Account Re-assignment and Child Object Re-assignment
Has anyone else experienced this situation or noticed it... We have approximately 2000 accounts; most with a dedicated Account Manager covering them. In addition, we have a team of Inside Sales and Technical resources that deal with all accounts. At times (new Account Manager, Account reorganization) the account ownership needs to be changed. This is all well and good; however, when you reassign an account ALL CHILD OBJECTS are also reassigned. This is fine for contacts and maybe even quotes/orders/invoices; however, why would we want all child activities also reassigned? This is especial...

Parent / Child Receiving Report or Gross Margin report
I receive items by the case (parent) and sell them by units (child). Does any one have a receiving report that will show the child's retail price, the received unit cost (parents cost / # units) and the gross margin ? OR Is there a report which shows the same info for all parent child items? Thanks for your help Jay HI Jay, Such thing can be handle by your own customize report. look at any report with .grp extention and try to make yours else send your detail I will see I can help you out. I need all kind of detail for your report. "Jay" wrote: > I receive items by t...

Window messages and Child dialogs with MDIFrame
hello all, The window message are not given to Child dialog created with Parent as CMDIFrameWnd. The dialog box is created in the following way. Open a Resource editor, Insert a new Dialog. In the Dialog properties, Set the Style as child. The dialog is created as theDialog.Create( dialog1::IDD, m_pMainWnd ); theDialog.ShowWindow( SW_SHOW ); It does not recive any WIndow messages, the button click, the mouse move etc. Is something I need to DO. thanks, Chandra- Just a random thought...does your child dialog have the WS_EX_CONTROLPARENT style set? This may or may not solve the problem, ...

Controls traversing
Let me know if you know this. I have Aspx page with below control structure. AjaxTabContainer - ReceiptPanel ? Literal ? ReportViewer - EmailPanel o UserControl ? TextBox1 ? TextBox1 ? Button I want to access the ReportViewer control from Button action. I tried var rptVw = (ReportViewer) Parent.Parent.Parent.Controls[0].Controls[1].Controls[1]; This works but looks ugly. Also I dont want to search the control by its ID. [I dont want hardcoding so that it can be used mul...

Child controls not being invalidated
Folks, I have an MFC problem that I have struggled with for a while where a control in a child dialog is not always invalidated/redrawn correctly. Please help! I have a series of classes as follows (parent/children): CFrameWnd-derived (ultimate parent) -> (a) modeless CDialog-derived class (with CTabCtrl) -> (b) modeless CDialog-derived class (tab page) -> CStatic-derived class Class (a) hosts a tab control and shows/hides a number of different (b) modeless dialogs depending on the tab selected. These classes are members of (a) and are constructed as children in (a)'s cons...

XPath returning multiple nodes.
Is it possible to create an XPath query that will return both the First and Last names using the following as an example? <Data> <Emp> <FirstName>Karen</FirstName> <LastName>Wade</LastName> <Dept>Finance</Dept> </Emp> <Emp> <FirstName>Carol</FirstName> <LastName>Britt</LastName> <Dept>HR</Dept> </Emp> <Emp> <FirstName>Nancy</FirstName> <LastName>Greene</LastName> <Dept>Sales</Dept> </Emp> ...