passing xml document to c# from php - c#

I need to pass the following xml document to my c# dll from PHP .Also i only need to pass the element watchlists and its child element.Its a DOMDocument
<assumption_list>
<assumption name="test" id="23" description="test1" is_shared="no">
<watchlists>
<watchlist globalissuer="k" prepayrate="" prepaytype="CPR" defaultrate="" defaulttype="CDR" lossrate="" lagmonths=""/>
</watchlists>
</assumption>
</assumption_list>
1:Should i convert this xml document to string and then pass it to c# dll,if yes should is there any PHP function that does that like xmldoc.tostring() of c#
2:How do i grab the watchlists element from this xml document.i tried using this code.
$watchlists = $xmlDoc->getElementsByTagName('watchlists');
If this is the right way then how do i pass this node to c# ,should i convert it to string or just pass this xml node directly.
Any feedback would be really helpfull.

I dont think there is a SimpleXML::getElementsByTagName()
This should echo what you want:
$result = $xml->xpath('/assumption_list/assumption/watchlists');
foreach($result as $node)
echo $node->asXML();
DEMO
EDIT :
You edited your question and changed SimpleXML into DOMDocument
$result = $dom->getElementsByTagName('watchlists');
foreach($result as $element)
echo $dom->saveXML($element);
DEMO

Related

C# write to json file with SimpleJSON

SimpleJSON link https://github.com/Bunny83/SimpleJSON
There is no documentation and I am trying to understand how to (add/delete/edit) information into the JSON file below.
All Values are strings
I want to know how to Add JSON Object/Array like shown below to the file
Delete a whole object/array ex:("Character0":{...})
edit a Node x["Character0"]["Head"].Value = "New Head" so that value updates
Any help would be awesome if you know how the SimpleJson class works would be helpful.
JSON FILE
{
"Character0":{
"Head":"HeadCube",
"Neck":"NeckCube",
"Body":"BodyCube",
"Arms":"Sphere_Capsule_Arms",
"Legs":"Sphere_Capsule_Legs"
}
}

C# Webservice response xml displaying as pdf

I am new to C# web development. I am developing a software that receives response from webservice in XML format. (includes barcodes generated by webservice).
There is an option given by webservice provider, that i have to add a line
(Example<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">)
as a second line in the xml and display in web browser by using style sheets provided by webservice provider. If i have to choose this option, how can i add that line as second line in the received xml file also how can i map the style sheets provided by the webserive in the project for this xml.
If i dont take that option, Is it possible to display the data in xml as a pdf(includes barcodes generated by webservice), if i dont choose the option .
If I understand your question correctly, you want to:
Add a stylesheet specification to an existing XML
Convert an XML to PDF
1. ADDING A STYLESHEET
There is an option given by webservice provider, that i have to add a line [...] as a second line in the xml and display in web browser by using style sheets
This is done using e.g. Linq, like in this answer.
First of all, I think the example you used, i.e.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
may be inaccurate, as it is the first line of a XSL file (a stylesheet); those kind of files are used to transform an XML into another file (a different XML or an HTML, like in your case). However, you say
using style sheets provided by webservice provider
so my guess is that you already have those stylesheets and you can you use them, rather than creating them yourself.
If so, the line you want to add is like
<?xml-stylesheet type="text/xsl" href="helloWorld.xsl"?>
Let's suppose you already have your XML stored into an XDocument variable named "Document" with its root element being "Root"
var FilePath = "Example.xml";
var Document = XDocument.Load(FilePath);
var Root = XDocument.Descendants("Root").Single();
Then you can add your stylesheet this way, getting a new XML:
var NewDocument = new XDocument(
new XProcessingInstruction("xml-stylesheet", "type='text/xsl'ref='helloWorld.xsl'"),
Root);
2. XML to PDF
There are several ways to do this.
You might parse your XML, retrieve the elements you want to show on your PDF, use a library like iTextSharp to create a specific layout and place their contents on the file.
Or, since you already have an XML and you can transform it to an HTML using an XSL, you can use wkHtmlToPdf.
Let me know if you need more details.

How to create a NewsML in C#

We are currently working on news website there we have an requirement to extract NewsML xml files.
Is there any tool in asp.net/C# to extract newsML xml files ?
First of all, this is a lot easier with the newer XML API Linq-2-XML (XLinq).
var root = XElement.Parse(xmlText); // or directly .Load(fileName)
List tifNames = root.Descendants("TIFNAME").Select(e => e.Value);
How about this ,you can generate a .xsd ,then build class by xsd.exe /c xsdname.xsd,then serialize xmlstring to this class.

How to comment an XMLElement using C#?

My application reads values from an xml file which I write everytime when I execute the application.
This is how I made comments of my lines:
XmlComment DirCom = doc.CreateComment("Comment")
XmlElementName.AppendChild(DirCom);
And It works fine, But now I need to comment the XML element, And the above doesn't work. My final result should be like:
<!--<name>David</name>-->
using C# and the XML document library.
To comment an xml node I would do it like this :
XmlComment DirCom = doc.CreateComment(XmlElementName.OuterXml);
doc.InsertAfter(DirCom, XmlElementName);
doc.RemoveChild(XmlElementName)

Dynamically change the xml file location that flash loads using c#

Can someone tell me how i can change the .xml file that a flash movie loads using c#. ie: i would like an ActionScript variable that defines the location of the flash movie. I would like to be able to change this variable using c# if possible.
i dont really know how it would look, but something like:
<object xmlpath='" + myCSharpVar + "'" ...></object>
I just starting this, but my ultimate goal is to create a .swf movie that can load an xml file that specifies images, etc. However i want to use the same .swf file in multiple places and only have to change a ref to what xml file it uses - and my Flash/ActionScript skills are very rusty.
To clear it up a bit, in AS you can do something like:
loader.load( new URLRequest("IWantThisNameDynamic.xml") );
how can i define that xml file in my c# code?
I'm quite sure you cannot "create" your own attributes for the object tag. At least not without consulting with the w3c ;-)
Passing values to flash is done via the "flashvar"-param:
<object ...>
<param name="flashvars" value="&xmlpath=<path to xml>"/>
</object>
In the flash-movie you can now access the path to your xml via the "xmlpath"-variable.
Edit: sorry, question was about ASP.NET
If you were using an AxShockwaveFlash object in C#, you would set the variables this way:
AxShockwaveFlash movie; // already exists
string xmlPath = "some path";
movie.FlashVars = "xmlPath=" + xmlPath; // url-encoded variables
Then in AS2:
var xmlPath:String = _level0.xmlPath;
Or in AS3:
var xmlPath:String = loaderInfo.parameters.xmlPath;

Categories

Resources