Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all 935 articles
Browse latest View live

SignedXML.ComputeSignature Performance

$
0
0

Hello!

I´m facing some performance issues using the ComputeSignature method .

I need do sign a huge volume of xml files, about 10000 files in a row.

To sign these files i used SignedXML class , but it is taking 1 second per file. That´s not a long time, but with a huge volume it will take a long time to finish.

Is there any other way to sign these files in a fastest way?

I´m using these configurations (client's requirement):

Transformations:

XmlDsigEnvelopedSignatureTransform
XmlDsigC14NTransform
Canonicalization:
SignedXml.XmlDsigCanonicalizationUrl



XML serialize

$
0
0

I am trying to generate an xml by serializing and facing some issues. There is a part of xml which is dynamic. the section "person" is dynamic i.e the sub sections
 person can increase or decrease. I am able to serialie the class with static value( with single person name and age) but when getting multiple 
values then I am not able to handle that.All the values are fetched from database and every name and age is store as a distinct row in database.So if I have 2 names and age then it will be stored
as 2 distinct rows in database. I tried to create a loop(on basis of number of rows) but not able understand how to incorporate the dynamic section to rest of xml
part.

Can someone help on this?

--------------- desired xml output--------------------------------------

   

<details>
 <description>Some description</description>
 <hobby> Anything</hobby>

<person>
   <name>Dann</name>
   <age>21</age>
</person>
<person>
   <name>Scott</name>
   <age>23</name>
</person>


</details>

--------------------------------------------------CODE -----------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.Xml.Serialization;

namespace xmltest
{
    public class Program
    {
        public class xmlserial
        {

            [XmlElement("details")]
            public string details { get; set; }
            [XmlElement("description")]
            public string description { get; set; }
            [XmlElement("hobby")]
            public string hobby { get; set; }

            [XmlElement("person")]
            public string person { get; set; }
            [XmlElement("name")]
            public string name { get; set; }
            [XmlElement("age")]
            public int age { get; set; }

            public xmlserial()
            {
            }

        }
        static void Main(string[] args)
        {

            string conStr = ConfigurationManager.ConnectionStrings["Test"].ToString();
            DataSet abc = new DataSet();
            abc = test_DS(conStr);

            List<xmlserial> AddressList = new List<xmlserial>();
            xmlserial y = new xmlserial();
            foreach (DataTable dt in abc.Tables)
            {

                y.details = "hello";
                y.description = "description";
                y.hobby = "hobby";
                y.person = "person";
                foreach (DataRow dr in dt.Rows)
                {

                    y.name = dr["NAME"].ToString();
                    y.age =(int) dr["age"];

                }
                AddressList.Add(y);
            }
            serialize(AddressList);

        }
        public static void serialize(List<xmlserial> list)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(List<xmlserial>));
            serializer.Serialize(Console.Out, list);
            Console.WriteLine();
            Console.ReadLine();

        }

        public static DataSet test_DS(string conStr)
        {
            try
            {
                using (SqlConnection SqlConn = new SqlConnection(conStr))
                {

                    SqlConn.Open();

                    using (SqlCommand cmd = new SqlCommand())
                    {
                        cmd.Connection = SqlConn;

                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.CommandText = "dbo.test_sp";                      

                        using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                        {                      
                            DataSet dataset = new DataSet();
                            da.Fill(dataset);

                            return dataset;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //Catch the exception

            }
            return null;
        }

    }
}

--------------------------------------------------------------------------------SQL  table and Procedure ---------------------------------

create table persondetails(name varchar(20),age int)
insert into persondetails(name,age)
select 'Dann',21
union all
select 'Scott',23
union all
Select 'Allen',24



create proc test_sp
as
 begin
   select distinct * from persondetails
 end

                                                                                       

How to build element path to query 2 nodes in XML

$
0
0

I have a sample xml which I am trying to query to show on SSRS report 

I want to show all the values from ELEMENT1 AND ELEMENT2.

I am not getting my element path right

My current query is like this 

="<Query><XmlData>" & Parameters!test.Value & "</XmlData> <ElementPath></ElementPath> <ElementPath></ElementPath> </Query>"

<Root xmlns:ns="http://schemas.microsoft.com/..."><ns:Element1><Node>Value A</Node><Node>Value B</Node><Node>Value C</Node></ns:Element1><ns:Element2><Node>Value D</Node><Node>Value E</Node><Node>Value F</Node></ns:Element2></Root>




XML deserializer

$
0
0

Hello,

I created an .xsd schema to deserialize an XML stream (see below).

The deserialzation works perfectly right now.

My issue is, I would like to use the template to deserialize other objects in addition to the CustomModule1 element.  The schemas are exactly the same, only the element name would change.

Is there a way to use a wildcard for the name of CustomModule1 so that it would accept any name there (e.g. CustomModule2, CustomModule3...)?

I looked at using xs:any, but I could not figure out how to make that work in my schema.

Thanks.

Bryan Hunt

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="response">
<xs:complexType>
<xs:sequence>
<xs:element ref="result"/>
</xs:sequence>
<xs:attribute name="uri" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name="result">
<xs:complexType>
<xs:sequence>
<xs:element ref="CustomModule1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="CustomModule1">
<xs:complexType>
<xs:sequence>
<xs:element ref="row" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="row">
<xs:complexType>
<xs:sequence>
<xs:element ref="FL" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="no" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name="FL">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="val"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:schema>

System error: -2147012711

$
0
0
What it mean with System error: -2147012711?

custom xmlreader and try to remove xmls=

$
0
0
hello.
I have created with the xsd.exe any classes from a huge xsd..
Then i load  a my custom xmlreader
I would create a custom xmlreader for make some little adjustment on the fly like sax to some xml files of size around 4 / 5 gb.
The problem is that when i change an element on the fly in the custom xmlreader the next function that is triggered is the public override string NamespaceURI and any string i return in this function i get an error because the parser asks for an xmls= and i can't remove this xmls= that is proposed in all elements.
How i can eliminate this xmlns=?
thanks.

Converting XML to JSON using XSLT

$
0
0

Hi All,

Iam a newbie using XSLT and I wanted to convert an XML to JSON using XSLT. Below is the Xml file that i wanted to convert to JSON file usinf XSLT :

"<mbs MsgType='1'><msg mid="6545" mr="0" st="020516145100" et="020616145100" u="rkunamneni" r="0" cc="appshark61" mt="2" rid="165074" ms="256" ph="+919985781502" smt="" bsms="0" e="ram.kunamneni@appshark.com" o="2" mri="2" mdt="1" l="en-US" mmr="0" stt="green" imd="1" mh="1" iu="0"><d><![CDATA[hello this is a ticker message]]></d><t><![CDATA[hello]]></t><t><![CDATA[hello]]></t><d><![CDATA[hello this is a ticker message]]></d></msg></mbs>"

Kindly help me on the same.

Thanks,

Ram


ram

VBA - parsing XML namespace problem

$
0
0

Hi,

I've spent the guts of a week trying to resolve this ....I haven't yet.

My goal is simply extracting a value from the xml below (the value I wish to extract is "Amount"...which I've bolded.)

But the first couple of lines of XML in bold are causing a problem with everything I've tried ...can you help?

<xml version="1.0">

 <GetCompetitivePricingForASINResponse xmlns="http://mws.amazonservices.com/schema/Products/2011-  10-01">
 <GetCompetitivePricingForASINResult ASIN="B003L6HJAA" status="Success">
 <Product xmlns:ns2="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd">
 <Identifiers>
 <MarketplaceASIN>
 <MarketplaceId>A1F83G8C2ARO7P</MarketplaceId><ASIN>B003L6HJAA</ASIN></MarketplaceASIN>
 </Identifiers>
 <CompetitivePricing>
 <CompetitivePrices>
 <CompetitivePrice bel c subc><CompetitivePriceId>1</CompetitivePriceId><Price>
 <LandedPrice>
 <CurrencyCode>GBP</CurrencyCode><Amount>14.45</Amount></LandedPrice>
 <ListingPrice>
 <CurrencyCode>GBP</CurrencyCode><Amount>14.45</Amount></ListingPrice>
 <Shipping>
 <CurrencyCode>GBP</CurrencyCode><Amount>0.00</Amount>
 </Shipping>
 </Price>
 </CompetitivePrice>
 </CompetitivePrices>
 <NumberOfOfferListings><OfferListingCount c>34</OfferListingCount><OfferListingCount c>34</OfferListingCount></NumberOfOfferListings></CompetitivePricing>
 <SalesRankings>
 <SalesRank>
 <ProductCategoryId>home_improvement_display_on_website</ProductCategoryId><Rank>14121</Rank>
 </SalesRank>
 <SalesRank>
 <ProductCategoryId>home_and_garden_display_on_website</ProductCategoryId><Rank>71928</Rank>
 </SalesRank>
 <SalesRank>
 <ProductCategoryId>1938969031</ProductCategoryId><Rank>180</Rank>
 </SalesRank>
 </SalesRankings>
 </Product>
 </GetCompetitivePricingForASINResult><ResponseMetadata>
 <RequestId>8c59ff95-ff9a-480a-82e7-9f87bfe180f9</RequestId></ResponseMetadata>
 </GetCompetitivePricingForASINResponse>




Process an object graph as opposed to an XML file- using XSLT

$
0
0

I'm trying to find out if I can feed an object graph into an XSLT transformer rather than an XML file/stream. I could of course XML serialize the object graph and use the resulting XML but this seems wasteful.

Does anyone know of such a mechanism in or for .Net?

Thanks

Korp.

read pdf content into text file using c#.net

$
0
0
Dear all,

Im trying to read pdf content into text file using c#.net.
when i trying to read pdf, its returning content as a unicode characters .so how can i read the characters form pdf.

Thanks,
ram krishna

XmlSerializer "hookup" when deserializing

$
0
0

Many times I have an object graph (root Object with properties which are collections of objects which in turn have... a.s.o.).
Often these are represented as xml files with a structure similar to:
<Root attr1="something">
  <Children>
    <Child name="First child">
      <GrandChildren>
        <GrandChild name="First grandchild"/>
        <GrandChild name="Second grandchild"/>
      </GrandChildren>
    <Child name="Second root child">
:
:

Then often each of the entities needs to refer it's "owner" or "parent" Object (e.g. GrandChild needs to refer it's parent which is an instance of Child and so on) (Down to a much deeper Level than indicated above.

Assume that the entity classes all have a property called parent or owner and I would like to get this one filled during DeSerializing the xml document, is it possible to "hook into" the serializer from the parameterless constructor or something like that to set the owner/parent Properties ?




Remove node from xml document

$
0
0

How can I remove Node 4 from the following document

<?xml version="1.0" encoding="utf-8"?><Node><Node1><Node2>test</Node2><Node3>test1</Node3></Node1><Node4>test2</Node4></Node>

get the value out of my XML

$
0
0

Hi all ,

I have a below XML structure, 


<Products>
        <Product>         
        <Item quality="good">GW001</Item>
                  <Item quality="bad">BW001</Item>
        <InStock>Yes</InStock>
          </Product>
         <Product>         
        <Item quality="good">GW002</Item>
                  <Item quality="bad">BW002</Item>
        <InStock>Yes</InStock>
          </Product>
        </Products>

and I have a below code to get the list of products out of the above xml 

   var products = xmlDocument.GetElementsByTagName("Product");
            foreach (XmlNode node in products)
            {

                  /////   

            }

and I wanted to populate my own list like below  ,  

myitems.Add(new ProductItem()  {good = "GW001",bad = "BW001",InStock ="Yes"});

myitems.Add(new ProductItem()  {good = "GW002",bad = "BW002",InStock ="Yes"});

could some one help me to get this ? 

thanks 

XmlSerializer constructors and pre-generated serializers

$
0
0
Hi,
 
I have a pre-generated serializer assembly loaded in the GAC.

When I have

XmlSerializer serializer = new XmlSerializer(typeof("myType"));
Then the pre-generated assembly is loaded and used.

However, if I have:
string namespace = myNameSpace;
XmlSerializer serializer = new XmlSerializer(typeof("myType"), namespace);


OR

XmlRootAttribute root = myXmlRoot;


XmlSerializer serializer = new XmlSerializer(typeof("myType"), root);

Then .net is generating temporary assemblies and not loading the one I have in the GAC.


Is there a way to use these overloaded XmlSerializer constructors and force .net to use the existing serializer assembly from the GAC?

Thanks!

Pre-built XmlSerializer with sgen

$
0
0
I have a class library that makes use of XmlSerializer.  I was getting an error in another assembly that uses this class library (see further information here).  So, I am trying to use sgen to create pre-built XmlSerializer.  Do I have to change anything in my class library (e.g., reference the pre-built class names instead of System.Xml.Serialization.XmlSerializer), or does the Framework take care of everything, assuming my pre-built serializers DLL is deployed and registered with my class library?

I found plenty of information on msdn about generating the pre-built assemblies, but I couldn't really find much information on what (if anything) needs to be done to use the pre-built assemblies.

Read xml tags containing search term.

$
0
0

I have xml file and I want to read it as following rule

  1. Check for a string in xml file.
  2. Read the nearest tag with name <queryItem>...............</queryItem> that encloses the stringn in point 1.
  3. Return the name value of name tag <name locale="en">**This Name**</name>within queryItem tag.
  4. Read the nearest tag with name <querySubject>...............</querySubject> that encloses the string in point 1. and return its name value as point 3.

I have already tried a lot by reading line(vbscript) Line = contents.readlineand getting queryItem and querySubject tags from line. But as the Line returned contains many other queryItems and querySubjects so My readline fails to get me to the exact tags containing string.

Any suggestion to implement this logic?

xsd.exe Bug (Constraints on Attribute Declaration Schema Components)

$
0
0

I'm trying to use xsd.exe to generate a schema for this class.

 

Code Snippet

publicclassTest

{

    [

XmlAttribute(AttributeName = "noNamespaceSchemaLocation", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]

    publicstring noNamespaceSchemaLocation;

}

 

When xsd.exe attempts to generate the schema, it fails.

 

Error: There was an error processing 'XmlTest.exe'.
   - Schema item 'attribute' named 'noNamespaceSchemaLocation' from namespace 'http://www.w3.org/2001/XMLSchema-instance'. The target namespace of an attribute declaration, whether local or global, must not match
http://www.w3.org/2001/XMLSchema-instance.
   - The target namespace of an attribute declaration, whether local or global, must not match
http://www.w3.org/2001/XMLSchema-instance.

 

I checked the specification (http://www.w3.org/TR/xmlschema-1/#coss-attribute) and noticed a slight difference--my emphasis in bold.

 

The {target namespace} of an attribute declaration, whether local or top-level, must not match http://www.w3.org/2001/XMLSchema-instance (unless it is one of the four built-in declarations given in the next section).

 

The noNamespaceSchemaLocation attribute is one of the declartions referenced in the "next section". Is this a bug in xsd.exe? Is there a fix available?

How to get all text in xml tag through regex using c#?

$
0
0

Hi,

Can you please help me?

Which Regex pattern is useful.

Description:

For example,this is xml tag

<title-group>
<title>abcdefghjtshdfg<email>EffectiveHealthCare@ahrq.hhs.gov</email>dfgdfgg</title>
</title-group>
</book-part-meta>
<body>
<p><bold>
<italic>Comparative Effectiveness Review</italic>
</bold></p>
<p><bold>Number 154</bold></p>
<p><bold>Prepared for:</bold></p>
<p>Agency for Healthcare Research and Quality</p>
<p>U.S. Department of Health and Human Services</p>
<p>540 Gaither Road</p>
<p>Rockville, MD 20850</p>
<p><ext-link xlink:href="www.ahrq.gov" ext-link-type="uri">www.ahrq.gov</ext-link></p>
<p><bold>Contract No. 290-2012-00009-I</bold></p>

In this example,

How to get highlighted text of tag though regex?

Thanks,

Rupali


XmlDocumento to string c#

$
0
0

Hi everyone, can help me, I have a xml document, y use the load function and I working whit it, and after i need the string of this XmlDocument, I use OuterXML function but in my string I obtain this:

"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"

but i need a string whit this:

<?xml version="1.0" encoding="UTF-8"?>

I hope any can halpme

P.D.

Sorry for by bad english :D

Working with XML

$
0
0

Hi, 

I'm trying to read in some XML from an online source but not having much luck.  What I don't know how to do is structure the .Element, I've tried different combinations using  "Report_Data" and "Report_Entry".  Report_Data encompases the entire XML object but is at the same level as "Report_Entry".  

Here is my code 

var url = "https://wd3-services1.junk.com/ccx/service/Generic_Data_Feed?Start_Date_from=2015-12-01-08:00&Start_Date_to=2016-01-01-08:00&format=simplexml";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Credentials = new NetworkCredential("username", "password");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream receiveStream = response.GetResponseStream();

XDocument doc = XDocument.Load(receiveStream);
XElement ge = doc
	.Element("Report_Data")
	.Element("Report_Entry");

reports.FirstName = ge.Element("firstName").Value;
reports.LastName = ge.Element("lastName").Value;


and here is the XML 

<wd:Report_Data xmlns:wd="urn:com.workday.report/HIG_Generic_Data_Feed"><wd:Report_Entry><wd:Employee_ID>00754</wd:Employee_ID><wd:Legal_Name_-_Title>Mr</wd:Legal_Name_-_Title><wd:Legal_Name>Fred Bloggs</wd:Legal_Name><wd:Preferred_Name_-_First_Name>Fred Bloggs</wd:Preferred_Name_-_First_Name><wd:firstName>Fred</wd:firstName><wd:lastName>Bloggs</wd:lastName><wd:Gender>Male</wd:Gender><wd:Job_Title>Teacher</wd:Job_Title><wd:Active_Status>0</wd:Active_Status><wd:Hire_Date>2012-06-25</wd:Hire_Date><wd:termination_date>2015-05-22</wd:termination_date><wd:continuous_service_date>2012-06-25</wd:continuous_service_date><wd:All_Managers_in_Management_Chain>Grande Fromage</wd:All_Managers_in_Management_Chain><wd:Worker_s_Manager><wd:Legal_Name>Blandine Arzur-Kean</wd:Legal_Name><wd:Manager_Supervisory_Org>DUAL Risk & Compliance (Stuart Priestley-Smith)</wd:Manager_Supervisory_Org><wd:Manager_Organisation_ID>SUP5.33</wd:Manager_Organisation_ID><wd:Company>Hyperion Insurance Group Limited</wd:Company></wd:Worker_s_Manager><wd:Superior_Org_ID>SUP5.33</wd:Superior_Org_ID></wd:Supervisory_Organization_-_Superior></wd:Report_Entry>

Any ideas? 

Thanks 



Viewing all 935 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>