I am using > http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl webservice to get the weather detials by calling GmlTimeSeries webmethod. Now I just want to read temparature, weather icon link details from the xml. The xml has huge data. Can anybody give an idea to fetch the required data from the xml?
NDFD HOme Page
The XML looks almost like below : Full XML File is Here
I want to fetch Temparature from below xml data:
<gml:featureMember>
<app:Forecast_Gml2Point>
<gml:position>
<gml:Point srsName="EPSG:4326">
<gml:coordinates>-87.8859170,41.7450495</gml:coordinates>
</gml:Point>
</gml:position>
<app:validTime>2011-06-07T12:00:00</app:validTime>
<app:temperature>77.0</app:temperature>
</app:Forecast_Gml2Point>
</gml:featureMember>
<gml:featureMember>
<app:Forecast_Gml2Point>
<gml:position>
<gml:Point srsName="EPSG:4326">
<gml:coordinates>-87.8859170,41.7450495</gml:coordinates>
</gml:Point>
</gml:position>
<app:validTime>2011-06-07T15:00:00</app:validTime>
<app:temperature>90.0</app:temperature>
</app:Forecast_Gml2Point>
</gml:featureMember>
And weather phrase from below:
<gml:featureMember>
<app:Forecast_Gml2Point>
<gml:position>
<gml:Point srsName="EPSG:4326">
<gml:coordinates>-87.8859170,41.7450495</gml:coordinates>
</gml:Point>
</gml:position>
<app:validTime>2011-06-08T03:00:00</app:validTime>
<app:weatherPhrase>Mostly Clear</app:weatherPhrase>
</app:Forecast_Gml2Point>
</gml:featureMember>
<gml:featureMember>
<app:Forecast_Gml2Point>
<gml:position>
<gml:Point srsName="EPSG:4326">
<gml:coordinates>-87.8859170,41.7450495</gml:coordinates>
</gml:Point>
</gml:position>
<app:validTime>2011-06-08T06:00:00</app:validTime>
<app:weatherPhrase>Mostly Clear</app:weatherPhrase>
</app:Forecast_Gml2Point>
</gml:featureMember>
The above is a piece of xml file. Like this I have large data for 7 days weather details. I need to read for the temp and weather condition from above xml.
Full XML File is Here
I think you will find your answer here
Edit:
you need to use namespace, for example:
XNamespace app = "http://www.weather.gov/forecasts/xml/OGC_services";
var result = from i in doc.Descendants(app+"Forecast_Gml2Point")
select new
{
temperature = i.Element(app + "temperature"),
icon = i.Element(app+"weatherIcon")
};
Edit 2:
if you need to get Element with other namespace, here is another example:
XNamespace gml ="http://www.opengis.net/gml"
i.Element(gml+"coordinates" )
It would be easier if you use the "Add Web Reference" feature of Visual Studio. In this way, Visual Studio generates all the (proxy) classes for you base on the WSDL, and you can then program against the classes like how you'll do normally. In other words, there is no parsing of XML needed.
As pointed out in this link:
Visual Studio.Net Web References are proxy classes created on the client to connect to the Web Service running on the server. Inside of the IDE Web references automatically generate code and insert hidden files into your project. This is required because .Net is type safe and in order to compile code that uses the Web Service, the client has to know the method signature of each method that is called.
You might want to refer to the above link about consuming WSDL in details.
Related
Hi to all the community.
This question is related to a specific product called OpenText Content Server 10.5 (previously named LiveLink) and the usage of his Content Server Web Service (CWS).
We use a very simple call to retrieve a document using his DocumentID "GetNode" passing the internal Document Id:
This method works every time except when we retrieve some files like Microsoft Excel with xls or xlsx extensions.
Even a text file with "Hallo Word" in it, renamed to xls does not works!
My idea is that this could be:
a) a faulty web service and a patch is needed
b) we missed something in the LiveLink configuration to enable certain files.
Any help is moire than welcome
Thanks in avant for any support
---------- Part 2 -----------------
To be more specific consider that we have a document with ID= 229835 (also the Nickname has the same value)
1) With the GetNode(229835) we receive the following error: DocumentManagement.GetNode() failed on the Livelink Server. No results were returned. Check the Livelink Server thread logs. (nothing on the server logs!)
2) With the GetNodeByNickName("229835") everything works fine.
3) With te GetGUID(229835) we first retrieve a GUID like "3F67..8942" and then with GetNodeByGUID(""3F67..8942") everything works fine.
So my questions is why the first command fail and the other two works?
Consider that this a "seems" to happen with certain types of XLS, XLSX, ZIP, DOC, DOCX files. The size is no more than 2 Mb.
The GetNode call returns only the meta data for the node.
You want to use GetVersionContents.
As a minimum you need to specify the ID and the versionNum for the required content.
The following code is an example written in Ruby, but it should be easy to translate the logic into a different language.
#
# get specific +version+ of a document +id+
# if +file_name+ is nil it returns the content of the file as base64 encoded string
#
def get_version(id, version, file_name=nil)
response = #docman.request('GetVersionContents',
'wsdl:ID' => id,
'wsdl:versionNum' => version)[:contents]
if file_name
File.open(file_name, 'wb') do |f|
f.write(Base64.strict_decode64(response))
end
else
return Base64.strict_decode64(response)
end
end
I am using the most recent Aspose.PDF DLL in Visual Studio with the appropriate (in the code applied) license.
For my conversion from pdf files to pdfa types I use the following code:
Aspose.Pdf.Document pdf = new Aspose.Pdf.Document(pdfPath);
bool converted = pdf.Convert(temptext, PdfFormat.PDF_A_1A, ConvertErrorAction.None);
Now I receive the following errors, extracted from the temptext txtfile:
<Problem Severity="Error" Clause="6.8.3.3" Convertable="True">Catalog shall have struct tree root entry</Problem>
<Problem Severity="Error" Clause="6.8.2.2" Convertable="True">Catalog shall have MarkInfo entry</Problem>
Now to get a MarkInfo entry into the structure of my PDF file, I am supposed to be able to add elements to the catalog or root structure ( I am not sure exactly) which will give me the ability to create this entry tag to the logical structure of the PDF file.
Then these two errors will be avoided and the PDFa file will be converted correctly.
I noticed PDFSharp had a solution for this problem with their dll’s in the following way:
PdfSharp.Pdf.PdfDocument doc = PdfSharp.Pdf.IO.PdfReader.Open(pdfPath);
PdfSharp.Pdf.PdfDictionary structureTreeRoot = new PdfSharp.Pdf.PdfDictionary(doc);
structureTreeRoot.Elements["/StructElem"] = new PdfSharp.Pdf.PdfName("/Entry1");
PdfSharp.Pdf.PdfArray array = new PdfSharp.Pdf.PdfArray(doc);
doc.Internals.AddObject(structureTreeRoot);
doc.Internals.Catalog.Elements["/StructTreeRoot"] = PdfInternals.GetReference(structureTreeRoot);
I want to only use the Aspose dll. Does anyone know how I can apply this with aspose dll?
Currently, Aspose.Pdf does not support to add MarkInfo entry in logical structure of PDF. Please check the forum thread for similar question.
My name is Tilal Ahmad and I am developer evangelist at Aspose.
I have a large XML file (68Mb), I am using SQL Server Business Intelligence Studio 2008 to extract the XML data into a database. There is an error in the XML file some where that prevents it from executing. Possibly a missing tag or something like that. The file is so large I cant manually sort through it looking for the error.
Below is a sample of the the XML schema used.
How can I use XPath to sort through the XML in VS 2012 using C#?
An example would be great!
-<PhoneNumberList>
<PhoneNumber value="1234567890" type="Phone"/>
</PhoneNumberList>
-<YearsOfServiceList>
<YearsOfService experienceInMonths="24" description="SuperAdmin" objectCode="049"/>
</YearsOfServiceList>
</Person>
-<Person dob="1960-01-09T00:00:00" lastName="Smith" middleName="Will" firstName="John" id="9999-9999-9999">
-<SiteList>
-<Site id="2014" siteLongName="HA" siteCode="1255" systemCode="999">
-<StaffPositionList>
<StaffPosition id="73" staffPosition="Administrator"/>
</StaffPositionList>
</Site>
</SiteList>
-<ProgramList>
<Program id="1234" siteLongName="ABC" siteCode="0000" systemCode="205"/>
<Program id="5678" siteLongName="DEF" siteCode="0000" systemCode="357"/>
</ProgramList>
-<TypeList>
<Type Description="Leader" certificateType="D"/>
<Type Description="Professional" certificateType="P"/>
</TypeList>
-<EmailList>
<Email value="jsmith#somesite.com" type="Email"/>
</EmailList>
-<PhoneNumberList>
<PhoneNumber value="1234567890" type="Phone"/>
</PhoneNumberList>
-<YearsOfServiceList>
<YearsOfService experienceInMonths="24" description="SuperAdmin" objectCode="049"/>
</YearsOfServiceList>
</Person>
</PersonList>
</GetPersonDetail>
If you want to do it in code then create an XSD file describing a valid format for the data, embed it as a resource in your app and then use code like this
var errors = new List<string>();
var schemaSet = new XmlSchemaSet();
schemaSet.Add("", XmlReader.Create(new StringReader(Properties.Resources.NameOfXSDResource)));
document.Validate(schemaSet, (sender, args) =>
{
errors.Add(args.Message);
}
);
This will give you a list of validation errors.
You don't need to search "by hand" if you use a competent text editor. NotePad++'s XML plugin, for instance, can determine if your XML as a whole is well-formed or valid, and both instances will provide separate error messages.
If you don't have a schema and the file is well-formed, you can use the CLR's System.XML namespace to read in the document and then iterate through its nodes using LINQ-to-XML, which would allow you to very finely control which nodes go where. With LINQ, you could either create a new XML file with only the valid entries, procedurally correct the invalid entries as you determine where they are, or even just write to your SQL server database directly.
Your troubleshooting process should be something as follows:
Is the XML well-formed? I..e, does it comport to the fundamental rules of XML?
Is the XML valid? I.e., does it have the elements and attributes you expect?
Is your import query accurate?
For things like this I usually have luck checking and fixing the data in Notepad++. Install the XmlTools plugin and that has a menu for checking the xml syntax and tags.
Also, those dashes will give you problems, it's best to save out the xml file directly without copying by hand.
A 68MB XML file is no problem for XML editors such as XMLBlueprint 64-bit (http://www.xmlblueprint.com/) or Stylus Studio (http://www.stylusstudio.com/). Just check the well-formedness of your xml file (F7 in XMLBlueprint) and the editor will display the errors.
I want to create a component by giving XML source input directly using core service 2011, in SDL Tridion 2011.
I want to write code to create a component by uploading source XML. Using the core service 2011.
Say name of the xml file is helloworld.xml and location is D:\abcd\cdef\all\helloworld.xml.
I have written the code like this, but its not working.
XmlDocument contentxml = new XmlDocument();
contentxml.LoadXml(#"D:\abcd\cdef\all\helloworld.xml");
Response.Write("<BR>" + contentxml.ToString());
component.Content = contentxml.ToString();
ComponentData comp = (ComponentData)client.Create(component, new ReadOptions());
The Response.write is displaying nothing. Correct me if I missed any thing.
It's not creating any component and error is coming.
When i tried this:
XmlDocument contentxml = new XmlDocument();
try
{
contentxml.LoadXml(#"D:\abcd\cdef\all\helloworld.xml");
}
catch (XmlException exp)
{
Console.WriteLine(exp.Message);
}
StringWriter sw = new StringWriter();
XmlTextWriter xw = new XmlTextWriter(sw);
contentxml.WriteTo(xw);
Response.Write("<BR>" + sw.ToString());
component.Content = sw.ToString();
ComponentData comp = (ComponentData)client.Create(component, new ReadOptions());
This time it's showing unable to find UUId: some thing like that.
My helloworld.xml looks like this.
<Content xmlns="uuid:1111eb85-0X11-11f9-1e2X-1X82X78fX920">
<first>Hello World.This is Fisrt field</first>
<second>Hello World.This is second field</second>
</Content>
It would be great if some one share some sample code to do it.
Loading any XML from a a file and trying to create a component won't work unless the XML uses the format the CMS is expecting.
The XML structure of a component in SDL Tridion has some fixed parts (Example Nodes Content, Metadata) plus some flexible parts
(The way you define the fields).
First you need to have the XML with the same structure that the CMS is expecting.
Typically the nodes that should be in your xml are the CONTENT and METADATA, load those in an XML Document and use the Core Service API to
create a component using the content contained in those nodes.
The best way to know how which is the structure of a component based on an schema is to create a sample component using the Tridion UI and
see how the XML is constructed. After that you need to create your XML Sources using that structure.
I posted recently an example of how to create a component using the Core Service, please have a look at that.
Faulted State error while creating component with Core Service
Following this code, you can access the nodes Content and Metadata
componentData.Content = xmlUtil.GetNewXmlNode("Content", schemaData.NamespaceUri);
componentData.Metadata = xmlUtil.GetNewXmlNode("Metadata", schemaData.NamespaceUri);
And replace those with your content
The general outline:
Load the XML from the file into an XDocument / XmlDocument.
Create a new Component by calling GetDefaultData on the client.
Set the Content property of the Component to the XML.
Save the Component by calling Save on the client.
If you haven't already, please have a look at the Core Service API documentation available on SDL Tridion World.
If you have trouble implementing this, please post the code that you have and what you have tried in order to make it work.
Using XmlDocument.LoadXML() expects an XML string as input, as commented by Peter you should use XMLDocument.Load() instead, see here for more details http://msdn.microsoft.com/en-us/library/a8ta6tz4.aspx
When you have passed that hurdle you will need the information Miguel gave in his answer to continue.
I have managed to read in a saved .csv file on my hard disc and get the data to poputlate a data table. I now want to take that data and put it into XML format, then send the XML to a web service. How can I do this?
Thanks for your time.
One option would be to connect to the Web Service using WCF (or ASP.NET Web Services depending on which .NET version you're using). You can then easily fill the proxy classes the framework creates for you and call the service.
The second option would be to use an XmlTextWriter and use that to build the XML document in a MemoryStream. Once you have the XML document built in memory, you can flush the document and send it out to the Web Service.
A third option would be to use LINQ to XML to build the XML document on the fly. Depending on the structure you parse your CSV file into this may be easier/harder for you than using the XmlTextWriter.
XLinq is excellent for putting the data into XML. If you can use an up to date .NET framework I highly recommend it.
There's some info to get started with here (for example)
http://www.c-sharpcorner.com/UploadFile/mahesh/xLinkDoc06202007130827PM/xLinkDoc.aspx
As for sending that XML to a web service, perhaps you should be calling the web service via a client automatically generated using the Visual Studio ServiceReference tool.
You may or may not need to send XML to that -- in many cases services are object-based (i.e. you'd not need XLinq, provided you can parse the CSV into the correct objects.)
/EDIT:
Rough example for calling webservices using WCF:
using(var client = new ServiceReference1.ThirdPartyServiceClient())
{
client.SendSomething("123", "hello");
string output = client.GetSomething();
Console.WriteLine(output);
}
Following code can also be used.
public static List<Student> convertXMLtoList(string filePath)
{
XDocument doc = XDocument.Load(filePath);
List<Student> studentsMarks = doc.Descendants("Student").Select(x => new Student()
{
RollNo = int.Parse(x.Element("roll_no").Value),
Name = x.Element("name").Value,
}).ToList();
return studentsMarks;
}
Where XML looks like
<?xml version="1.0" encoding="utf-8"?>
<Students>
<Student>
<roll_no>1</roll_no>
<name>XYZ</name>
</Student>
...
</Students>
You can find more details at http://bit.ly/1eveLz3. you can find CSV to XML also on this post.
I haven't done this with a datatable, but it work great for other objects.
Try something like this:
public void writeToXML(DataTable inputData, string fileName) {
XmlSerializer xml = new XmlSerializer(typeof(DataTable));
StreamWriter sw = new StreamWriter(fileName);
xml.Serialize(sw, inputData);
sw.Close();
}
Edit: Just noticed you needed to pass it along to a web service. So instead of StreamWriter, use a memory stream...but same idea.
There are different options depending on how robust of a solution you want. Assuming you want to follow the quickest route you should look at the XmlWriter. Using an XmlWriter you can quickly generate an XML document, save to string and then pass along to your web service.