473,748 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding <?mso-application ...> programmaticall y

Hi,

If I have an XmlDocument DOM how do I insert
<?mso-application progid="ProgId. Here"?> programmaticall y?
--
Victor Hadianto
http://www.synop.com/Products/SauceReader/

Nov 12 '05 #1
4 5988
"Victor Hadianto" <sy***@nospam.n ospam> wrote in message news:06******** *************** ***********@mic rosoft.com...
If I have an XmlDocument DOM how do I insert
<?mso-application progid="ProgId. Here"?> programmaticall y?


Given an already positioned XmlNode, you can call the XmlDocument's
CreateProcessin gInstruction( ) and use InsertBefore( ), InsertAfter( )
or AppendChild( ) to place the P.I. in relation to the XmlNode. e.g.,

string progId = "ProgId.Her e";

xmlDoc.InsertBe fore(
xmlDoc.CreatePr ocessingInstruc tion(
"mso-application",
string.Format( "progid=\"{0}\" ", progId)
),
xmlNodeToInsert Before
);

The first 'token' after the <? is called the target of the P.I. and is the first
argument to CreateProcessin gInstruction( ), any remaining text after the
target up until the ?> is the second argument. The second argument may
contain multiple 'pseudo-attributes'.
Derek Harmon
Nov 12 '05 #2
> Given an already positioned XmlNode, you can call the XmlDocument's
CreateProcessin gInstruction( ) and use InsertBefore( ), InsertAfter( )
or AppendChild( ) to place the P.I. in relation to the XmlNode. e.g.,

string progId = "ProgId.Her e";

xmlDoc.InsertBe fore(
xmlDoc.CreatePr ocessingInstruc tion(
"mso-application",
string.Format( "progid=\"{0}\" ", progId)
),
xmlNodeToInsert Before
);

The first 'token' after the <? is called the target of the P.I. and is the first
argument to CreateProcessin gInstruction( ), any remaining text after the
target up until the ?> is the second argument. The second argument may
contain multiple 'pseudo-attributes'.


Thanks,

Is there a way (without using Regex) to find out if I already have the <?mso
....?> on the document?

---
Victor Hadianto
Nov 12 '05 #3
Victor Hadianto wrote:
Is there a way (without using Regex) to find out if I already have the <?mso
...?> on the document?


XmlNode pi =
xmlDoc.SelectSi ngleNode("/processing-instruction('ms o-application')") ;
if (pi != null)

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #4
"Victor Hadianto" <sy***@nospam.n ospam> wrote in message news:29******** *************** ***********@mic rosoft.com...
Is there a way (without using Regex) to find out if I already have the <?mso
...?> on the document?


There are at least three ways to find out if there's a processing instruction
in an XmlDocument that is (or starts with) "mso".

1. The method Oleg already posted is to use the XPath function,
processing-instruction( ). I'll add that if you want to find all PIs
starting with "mso", you'd use the following XPath expression,

//processing-instruction()[starts-with(local-name(),'mso')]

because the local-name() of a PI in XPath corresponds to the
PI's target.

2. Enumerate the DOM nodes of the document and when you
find a node with a NodeType of XmlNodeType.Pro cessingInstruct ion
then you can examine it's LocalName and Value properties to get it's
target and pseudo-attributes, respectively.

- - - PiDomSearch.cs (excerpt)
// . . .
public void Descend( XmlNode node)
{
if ( null != node )
{
if ( XmlNodeType.Pro cessingInstruct ion == node.NodeType )
{
if ( node.LocalName. StartsWith( "mso"))
{
// ... do something here ...
}
}
this.Descend( node.FirstChild );
this.Descend( node.NextSiblin g);
}
return;
}
// . . .
this.Descend( xmlDoc.Document Element);
// . . .
- - -
3. The prior techniques may be appealing if you're already traversing
the DOM node tree of an XmlDocument, but if you want the information
a priori then I think the best method is to use a specialized XmlReader
when loading the XmlDocument that would be responsible for detecting
the presence of these processing instructions,

- - - PiReaderSearch. cs (excerpt)
using System;
using System.Collecti ons;
using System.IO;
using System.Xml;
// . . .

/// <summary>
/// <b>XmlTextReade r</b> subclass that detects the presence of processing-instructions
/// as it reads an incoming <b>TextReader </b> whose targets start with a given text string.
/// </summary>
public class ProcInstXmlText Reader : XmlTextReader
{
private string piTarget;
private ArrayList matches;
private bool listening;

public ProcInstXmlText Reader( TextReader reader, string piTarget) : base( reader)
{
this.piTarget = piTarget;
this.matches = new ArrayList( );
}

public int MatchCount
{
get
{
return matches.Count;
}
}

public override XmlNodeType NodeType
{
get
{
this.intercepti ng = ( XmlNodeType.Pro cessingInstruct ion == base.NodeType );
return base.NodeType;
}
}

public override string Name
{
get
{
string tgt = base.Name;
if ( this.intercepti ng )
{
if ( tgt.StartsWith( this.piTarget))
{
this.matches.Ad d( tgt);
this.intercepti ng = false;
}
}
return tgt;
}
}
}
// . . .

ProcInstXmlText Reader pixtr = new ProcInstTextRea der(
new StreamReader( "filename.xml") , "mso"
);
xmlDoc.Load( pixtr);
if ( pixtr.MatchesCo unt > 0 )
{
// Process xmlDoc knowing that mso* PIs are present.
}
else
{
// Process xmlDoc knowing that it contains no mso* PIs.
}

// . . .
- - -

These examples presume you're looking for processing instructions that
start with the leading characters, "mso" (working with Microsoft Office
XML), but they're also easily adapted to testing for equality to "mso" if
you're looking for only one specific processing instruction target.
Derek Harmon
Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
5173
by: haoren | last post by:
Can anybody help me with this problem: How can I echo a string that contain <? and <?php? For example, $str="test <? and <?php echo"; echo $str;
4
9647
by: matatu | last post by:
Hi to all, I have a xml file, a substring like: &lt;a href=&quot;#&quot;&gt;text&lt;/a&gt; which after an xslt trasform is rendered as (using xsl:output method html): &lt;a href="#"&gt;text&lt;/a&gt;
4
62111
by: higabe | last post by:
Three questions 1) I have a string function that works perfectly but according to W3C.org web site is syntactically flawed because it contains the characters </ in sequence. So how am I supposed to write this function? String.replace(/</g,'&lt;');
5
3543
by: tobbe | last post by:
Hi Im trying to load a XmlDataDocument with the following xml: <ROOT> <NAME> &LT; &AMP; &GT; " '</NAME> </ROOT> And i know I have a entity problem here, but i cant find any solution for it. The problem is that i recive this from external source and cant
10
42967
by: Jon Noring | last post by:
Out of curiosity, may a CDATA section appear within an attribute value with datatype CDATA? And if so, how about other attribute value datatypes which accept the XML markup characters? To me, the XML specification seems a little ambiguous on this, so I defer to the XML authorities. Refer to sections 2.4 and 2.7 (it all hinges on if CDATA attribute values are part of markup or not.) Thanks.
4
1918
by: Armel Asselin | last post by:
Hello, I've been using XML for a while in a rather 'free' manner (i.e. as long as IE accept it it's OK), I read recently (again) the Xml standard 1.0 (3rd edition) and found this sentence: Well-formedness constraint: No < in Attribute Values The replacement text of any entity referred to directly or indirectly in an attribute value MUST NOT contain a <.
0
260
by: ChrisMiddle10 | last post by:
Sorry to bother everyone with this question, but the answer to this the question is difficult to search for. I want to add javascript to an HtmlInputButton control attribute. A portion of the javascript goes something like this: if( x < y && x != y ) { // do something }
3
4018
by: webmasterATflymagnetic.com | last post by:
Folks, I'm struggling to put the question together, but I have this problem. I have written an HTML form that I can use for data entry. This uses PHP to write a SQL UPDATE command that gets written to my MySQL database. I can later view this data back in the form. One thing I've noticed happening is if I enter code such as &lt; it gets rewritten as < (ie the less-than sign). Now I don't want this to happen, but something somewhere is...
1
1717
by: desomnambulist | last post by:
I've got the following query that just won't seem to save properly in Access 2000: SELECT InvoicingLine.ILType, InvoicingLine.ILDate, InvoicingLine.ILInvoicedQty, InvoicingLine.ILSellingPrice, InvoicingLine.ILTotalAmount, InvoicingLine.ILUnique, InvoicingLine.ILProductKey, InvoicingLine.ILCustomerSupplierNumber FROM InvoicingLine INNER JOIN ( SELECT Product.PrDescription1, Product.PrNumber, Product.RecordPos FROM Product WHERE...
2
1931
by: premprakashbhati | last post by:
happy new year all of u... sir, iam using dataservice function of type int named getunbookedslots(DateTime dt) and the same is used for adding the returned datetime value to RadioButtonList of other .aspx page dynamically... here is the Code in Page_Load() of page aspx.cs.... DataService myservices = new DataService(); protected void Page_Load(object sender, EventArgs e) { string s = ""; DateTime dt = ...
0
8996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9386
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8255
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.