I have this template from a bank that is used to make payments on bank account transfers.
See xml below. I have included the sample data that has to be entered when sending the file to the bank.
<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<CstmrCdtTrfInitn>
<GrpHdr>
<MsgId>Cart Urgent28052018_57894</MsgId>
<CreDtTm>2018-06-29T11:52:23</CreDtTm>
<NbOfTxs>1</NbOfTxs>
<CtrlSum>667896.00</CtrlSum>
<InitgPty>
<Nm>CART LIMITED</Nm>
<Id>
<OrgId>
<Othr>
<Id>S001234/PJones</Id>
<SchmeNm>
<Cd>CUST</Cd>
</SchmeNm>
</Othr>
</OrgId>
</Id>
</InitgPty>
</GrpHdr>
<PmtInf>
<PmtInfId>Payment for addon development SAP B1</PmtInfId>
<PmtMtd>TRF</PmtMtd>
<BtchBookg>false</BtchBookg>
<NbOfTxs>1</NbOfTxs>
<CtrlSum>667896.00</CtrlSum>
<PmtTpInf>
<InstrPrty>HIGH</InstrPrty>
</PmtTpInf>
<ReqdExctnDt>2018-06-29</ReqdExctnDt>
<Dbtr>
<Nm>CART LIMITED</Nm>
</Dbtr>
<DbtrAcct>
<Id>
<Othr>
<Id>0112345110846</Id>
</Othr>
</Id>
<Ccy>KES</Ccy>
</DbtrAcct>
<DbtrAgt>
<FinInstnId>
<BIC>SBICKENX</BIC>
</FinInstnId>
</DbtrAgt>
<CdtTrfTxInf>
<PmtId>
<EndToEndId>156335578965</EndToEndId>
</PmtId>
<Amt>
<InstdAmt Ccy="KES">667896.00</InstdAmt>
</Amt>
<ChrgBr>DEBT</ChrgBr>
<CdtrAgt>
<FinInstnId>
<BIC>DTKEKENA</BIC>
<ClrSysMmbId>
<MmbId>63000</MmbId>
</ClrSysMmbId>
</FinInstnId>
</CdtrAgt>
<Cdtr>
<Nm>EOH SEAL LTD</Nm>
<PstlAdr>
<StrtNm>P.O. Box 10496</StrtNm>
<TwnNm>Nairobi</TwnNm>
<Ctry>KE</Ctry>
<AdrLine>P.O. Box 10496</AdrLine>
<AdrLine>00100 NAIROBI</AdrLine>
</PstlAdr>
</Cdtr>
<CdtrAcct>
<Id>
<Othr>
<Id>0112406001</Id>
</Othr>
</Id>
</CdtrAcct>
<RmtInf>
<Ustrd>Cart Urgent28052018_57894</Ustrd>
</RmtInf>
</CdtTrfTxInf>
</PmtInf>
</CstmrCdtTrfInitn>
</Document>
The file is quite long as has to be in the format given. The black letters represent the details to be passed to the xml. To test if I understood what data goes where I filled it manually and sent to bank for testing. That is all good now.
I have a SAP addon program that captures details from a form and generates a list. Each payment must follow this structure.
Looking at the below:
<Nm>CART LIMITED</Nm>
<Id>
<OrgId>
<Othr>
<Id>S001234/PJones</Id>
<SchmeNm>
<Cd>CUST</Cd>
</SchmeNm>
</Othr>
</OrgId>
</Id>
Is creating a class with all properties according to the template the best way to create the xml needed.
How do I stagger the
<Id>
<OrgId>
<Othr>
as in the case above?
Also the <CtrlSum>667896.00</CtrlSum> is found in the group header and payment info tags. How do I deal with this?
For what i see, the problem is you have a addon in SAP to specify multiple payments methods, but in the XML template given from the bank you don't the structure for multiple payments, so you need to get this information to know how can you work with it.
when you have this information you can use a better XML template with VS or another tool to generate the correct class to work with the XML
Can you please tell me how to get line number using XDocument or XmlDocument?
In XDocument,
Input:
1. <title-group>
2. <article-title>Education Finance: How It Differs from the and the
Analytic and Data Collection Changes It Implies</article-title>
4. </title-group>
5. <contrib-group>
6. <contrib contrib-type="author"><name><surname>Guthrie</surname><given-names>James W.</given-names></name><aff>Department of Leadership, Policy and Organization, Peabody College of Vanderbil University, 230 Appleton Place, # Nashville, TN 37203-5721, E-mail: <email xlink="jwgxiii#sbcglobal.net">jwgxiii#sbcglobal.net</email></aff>
7. testest</contrib>
8. </contrib-group>
My output will look like:
2. <article-title>Education Finance: How It Differs from the and the Analytic and Data Collection Changes It Implies</article-title>
6. <contrib contrib-type="author"><name><surname>Guthrie</surname><given-names>James W.</given-names></name><aff>Department of Leadership, Policy and Organization, Peabody College of Vanderbil University, 230 Appleton Place, # Nashville, TN 37203-5721, E-mail: <email xlink="jwgxiii#sbcglobal.net">jwgxiii#sbcglobal.net</email></aff>
7. testest</contrib>
You will need to check using the HasLineInfo method if the XDocument supports line information.
If it does you can use it via the IXmlLineInfo Interface for functions like the LineNumber property.
First off im very new to C# im trying to recreate a application i created in Java.
I have 4 Listboxes. Each box will hold a list of values from the xml file.
listBox_year for the <Year>.
listBox_make for the <Make>.
listBox_model for the <Model>.
listBox_subModel is for the <sub-Model>.
So lets say i add all the years to the listBox_year with no duplicate years. Say i click on a year it will bring up all the Make of cars that have that year. Then i click on the Make and it will bring up the models for that Make thats under that Year etc...
with Java i was able to use a HashMap to make this work to where i can have multiple keys of the same name and i can search for what ever key in this case year is selected grab all the Makes or Values that has that year as a key.
Here is the XML format
<?xml version="1.0" encoding="utf-8" ?>
<vehicles>
<Manufacturer>
<Make>Subaru</Make>
<Year>2010</Year>
<Model>Impreza</Model>
<Sub-Model>2.0i</Sub-Model>
<Highway>36 MPG highway</Highway>
<City>27 MPG city</City>
<Price>$17,495</Price>
<Description>
Symmetrical All-Wheel Drive.
SUBARU BOXER® engine.
Seven airbags standard.
>Vehicle Dynamics Control (VDC).
</Description>
</Manufacturer>
<Manufacturer>
<Make>Toyota</Make>
<Year>2012</Year>
<Model>Supra</Model>
<Sub-Model>TT</Sub-Model>
<Highway>22 MPG highway</Highway>
<City>19 MPG city</City>
<Price>$48,795</Price>
<Description>
16-inch aluminum-alloy wheels.
6-speaker audio system w/iPod® control.
Bluetooth® hands-free phone and audio.
Available power moonroof.
</Description>
</Manufacturer>
<Manufacturer>
<Make>Subaru</Make>
<Year>2011</Year>
<Model>Impreza</Model>
<Sub-Model>2.0i Limited</Sub-Model>
<Highway>36 MPG highway</Highway>
<City>27 MPG city</City>
<Price>$18,795</Price>
<Description>
16-inch aluminum-alloy wheels.
6-speaker audio system w/iPod® control.
Bluetooth® hands-free phone and audio.
Available power moonroof.
</Description>
</Manufacturer>
<Manufacturer>
<Make>Subaru</Make>
<Year>2011</Year>
<Model>Impreza</Model>
<Sub-Model>2.0i Limited</Sub-Model>
<Highway>36 MPG highway</Highway>
<City>27 MPG city</City>
<Price>$18,795</Price>
<Description>
16-inch aluminum-alloy wheels.
6-speaker audio system w/iPod® control.
Bluetooth® hands-free phone and audio.
Available power moonroof.
</Description>
</Manufacturer>
</vehicles>
The closest type to the java hashmap is the Dictionary. Since you need to have multiple items with the same key, I would use a Dictionary<int,List<Item>>.
Here are some basic function you might need:
void AddItem(int key, Item i, Dictionary<int,List<Item>> dict)
{
if (!dict.ContainsKey(key))
{
dict.Add(i,new List<Item>());
}
dict[key].Add(i);
}
List<Item> GetList(int key)
{
if (dict.ContainsKey(key))
{
return dict[key];
}
else
{
return new List<Item>(); // can also be null
}
}
I've got some problems parsing the response of a Last.fm API call from a Silverlight 3 application. I pass the response string of the REST service call, which was made via the WebClient class, to the XDocument.Parse() method to get a XDocument.
Parsing the xml string seems to be successful but when I look at the resulting XDocument it shows that the XDocument has only one node containing the whole xml string. So calling any method like Element(nodeName) returns null.
I couldn't image that the result string of the REST service call returns an invalid and not well formed response so probably I do something wrong.
UPDATE
The code I use to parse the XML:
XDocument xml = XDocument(e.result) // e is the response from the WebClient call.
XElement nameNode = xml.Element("name");
After running this code, the nameNode object is null.
And here is the XML the Last.fm REST service returns without any modification. The \n and \t characters were all part of the response.
<?xml version=\"1.0\" encoding=\"utf-8\"?>\n <lfm status=\"ok\">
\n<artist>
\n <name>Air</name>\n <mbid>cb67438a-7f50-4f2b-a6f1-2bb2729fd538</mbid>\n <url>http://www.last.fm/music/Air</url>\n <image size=\"small\">http://userserve-ak.last.fm/serve/34/251119.jpg</image>\n <image size=\"medium\">http://userserve-ak.last.fm/serve/64/251119.jpg</image>\n <image size=\"large\">http://userserve-ak.last.fm/serve/126/251119.jpg</image>\n <image size=\"extralarge\">http://userserve-ak.last.fm/serve/252/251119.jpg</image>\n <image size=\"mega\"></image>\n <streamable>1</streamable>\n <stats>
\n <listeners>1176515</listeners>\n <playcount>39388973</playcount>\n
</stats>\n\n <similar>
\n\t <artist>
\n\t <name>Zero 7</name>\n\t <url>http://www.last.fm/music/Zero+7</url>\n\t <image size=\"small\">http://userserve-ak.last.fm/serve/34/8612117.jpg</image>\n\t <image size=\"medium\">http://userserve-ak.last.fm/serve/64/8612117.jpg></image>\n\t <image size=\"large\">http://userserve-ak.last.fm/serve/126/8612117.jpg</image>\n\t <image size=\"extralarge\">http://userserve-ak.last.fm/serve/252/8612117.jpg</image>\n\t <image size=\"mega\"></image>\n\t
</artist>\n <artist>
\n\t <name>Air and Alessandro Baricco</name>\n\t <url>http://www.last.fm/music/Air+and+Alessandro+Baricco</url>\n\t <image size=\"small\">http://userserve-ak.last.fm/serve/34/511739.jpg</image>\n\t <image size=\"medium\">http://userserve-ak.last.fm/serve/64/511739.jpg></image>\n\t <image size=\"large\">http://userserve-ak.last.fm/serve/126/511739.jpg</image>\n\t <image size=\"extralarge\">http://userserve-ak.last.fm/serve/252/511739.jpg</image>\n\t <image size=\"mega\"></image>\n\t
</artist>\n <artist>
\n\t <name>Röyksopp</name>\n\t <url>http://www.last.fm/music/R%C3%B6yksopp</url>\n\t <image size=\"small\">http://userserve-ak.last.fm/serve/34/22960937.jpg</image>\n\t <image size=\"medium\">http://userserve-ak.last.fm/serve/64/22960937.jpg></image>\n\t <image size=\"large\">http://userserve-ak.last.fm/serve/126/22960937.jpg</image>\n\t <image size=\"extralarge\">http://userserve-ak.last.fm/serve/252/22960937.jpg</image>\n\t <image size=\"mega\">http://userserve-ak.last.fm/serve/_/22960937/Ryksopp+Svein++Torbjorn+Being+Weird.jpg</image>\n\t
</artist>\n <artist>
\n\t <name>Télépopmusik</name>\n\t <url>http://www.last.fm/music/T%C3%A9l%C3%A9popmusik</url>\n\t <image size=\"small\">http://userserve-ak.last.fm/serve/34/880851.jpg</image>\n\t <image size=\"medium\">http://userserve-ak.last.fm/serve/64/880851.jpg></image>\n\t <image size=\"large\">http://userserve-ak.last.fm/serve/126/880851.jpg</image>\n\t <image size=\"extralarge\">http://userserve-ak.last.fm/serve/252/880851.jpg</image>\n\t <image size=\"mega\"></image>\n\t
</artist>\n <artist>
\n\t <name>Thievery Corporation</name>\n\t <url>http://www.last.fm/music/Thievery+Corporation</url>\n\t <image size=\"small\">http://userserve-ak.last.fm/serve/34/172112.jpg</image>\n\t <image size=\"medium\">http://userserve-ak.last.fm/serve/64/172112.jpg></image>\n\t <image size=\"large\">http://userserve-ak.last.fm/serve/126/172112.jpg</image>\n\t <image size=\"extralarge\">http://userserve-ak.last.fm/serve/252/172112.jpg</image>\n\t <image size=\"mega\">http://userserve-ak.last.fm/serve/500/4872357/Thievery+Corporation+thievery_corporation_2.jpg</image>\n\t
</artist>\n
</similar>\n <tags>
\n <tag>
\n\t <name>electronic</name>\n\t <url>http://www.last.fm/tag/electronic</url>\n\t
</tag>\n <tag>
\n\t <name>chillout</name>\n\t <url>http://www.last.fm/tag/chillout</url>\n\t
</tag>\n <tag>
\n\t <name>ambient</name>\n\t <url>http://www.last.fm/tag/ambient</url>\n\t
</tag>\n <tag>
\n\t <name>electronica</name>\n\t <url>http://www.last.fm/tag/electronica</url>\n\t
</tag>\n <tag>
\n\t <name>french</name>\n\t <url>http://www.last.fm/tag/french</url>\n\t
</tag>\n
</tags>\n <bio>
\n <published>Mon, 25 May 2009 19:45:40 +0000</published>\n <summary><![CDATA[There are at least six artists with this name:\r 1. French electronica duo formed in 1995. (The main producer of music under the name Air)\r 2. Chicago-based jazz trio formed in the early 70s.\r 3. Alias of ambient producer Pete Namlook.\r 4. Alias of Japanese artist Koji kurumatani.\r 5. German krautrock band.\r 6. Lithuanian artist band "Artist in residence" 1) The French band Air is a duo consisting of Nicolas Godin and Jean-Benoit Dunckel.]]></summary>\n <content><![CDATA[There are at least six artists with this name:\r 1. French electronica duo formed in 1995. (The main producer of music under the name Air)\r 2. Chicago-based jazz trio formed in the early 70s.\r 3. Alias of ambient producer Pete Namlook.\r 4. Alias of Japanese artist Koji kurumatani.\r 5. German krautrock band.\r 6. Lithuanian artist band "Artist in residence"\r \r <strong>1)</strong> The French band <strong>Air</strong> is a duo consisting of Nicolas Godin and Jean-Benoit Dunckel. They went to school in Versailles, Paris (Lycée Jules Ferry) before forming the band in 1995. Their critically acclaimed first album <a title=\"Air - Premiers symptômes\" href=\"http://www.last.fm/music/Air/Premiers+sympt%C3%B4mes\" class=\"bbcode_album\">Premiers symptômes</a> was followed by the release of <a title=\"Air - Moon Safari\" href=\"http://www.last.fm/music/Air/Moon+Safari\" class=\"bbcode_album\">Moon Safari</a>, <a title=\"Air - The Virgin Suicides\" href=\"http://www.last.fm/music/Air/The+Virgin+Suicides\" class=\"bbcode_album\">The Virgin Suicides</a> (soundtrack), <a title=\"Air - 10,000hz Legend\" href=\"http://www.last.fm/music/Air/10%2C000hz+Legend\" class=\"bbcode_album\">10,000hz Legend</a>, and <a title=\"Air - Talkie Walkie\" href=\"http://www.last.fm/music/Air/Talkie+Walkie\" class=\"bbcode_album\">Talkie Walkie</a>. In 2007, Air released the album <a title=\"Air - Pocket Symphony\" href=\"http://www.last.fm/music/Air/Pocket+Symphony\" class=\"bbcode_album\">Pocket Symphony</a>.\r \r Although Air's music is often referred to as electronica or trip-hop and is often found in such bins in record stores, their form of electronic music actually owes more to the synthesizer sounds of the 1970s such as Jean Michel Jarre and Vangelis. Other influences that are more readily apparent than house and techno are psychedelic rock pioneers Pink Floyd and krautrockers Tangerine Dream (although there are some echoes of dance music styles in the production). Another influence is French crooner Serge Gainsbourg. Air's music also has jazz inflections at times, and their ability to improvise is more clearly highlighted in the live arena. Before they founded Air, JB and Nicolas played together in the band Orange, with others such as Alex Gopher, Xavier Jamaux and Etienne De Crecy names which have recently reappeared in connection with Air's remixes.\r \r Air uses many of their studio instruments (like Moog synthesizers, the Korg MS20, Wurlitzer and Vocoder) live on stage. The band performs the well-known tracks from the albums live as extended or altered versions. Air often works together, both in the studio and live on stage, with artists like Beth Hirsch (Moon Safari), Françoise Hardy ("Jeanne"), Jean-Jaques Perrey ("Cosmic Bird"), Gordon Tracks ("Playground Love" and "Easy Going Woman"), Beck (10,000Hz Legend) and, on the 2004 tour, with Dave Palmer and drummer Earl Harvin. On their 2007 album "<a title=\"Air - Pocket Symphony\" href=\"http://www.last.fm/music/Air/Pocket+Symphony\" class=\"bbcode_album\">Pocket Symphony</a>", more guest writer and vocalist appearances were made by Jarvis Cocker and Neil Hannon (of The Divine Comedy. For the 2007 tour that accompanied the record, the band consisted of Earl Harvin on drums, multi-instrumentalist Steve Jones (<span class=\"userIcon\">steviejjones</span>) and French keyboard player Vincent Taurelle.\r \r Their music has also frequently been used in commercials. "<a title=\"Air – Surfing on a Rocket\" href=\"http://www.last.fm/music/Air/_/Surfing+on+a+Rocket\" class=\"bbcode_track\">Surfing on a Rocket</a>" is the background music for the Nissan Armada commercial (2005). "<a title=\"Air – Playground Love\" href=\"http://www.last.fm/music/Air/_/Playground+Love\" class=\"bbcode_track\">Playground Love</a>" was used in a Levi's jeans commercial (2002). A number of their songs are used as the background music for the BBC 2 show "Top Gear" in their films about exotic sports cars.\r \r They recently contributed to Charlotte Gainsbourg's second album, "5:55".\r \r \r <strong>2)</strong> <strong>Air</strong> was a jazz trio with its roots steeped in Chicago's Association for the Advancement of Creative Musicians (AACM), and was formed originally in 1971 or 1972.\r \r The jazz trio Air formed from within the Muhal Richard Abrams Sextet, which was active on the Chicago scene contemporaneously with the birth and growth of the AACM and groups such as the Art Ensemble of Chicago. Henry Threadgill on reeds, hubcaphone, and percussion; Fred Hopkins on bass, and Steve McCall on drums formed the trio when Threadgill was commissioned by Columbia College to score and adapt Scott Joplin's work for a performance honoring Joplin's centenary (Joplin's birth has been established now as sometime in 1868) and a rebirth of interest in the noted ragtime composer. All three men were Air signs in the zodiac, and so adopted the name.\r \r They performed first around Chicago, while maintaining residency with Muhal Abrams group, which also featured Kalaparusha Maurice Mcintyre and Wallace McMillan, both reed players. The Air "brand" remained a side project until all three reunited in New York in 1975, and began recording under that name for India Navigation, nessa, Black Saint, and Novus. The trio broke up when Steve McCall left in the early 1980s, and when <span title=\"Unknown artist\" class=\"bbcode_unknown\">Pheroan Aklaff</span> joined in 1982, they recorded as New Air, and recorded several albums under that name, including Air Show No. 1 in 1986, which featured Cassandra Wilson on vocals. Andrew Cyrille ultimately replaced akLaff before the band eventually was superceded by the burgeoning careers of its members: Threadgill with his groups Sextett and Very Very Circus, and Hopkins as the go-to bassist for Threadgill, David Murray, and Hamiet Bluiett. McCall's health forced his retirement from touring around 1980, and the dynamic drummer and effusive and gracious man who was a cofounder of the AACM with Muhal Abrams and Fred Anderson, died of a stroke in 1989.\r \r \r <strong>4)</strong> Japanese noise rock, <strong>Air</strong> is the alias of Koji kurumatani.\r \r \r ]]></content>\n
</bio>\n
</artist>
</lfm>\n
How did you determine that everything was in one element? Is doc.FirstNode == doc.LastNode? What is doc.NodeType?
If you are only looking at doc.Root.Value, that won't help, as it contains the concatenation of all the descendent text nodes.
Also, you should post at least a little of the XML document causing this problem.
From your example, you're parsing the XML wrong. XDocument.Element gets the first child element with the given name. "name" is not a child of the document.
I'm trying to create a Podcast RSS feed using WCF. The feed seems to be valid, but the enclosure tag is being ignored. Any ideas?
Fixed now ... don't use file file:/// urls even if you are feeding yourself the files.
<rss version="2.0">
<channel>
<title>Joe Blow</title>
<link>http://google.com/</link>
<description>The Joe Blow Show</description>
<managingEditor>joeblow#gmail.com</managingEditor>
<category>Talk Radio</category>
<item>
<guid isPermaLink="false">1342</guid>
<category>Podcast</category>
<title>Joe Blow Show #1</title>
<description>Joe Blow Show #1</description>
<pubDate>Mon, 01 Jun 2009 13:57:47 -0600</pubDate>
<enclosure url="file:///C:/JoeBlowShow1.mp3" type="audio/mpeg" length="101725855" />
</item>
</channel>
</rss>
Two things:
The enclosure should not be stored on your hard drive. This should be a world accessible URL. (This assumes that you are publishing this on the web.)
Run the feed through a feed validator to look for errors.