473,386 Members | 1,720 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,386 software developers and data experts.

What is the Xpath

Hello,
Thanks for the response Oleg. Now I need to know few answers. How do I
get the value of a node using the xpath. I want the value of the MessageID
and ResultCode from secondxml. And using this I want to delete the Child
Nodes in the firstxml document.
I am using the fowllowing code but the ni.current.value has values of all
nodes in the file. I am confused.

XmlDocument doc = new XmlDocument();
doc.Load("Firstxml.xml")
hDocument doc2 = new XPathDocument("second.xml");
XPathNavigator nav = doc2.CreateNavigator();

foreach (XmlNode msg in doc.SelectNodes("//Message"))
{
XPathNodeIterator ni = nav.Select("/Result[MessageID='" +
msg.SelectSingleNode("MessageID/text()").Value +
"']/ResultCode");

ni.MoveNext();
if (ni.Current.Value == "Error")
msg.ParentNode.RemoveChild(msg);
}

1. My FirstXML Document Looks Like this.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<AE xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="az-envelope.xsd">
<Header>
<DocumentVersion>1.0</DocumentVersion>
<MerchantIdentifier>M_493</MerchantIdentifier>
</Header>
<MessageType>Relationship</MessageType>
<Message>
<MessageID>1</MessageID>
<Relationship>
<ParentSKU>0113311000000</ParentSKU>
<Relation><SKU>0113508000000</SKU><Type>Accessory</Type></Relation>
<Relation><SKU>0113630000000</SKU><Type>Accessory</Type></Relation>
</Relationship>
<MessageID>2</MessageID>
<Relationship>
<ParentSKU>0113312000000</ParentSKU>
<Relation><SKU>0113312048305</SKU><Type>Variation</Type></Relation>
<Relation><SKU>0113312048306</SKU><Type>Variation</Type></Relation>
</Relationship>
<MessageID>3</MessageID>
<Relationship>
<ParentSKU>0113312000000</ParentSKU>
<Relation><SKU>0113312048305</SKU><Type>Variation</Type></Relation>
<Relation><SKU>0113312048306</SKU><Type>Variation</Type></Relation>
</Relationship>
</Message>
</AE>

2. My secondXML look like this.

<?xml version="1.0" encoding="UTF-8"?>
<AE xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
<Header>
<DocumentVersion>1.01</DocumentVersion>
<MerchantIdentifier>M_493</MerchantIdentifier>
</Header>
<MessageType>ProcessingReport</MessageType>
<Message>
<MessageID>1</MessageID>
<ProcessingReport>
<DocumentTransactionID>30035573</DocumentTransactionID>
<StatusCode>Complete</StatusCode>
<ProcessingSummary>
<MessagesProcessed>921</MessagesProcessed>
<MessagesSuccessful>686</MessagesSuccessful>
<MessagesWithError>235</MessagesWithError>
<MessagesWithWarning>0</MessagesWithWarning>
</ProcessingSummary>
<Result>
<MessageID>17</MessageID>
<ResultCode>Error</ResultCode>
<ResultMessageCode>8008</ResultMessageCode>
<ResultDescription>The entry for SKU [0400235000000] contains an invalid or
unrecognized SKU. Please correct the SKU and

resubmit the item with your next feed. The item will appear with the next
catalog build.</ResultDescription>
</Result>
<Result>
<MessageID>17</MessageID>
<ResultCode>Error</ResultCode>
<ResultMessageCode>8008</ResultMessageCode>
<ResultDescription>The entry for SKU [113122B000000] contains an invalid or
unrecognized SKU. Please correct the SKU and

resubmit the item with your next feed. The item will appear with the next
catalog build.</ResultDescription>
</Result>
<Result>
<MessageID>24</MessageID>
<ResultCode>Error</ResultCode>
<ResultMessageCode>8008</ResultMessageCode>
<ResultDescription>The entry for SKU [0535508000000] contains an invalid or
unrecognized SKU. Please correct the SKU and

resubmit the item with your next feed. The item will appear with the next
catalog build.</ResultDescription>
</Result>
<Result>
<MessageID>24</MessageID>
<ResultCode>Error</ResultCode>
<ResultMessageCode>8008</ResultMessageCode>
<ResultDescription>The entry for SKU [0535630000000] contains an invalid or
unrecognized SKU. Please correct the SKU and

resubmit the item with your next feed. The item will appear with the next
catalog build.</ResultDescription>
</Result>
<Result>
<MessageID>24</MessageID>
<ResultCode>Error</ResultCode>
<ResultMessageCode>8016</ResultMessageCode>
<ResultDescription>Elements are missing in [ 0113534235039 ] to establish
relationships appropriately. Please check the

VariationTheme and make sure the variations elements match what is
declared.</ResultDescription>
</Result>
<Result>
<MessageID>27</MessageID>
<ResultCode>Error</ResultCode>
<ResultMessageCode>8008</ResultMessageCode>
<ResultDescription>The entry for SKU [0400358000000] contains an invalid or
unrecognized SKU. Please correct the SKU and

resubmit the item with your next feed. The item will appear with the next
catalog build.</ResultDescription>
</Result>
<Result>
<MessageID>36</MessageID>
<ResultCode>Error</ResultCode>
<ResultMessageCode>8008</ResultMessageCode>
<ResultDescription>The entry for SKU [0121501000000] contains an invalid or
unrecognized SKU. Please correct the SKU and

resubmit the item with your next feed. The item will appear with the next
catalog build.</ResultDescription>
</Result></ProcessingReport>
</Message>
</AE>







Nov 11 '05 #1
1 1659
Naga wrote:
Thanks for the response Oleg. Now I need to know few answers. How do I
get the value of a node using the xpath. Select appropriate node and get its value. That's it.
I want the value of the MessageID
and ResultCode from secondxml. And using this I want to delete the Child
Nodes in the firstxml document.
I am using the fowllowing code but the ni.current.value has values of all
nodes in the file. I am confused.


Yeah, my fault. That means navigator selects nothing, and good practice to
avoid getting confused in this situation is to check if any result exists by
testing MoveNext() returned value:
foreach (XmlNode msg in doc.SelectNodes("//Message"))
{
XPathNodeIterator ni = nav.Select("/Result[MessageID='" +
msg.SelectSingleNode("MessageID/text()").Value +
"']/ResultCode");

//Note this
while (ni.MoveNext()) {
if (ni.Current.Value == "Error")
msg.ParentNode.RemoveChild(msg);
}
}

--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #2

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

Similar topics

0
by: bdinmstig | last post by:
I am building various framework components for my team to use in development, and one of those components is a Facade for reading/writing user preferences. The idea is that preference settings...
1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
1
by: kurt hansen | last post by:
hi I thought that this would be easy, but maybe not so much. I want to: pass an xpath expression and a string value to a stylesheet and copy the source xml document, changing the value of...
4
by: Son KwonNam | last post by:
In XSLT, is this possible to get value from xml using XPath which is in XSLT variable? I mean XPath strings can be dynamic while XSL Transforming. If possible, How?? Because I'm not a...
4
by: Bnaya Eshet | last post by:
I do like XPath, I really do. But I'm working on the compact framework which XPath is not included. So I come to understanding that if XPath do not come to the mountain,
5
by: laks | last post by:
Hi I have the following xsl stmt. <xsl:for-each select="JOB_POSTINGS/JOB_POSTING \"> <xsl:sort select="JOB_TITLE" order="ascending"/> This works fine when I use it. But when using multiple...
5
by: Gnic | last post by:
Hi , I have an XmlDocument instance, I want to find a node in the xml, but I don't know it's path until runtime, for example <aaa> <bbb name="x"/> <aaa attr="y"> <ccc>sometext</ccc> </aaa>
3
by: werD | last post by:
Hello I have an xml document that im currently using a forward only .net repeater on and using some xpath queries to display the data The xml is quite simple <?xml version="1.0"...
2
by: arunairs | last post by:
Hi, Is there a way of validating and XPath? In this case , I am accepting an XPath from the user and I need to validate the XPath syntax. Is there a regular expression available that anyone can...
8
by: Sven | last post by:
Dear all, I'm trying to extract data from HTML using XPath in Java. Unfortunately the text contents of nodes may contain <br/tags which are not correctly interpreted, at least not for me ;) A...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...

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.