473,387 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

need to remove root element when parsing xml doc or storing in database

i am fetching an xml document with the following structure:
<?xml version="1.0" encoding="UTF-8"?>
<DTCResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:/ows/aws/1.2
http://www.overture.com/schema/dtc/1.2/dtc_response.xsd"
xmlns="urn:/ows/aws/1.2" success="true">
<ActionsResponse accountId="123">
<GetAccountIdsResponse success="true">
<Account id="123" market="UK" />
....

i want to parse the document in my .net script and this part is new to
me.
i am using an xmldocument and looping through its nodes as follows:

XmlNodeList nodes =
xmlDoc.SelectNodes("/ActionsResponse/GetAccountIdsResponse/Account");
foreach(XmlNode node in nodes)
{
Console.WriteLine(node.Attributes.GetNamedItem("id ").Value);
Console.WriteLine(node.Attributes.GetNamedItem("ma rket").Value);
}

I originally had
xmlDoc.SelectNodes("/DTCResponse/ActionsResponse/GetAccountIdsResponse/Account");
but this was not printing anything out. So the above code works, but
only if I remove the root DTCResponse element from my document!

I also wanted to store a similar document in Sql Server using OPENXML
(i.e. my stored procedure calls sp_xml_preparedocument and does a bulk
insert). I ran into the same issue there. I needed to remove the
DTCResponse element and adjust my element list accordingly. Otherwise
nothing got inserted. I have used OPENXML several times before and
never encountered this, although I am unsure if those docs had schema
references etc.

Once I strip the root element from the document before parsing or
storing it in the database, everything works fine so I have a
workaround. However, as a newbie, I would like to know where I have
gone wrong and why this is happening. Could anyone enlighten me?

Thanks in advance :)

Nov 12 '05 #1
2 2097


fizzy wrote:
i am fetching an xml document with the following structure:
<?xml version="1.0" encoding="UTF-8"?>
<DTCResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:/ows/aws/1.2
http://www.overture.com/schema/dtc/1.2/dtc_response.xsd"
xmlns="urn:/ows/aws/1.2" success="true">

^^^^^^^^^^^^^^^^^^^^^^^^
The root element declares a default namespace with the URL
urn:/ows/aws/1.2 and thus any XPath expression needs to take that into
account, see
<http://www.faqts.com/knowledge_base/view.phtml/aid/34022/fid/616>

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
many thanks for filling me in martin :)

Nov 12 '05 #3

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

Similar topics

0
by: MT | last post by:
I have a very strange problem. I created an XSD file with the following root: <Database> </Database> However, since C++ does not allow you to have a property with the same name as the class,...
5
by: Paul Nations | last post by:
I'm in a real pickle. I've inherited a project with major problems. It receives encrypted XML files from a website not under my control (so I can't modify the web app) for insertion into a...
0
by: Martin | last post by:
Hi, I am retriving data from sql server using the xml raw clause and an xmltextwriter. this is working out fine except the xml raw clause does not put a root node on the xml that is returned...
2
by: Joe Bloggs | last post by:
Hi, I am trying to remove the namespace in the root node in the following XML, <ordersHistory xmlns="http://tempuri.org/Orders.xsd"> <order number="PO-1" added="12/12/2002"> <client...
6
by: fzhang | last post by:
I am relatively new to XML and C#. So, forgive me if this question is too newbie. :-) While assuming this is an easy programming task, I couldn't find a single reference anywhere for how to do...
1
by: sommarlov | last post by:
Hi everyone >From one of our systems an xml file is produced. I need to validate this file before we send it to an external system for a very lenghty process. I cannot change the xml file layout....
8
by: VK | last post by:
Can be multiple instances of element used as the root element? That's a curly way of asking, but I did not come up with a better sentence, sorry. What I mean is with a document like: <?xml...
27
by: comp.lang.tcl | last post by:
My TCL proc, XML_GET_ALL_ELEMENT_ATTRS, is supposed to convert an XML file into a TCL list as follows: attr1 {val1} attr2 {val2} ... attrN {valN} This is the TCL code that does this: set...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.