|
I have to parse RSS channel definition XML file. I have appended one sample at the end of this topic.
I have installed MSXML parser 6 and uses it successfully. Please refer to function XmlRSSRead.
There are a lot of information about the channel and item of this channel. For example, one channel has title, link, description information. One channel may have a lot of item too. Each item also hase title, link, description information.
I have to extract title, link, description information in my application. I can not find one quick start guide from microsoft doucments.
Could anyone be kind to tell me what I should do next?
The following is the function I have now and the xml file I want to parse.
void XmlRSSRead( void )
{
//¡ä¡ä?¡§DOMDocument???¨®
MSXML2::IXMLDOMDocumentPtr pDoc;
HRESULT hr = pDoc.CreateInstance(__uuidof(MSXML2::DOMDocument30));
if(!SUCCEEDED(hr))
{
AfxMessageBox( _T("?T¡¤¡§¡ä¡ä?¡§DOMDocument???¨®¡ê????¨¬2¨¦¨º?¡¤?¡ã2¡Á¡ã¨¢?MS XML Parser ??DD?a!") );
}
//?¨®?????t
pDoc->load( _T("D:\\temp\\mPhone\\Docs\\RSS\\nature.xml") );
//?¨²¨º¡Â?D2¨¦?¨°???achannel¦Ì??¨²¦Ì?,
// "//"¡À¨ª¨º??¨²¨¨?¨°a¨°?2?2¨¦?¨°
MSXML2::IXMLDOMElementPtr childNode ;
childNode = (MSXML2::IXMLDOMElementPtr)(pDoc->selectSingleNode("//channel"));
//¦Ì?¦Ì??¨²¦Ì?¨¤¨¤D¨ª
MSXML2::DOMNodeType nodeType;
childNode->get_nodeType(&nodeType);
//?¨²¦Ì???3?
BSTR var;
CString name;
childNode->get_nodeName(&var);
name = (char*)(_bstr_t)var;
//?¨²¦Ì??¦Ì
VARIANT varVal;
childNode->get_nodeTypedValue(&varVal);
CString strValue = (char*)(_bstr_t)varVal;
//?¨²¦Ì?¨º?D?,¡¤??¨²¨¢¡ä¡À¨ª?D
MSXML2::IXMLDOMNamedNodeMapPtr pAttrs = NULL;
MSXML2::IXMLDOMNodePtr pAttrItem;
childNode->get_attributes(&pAttrs);
long nCount ;
pAttrs->get_length(&nCount);
for(int i = 0 ; i < nCount ; i++)
{
pAttrs->get_item(i,&pAttrItem);
//?¨°???¨¦¨°?¨ª¡§1yo¡¥¨ºyget_nodeName,get_nodeTypedValue¦Ì?¦Ì?¨º?D???o¨ª¨º?D??¦Ì
//¨°2?¨¦¨°??¡À?¨®¦Ì?¦Ì?
CString strAttrName = (char*)(_bstr_t)pAttrItem->nodeName;
CString strAttrValue = (char*)(_bstr_t)pAttrItem->nodeTypedValue;
}
}
void mfXmlReadTest( void )
{
::CoInitialize(NULL);
MSXML2::IXMLDOMDocumentPtr spPtr;
HRESULT hr = spPtr.CreateInstance(__uuidof(MSXML2::DOMDocument30));
ASSERT(SUCCEEDED(hr));
spPtr->loadXML("<r>\n<t>top\nbottom\n");
spPtr->save("C:\\nature.xml");
spPtr.Release();
::CoUninitialize();
}
XMLÎļþÈçÏ£º
<rss xmlns:itunes="http://www.itunes.com/DTDs/Podcast-1.0.dtd" version="2.0">
<channel>
<title>Nature Podcast
http://www.nature.com/nature/podcast/rss/nature.xml <description>Nature is a weekly international journal publishing the finest peer-reviewed research in all fields of science. The Nature Podcast is a free weekly audio show highlighting content from each issue, and interviews with the scientists creating the data. The Nature Podcast provides insight and context to groundbreaking research, and allows the scientists to explain the significance of their work in their own words.
<language>en
<copyright>© 2006 Nature Publishing Group
<lastbuilddate>Wed, 25 Jul 2007 18:00:00 GMT
<category>Science & Medicine
<category>Technology
<url>http://www.nature.com/nature/podcast/images/nature_rss_logo.png
<title>Nature
http://www.nature.com/nature/podcast/rss/nature.xml <width>144
<height>144
<itunes:author>Nature
<itunes:subtitle>Interviews, insight and highlights of the latest scientific discoveries, every week in Nature
<itunes:summary>Nature is a weekly international journal publishing the finest peer-reviewed research in all fields of science. The Nature Podcast is a free weekly audio show highlighting content from each issue, and interviews with the scientists creating the data. The Nature Podcast provides insight and context to groundbreaking research, and allows the scientists to explain the significance of their work in their own words.
<itunes:owner>
<itunes:name>Nature
<itunes:email>podcast@nature.com
<itunes:category text="Science & Medicine">
<itunes:category text="Technology">
<itunes:image href="http://www.nature.com/nature/podcast/images/nature_itunes_logo.png">
<item>
<title>Nature Podcast: 26 July 2007
http://www.nature.com/nature/podcast/v448/n7152/nature-2007-07-26.mp3 <description>?26 July: Rain changes of our own making, science in the Simpsons, Californian-style plate rifts, investigating inflammatory bowel disease, pygmies with palm pilots.
<guid>http://www.nature.com/nature/podcast/v448/n7152/nature-2007-07-26.mp3
<enclosure url="http://www.nature.com/nature/podcast/v448/n7152/nature-2007-07-26.mp3" length="13343922" type="audio/mpeg">
<pubdate>Wed, 25 Jul 2007 18:00:00 GMT
<category>Science & Medicine
<category>Technology
<itunes:author>Nature
<itunes:subtitle>?26 July: Rain changes of our own making, science in the Simpsons, Californian-style plate rifts, investigating inflammatory bowel disease, pygmies with palm pilots.
<itunes:duration>37:03
<itunes:explicit>no
<itunes:category text="Science & Medicine">
<itunes:category text="Technology">
<itunes:keywords>nature, podcast, science, technology, education, science news, biology, physics, genetics, astronomy, astrophysics, quantum physics, evolution, evolutionary biology, geophysics, climate change, earth science, materials science, science policy, medicine, systems biology, genomics, palaeobiology, ecology, molecular biology, cancer, immunology, pharmacology, developmental biology, biochemistry, bioinformatics, nanotechnology, biotechnology, drug discovery, environmental science, life, marine biology, medical research, neuroscience, rna, dna, cell cycle, signal transduction, cell signalling
|
|
|
|
|
I have two XSD File. one is master and second is its child. i m creating the dataset from child XSD. now i m setting the data into dataset and then generating xml file from this dataset. it is working fine. But the problem is that the sequence defined in master file is not following in the xml file created thru DATASet.
can any body help me.
kishore
|
|
|
|
|
Never tried that but wouldn't you need to generate your DataSet from the Master file?
|
|
|
|
|
I've a problem for which I can't seem to find an elegant/efficient solution. Maybe someone would have an answer/hint. Did RTFM, googled, read 2 Java/Sax books.....
We have a servlet which is accepting a SOAP request. This is fed to a SAX2 XMLFilter (called SoapXMLFilter) and the result of this using an XMLWriter is put as the string 'payload' in a Result object. Later a new SOAP request is generated, part of the body of this SOAP msg is the payload string. This is given to a MessageQueue. So far so good.
In the new setup the header of the SOAP message contains a <security> block. The body contains amongst other things a <logistic> block. In the past SoapXMlfilter returned only the logistic> block (using super.startelement super.endelement etc.... In the new situation I have to return the following <logistic> <security> . Eg the security block is now INSIDE the logistic block.
When at the endelement tag for logistic I would like to insert the security block. Using a XMLWriter inside SoapXMLfilter I can put the security block into a string. At the endelement for Logistic I have this available. I somehow must have this block returned from SoapXMLFilter.
Things I can come up with:
---------------------------
1) Put security block as string security in a Object Body (using XMLwriter inside SOAPXMLWriter, this already works) . Put things between the <logistic> and tags as string logistic (using another XMLWriterr) in Object body. When generating end SOAP request. Create Stringbuffer, append "<logistic>", append logistic string, append security string, append "". Hence I know have a security block inside the logistic block. I find this UGLY and this should be done in SOAPXMLFilter.
2) The super.startelement(, , ,) super.endelement(, , ) are put in a String array. At endelement of Logistic I somehow have to execute them. Don't know if this is even possible......
3) Maybe an an additional XMLFilter inside SOAPXMLfilter which has as input has the security string. Maybe you can pass as a parameter the original XMLreader handler so that somehow a <orginal xmlreader="">.startelement inside this additional XNLFilter will have the effect of a super.startelement in SOAPXMLfilter. Eg SOAPXMLfilter returns the security block inside the logistic block. No idea if this possible at all..........
4) Easy, elegant, fast. I've missed it....... At this point I'm basically given up.
SoapXMLfilter is in fact a very complex beast which does many many things. Rewriting this is not an option (if it works don't...) . The website is a higtraffic one which means a solution has to be efficient (speed and memory footprint wise). This all means I need a solution using SAX2 (DOM or something like is not really an option I think).
Any hints/pointers are HIGHLY appreciated.
|
|
|
|
|
I ve got an error: I cannot use 'Content' element. The expected one is: 'Content'. erghh...
The element 'HelpText' in namespace 'http://korepetytor/HelpXmlSchema' has invalid child element 'Content' in namespace 'http://korepetytor/HelpXmlSchema'. List of possible elements expected: 'Content' in namespace 'http://korepetytor/KorXmlSchema'.
The HelpXmlSchema has an import element, which links to KorXmlSchema, which has a complex type 'Text'. 'HelpText.Content' is of type 'Text', but it is correctly imported and validation of HelpXmlSchema is positive.
How can I get around this? I use VS 2005. Please help.
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
It would help to see the files in question or at least the important parts.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Thanks for answer, although I have succeed to solve it myself.
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
Hello,
VS 2005
I am creating a PDA application that will get data from a database and display the data to the user.
When the user has finished using the application, I want to save the changes from the dataset to an xml file using the datasets read and write xml methods.
However, as the xml files are left on the PDA, any one could open them and view the contents of the data that has been saved.
Which is the best method to quickly encrypt the xml and decrypt it?
Many thanks,
Steve
|
|
|
|
|
There are encryption classes in .NET and also support in the Xml namespace for encrypting/signing XML. There isn't necessarily a "best method", it all depends on what you want and how you want it to work.
|
|
|
|
|
Is there a way to serialize non-textual objects, for example fonts and colors, using XML Serialization. working fine with binary formatter, but I have to use XML for political reasons.
Thanks PhilD
|
|
|
|
|
pjd1001 wrote: I have to use XML
XML is text based so the question is can you represent your data in text. The answer of course is Yes. There different ways to do it. Lets look at a Date. It's a numeric type so we can store the string representation of the number or we can transform the date into a human readable format and store that as long as we can parse it back into the numeric type it will work. Another approach is to use a standard binary data mechanism in XML which is Base64 encoding.
Does that help?
|
|
|
|
|
Yeah, but I dont have to do the transforms on a double or or an int, nor a decimal (I think) so why should I have to do common things like Colors & Fonts - I guess I resent having to delve into XML serilization when binary works fine.
|
|
|
|
|
What are we, girl friends? I don't think so.
Besides, if you don't like writing code just switch to being a Visual Basic Drag n Drop developer.
|
|
|
|
|
given i've been writing the stuff for 30+ years I guess the thrill of writing stuff that don't need writing has gone. BTW only Basic I ever used was Dartmouth Basic on a GE timesharing system - Gates would have been at scool then & I dont mean grad or high scool
cya
|
|
|
|
|
I been at this only 15+ years, I wish I had even one team member with half your experience. You guys hiring?
|
|
|
|
|
we're always hiring, no shortage of applicants, you can join at your leisure.
rgds phild - retiree's inc.
btw I did the xml stuff yesterday
oh I do free work for heart disease research - university CompSci are the politicians.
|
|
|
|
|
hi all,
i have the following xml file.
<rss version="2.0" xmlns:media="http://tools.search.yahoo.com/mrss/" >
<channel>
<title>SWF media</title>
<link>http://www.blogdigger.com/media/</link>
<description>Recent .swf files found by Blogdigger</description>
<item>
<title>Dollar Bus Rolls Into Town</title>
<link>http://feeds.feedburner.com/Chicagoist?m=1115</link>
<description>some description</description>
<pubDate>Thu, 23 Mar 2006 14:11:57 EST</pubDate>
<enclosure url="http://www.kitschn.com/flash/MenuCoverPage-DrinksMenu09-05.swf" type="application/x-shockwave-flash"/>
<media:content url="http://www.kitschn.com/flash/MenuCoverPage-DrinksMenu09-05.swf" type="application/x-shockwave-flash"/>
</item>
<item>
<title>E-mail</title>
<link>http://billarnold.typepad.com/poet_in_motion/2006/03/email.html</link>
<description>description 2/description>
<pubDate>Wed, 22 Mar 2006 17:28:28 EST</pubDate>
<enclosure url="http://www.softlab.ece.ntua.gr/~sivann/pub/swf/may02-smilepop-soapbox4.swf" type="application/x-shockwave-flash"/>
<media:content url="http://www.softlab.ece.ntua.gr/~sivann/pub/swf/may02-smilepop-soapbox4.swf" type="application/x-shockwave-flash"/>
</item>
</channel>
</rss>
i am using xpath to navigate through this xml file.
i used the following code to navigate through items node.
XmlDocument doc = new XmlDocument();
doc.Load(xmlfile);
XPathNavigator nav = doc.CreateNavigator();
XPathExpression exp = nav.Compile("rss/channel/item");
XPathNodeIterator iterator = nav.Select(exp);
XPathNodeIterator iter1;
while (iterator.MoveNext())
{
iter1 = iterator.Current.SelectChildren("media:content", "");
if (iter1.Count > 0)
{
while (iter1.MoveNext())
{
if (iter1.Current.HasAttributes == true)
{
string url = iter1.Current.GetAttribute("url", "");
}
}
}
}
but when i execute the code, the iter1.count always returns zero. if i select anyother children(like title or description)i am able to display the value.but when i select media:content(one of the subitems of item) i am not able to display the attribute value.
Where am i going wrong?
Any suggestions please
Thanks in advance.
Regards
Anuradha
|
|
|
|
|
hi guys,
i solved it by myself. for everybody's reference,
iter1 = iterator.Current.SelectChildren("content", "http://tools.search.yahoo.com/mrss/");
i need to include the namespace URI in the selectchildren method and it worked.
Thanks
Regards
Anu
|
|
|
|
|
I am trying to generate a Word document for an ASP.Net application -- all users will have Word 2003.
I created a simple document in Word (Simple.doc).
Then, I used an XML Schema found in Simple.xsd and placed a couple of XML placeholders in the document.
I saved it as Simple.XML.
Downloaded and ran wml2xslt to create simple.xslt.
However, I am a little stuck as to how to get the data from my application into xml using this xslt file. Every example I can find seems to assume all data will be coming from a SQL database or databound web/win forms.
I would like to do something like:
Swap("xmlDataElementName", myObject1.ToString());
Is this doable; any help is greatly appreciated.
--G
|
|
|
|
|
I want to figure out the formula in getting the following:
$2500 loan amount
239.9961% APR
12 month term
Bi-weekly payment (26 payment total)
What is the formula for each payment?
What is the formula for the Total Finance Charge?
How can I calculate Bi-weekly equal payments??
We know that each payment will be $251.96 (Equal Payments) But how have they come up with such formula?? And where?
HELP!?!?!?!?!
Victoria
|
|
|
|
|
I will assume that your $251.96 is paying both interest on the balance and part of the loan is repaid each month.
So each each payment = interest + repayment
I used to Excel and "Goal-Seek" to work out the nominal (annual) rate of interest, it is 234.214%. Therefore each bi-weekly payment (assuming 52 weeks in a year) is 1/26 x 234.214% which is 9.008%
This is the interest part: so in first week interest is balance x 9.008% which is $225.206
Subtract this from $251.96 and you have the net repayment that month, $26.76.
For bi-week 2, interest on the balance is now $2473.24 x 9.008% .. etc
As to formulas I don't know if there is one, it's so long since I did all this stuff.. As you can see the interest is calculated monthly based on the remaining balance, and totals $4050.96
'Howard
|
|
|
|
|
I am venturing into the .NET XML world and have already run into a problem.
I have some very simple (I think) XML that defines several loan rate values, with attributes indicating the min and max amount for the loan:
<code>
<LoanInformation>
<LoanRates>
<Loan MinValue="001000.00" MaxValue="004999.99">
<Margin>10.25</Margin>
<Floor>14.75</Floor>
</Loan>
<Loan MinValue="005000.00" MaxValue="009999.99">
<Margin>5.25</Margin>
<Floor>9.75</Floor>
</Loan>
</LoanRates>
</LoanInformation>
</code>
So, a loan for $2500.00 should have a margin of 10.25/floor of 14.75, while a loan of $7500.00 should have a margin of 5.25/floor of 9.75.
I want to access these values in my C# code to calculate the rate/payment, but am stuck.
<code>
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath(@"~\App_Data\LoanInformation.xml"));
string xPath = string.Format("//LoanRates/Loan[@MinValue >= '{0:000000.00}' and @MaxValue <= '{0:000000.00}']", plcdata.LoanAmount);
XmlNode node = xmlDoc.SelectSingleNode(xPath);
</code>
node seems to always be null, unless I remove the 'and @Max ..' clause. I added the leading zero's in case text vs. number comparison was causing a problem.
Any pointers would be greatly appreciated.
--G
-- modified to "ignore HTML tags"
|
|
|
|
|
Your XPath query is incorrect. Your code should read:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath(@"~\App_Data\LoanInformation.xml"));
string xPath = string.Format("//LoanRates/Loan[@MinValue <= '{0:000000.00}' and @MaxValue >= '{0:000000.00}']", plcdata.LoanAmount);
XmlNode node = xmlDoc.SelectSingleNode(xPath);
Paul Marfleet
|
|
|
|
|
<smacks head="">
Duh! I've been trying various combinations, *assuming* the problem was XML (and my lack thereof) related. Stupid logic!
Thanks.
--G
|
|
|
|
|
I'm Getting Different XML files.So I want to Create a single XSL file For all those XML Files..How Can I do?
|
|
|
|
|