Implement find element by XML schema feature
This commit is contained in:
parent
87835df396
commit
cccf7a3ec6
@ -7,16 +7,11 @@ namespace UniversalEditor.ObjectModels.Markup
|
||||
public abstract class MarkupContainerElement : MarkupElement
|
||||
{
|
||||
private MarkupElement.MarkupElementCollection mvarElements = null;
|
||||
public MarkupElement.MarkupElementCollection Elements
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.mvarElements;
|
||||
}
|
||||
}
|
||||
public MarkupElement.MarkupElementCollection Elements { get { return mvarElements; } }
|
||||
|
||||
public MarkupContainerElement()
|
||||
{
|
||||
this.mvarElements = new MarkupElement.MarkupElementCollection(this);
|
||||
this.mvarElements = new MarkupElement.MarkupElementCollection(this, this.ParentObjectModel);
|
||||
}
|
||||
public MarkupElement FindElement(params string[] fullNames)
|
||||
{
|
||||
@ -48,14 +43,14 @@ namespace UniversalEditor.ObjectModels.Markup
|
||||
if (tag == null)
|
||||
{
|
||||
tag = new MarkupTagElement();
|
||||
tag.Name = elementNames[i];
|
||||
tag.FullName = elementNames[i];
|
||||
basetag = tag;
|
||||
this.Elements.Add(tag);
|
||||
}
|
||||
else
|
||||
{
|
||||
MarkupTagElement newtag = new MarkupTagElement();
|
||||
newtag.Name = elementNames[i];
|
||||
newtag.FullName = elementNames[i];
|
||||
tag.Elements.Add(newtag);
|
||||
tag = newtag;
|
||||
}
|
||||
@ -63,6 +58,65 @@ namespace UniversalEditor.ObjectModels.Markup
|
||||
return basetag;
|
||||
}
|
||||
|
||||
public string XMLSchema
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.Namespace == null)
|
||||
return null;
|
||||
|
||||
for (int i = 0; i < this.ParentObjectModel.Elements.Count; i++) {
|
||||
MarkupTagElement tagTopLevel = (this.ParentObjectModel.Elements [i] as MarkupTagElement);
|
||||
if (tagTopLevel == null)
|
||||
continue;
|
||||
|
||||
MarkupAttribute att = tagTopLevel.Attributes ["xmlns:" + this.Namespace];
|
||||
if (att != null)
|
||||
return att.Value;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void UpdateParentObjectModel ()
|
||||
{
|
||||
base.UpdateParentObjectModel ();
|
||||
this.Elements.ParentObjectModel = this.ParentObjectModel;
|
||||
for (int i = 0; i < this.Elements.Count; i++) {
|
||||
this.Elements [i].ParentObjectModel = this.ParentObjectModel;
|
||||
}
|
||||
}
|
||||
|
||||
public MarkupElement FindElementUsingSchema(string schema, string name)
|
||||
{
|
||||
string tagPrefix = null;
|
||||
for (int i = 0; i < this.ParentObjectModel.Elements.Count; i++)
|
||||
{
|
||||
MarkupTagElement tagTopLevel = (this.ParentObjectModel.Elements [i] as MarkupTagElement);
|
||||
if (tagTopLevel != null) {
|
||||
for (int j = 0; j < tagTopLevel.Attributes.Count; j++) {
|
||||
if (tagTopLevel.Attributes [j].Namespace.Equals ("xmlns")) {
|
||||
|
||||
if (tagTopLevel.Attributes [j].Value.Equals (schema)) {
|
||||
tagPrefix = tagTopLevel.Attributes [j].Name;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tagPrefix == null) {
|
||||
Console.WriteLine ("ue: MarkupObjectModel: tag prefix for schema '" + schema + "' not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
string fullName = tagPrefix + ":" + name;
|
||||
return FindElement (fullName);
|
||||
}
|
||||
|
||||
public override void Combine(MarkupElement el)
|
||||
{
|
||||
MarkupTagElement tag = (el as MarkupTagElement);
|
||||
|
||||
@ -9,6 +9,9 @@ namespace UniversalEditor.ObjectModels.Markup
|
||||
public class MarkupElementCollection
|
||||
: System.Collections.ObjectModel.Collection<MarkupElement>
|
||||
{
|
||||
private MarkupObjectModel _parentObjectModel = null;
|
||||
public MarkupObjectModel ParentObjectModel { get { return _parentObjectModel; } internal set { _parentObjectModel = value; } }
|
||||
|
||||
private MarkupContainerElement _parent = null;
|
||||
public MarkupElement this[string nameSpace, string name]
|
||||
{
|
||||
@ -57,16 +60,26 @@ namespace UniversalEditor.ObjectModels.Markup
|
||||
}
|
||||
}
|
||||
public MarkupElementCollection()
|
||||
: this(null)
|
||||
: this(null, null)
|
||||
{
|
||||
}
|
||||
public MarkupElementCollection(MarkupObjectModel parentObjectModel)
|
||||
: this(null, parentObjectModel)
|
||||
{
|
||||
}
|
||||
public MarkupElementCollection(MarkupContainerElement parent)
|
||||
: this(parent, null)
|
||||
{
|
||||
}
|
||||
public MarkupElementCollection(MarkupContainerElement parent, MarkupObjectModel parentObjectModel)
|
||||
{
|
||||
this._parent = parent;
|
||||
this._parentObjectModel = parentObjectModel;
|
||||
}
|
||||
public new void Add(MarkupElement item)
|
||||
{
|
||||
item.mvarParent = this._parent;
|
||||
item.ParentObjectModel = this._parentObjectModel;
|
||||
base.Add(item);
|
||||
}
|
||||
public bool Contains(string fullName, string id = null)
|
||||
@ -90,6 +103,14 @@ namespace UniversalEditor.ObjectModels.Markup
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private MarkupObjectModel mvarParentObjectModel = null;
|
||||
public MarkupObjectModel ParentObjectModel { get { return mvarParentObjectModel; } internal set { mvarParentObjectModel = value; UpdateParentObjectModel (); } }
|
||||
|
||||
protected virtual void UpdateParentObjectModel()
|
||||
{
|
||||
}
|
||||
|
||||
private string mvarName = string.Empty;
|
||||
private string mvarValue = string.Empty;
|
||||
private string mvarNamespace = string.Empty;
|
||||
|
||||
@ -18,14 +18,14 @@ namespace UniversalEditor.ObjectModels.Markup
|
||||
this.mvarElements.Clear();
|
||||
}
|
||||
|
||||
private MarkupElement.MarkupElementCollection mvarElements = new MarkupElement.MarkupElementCollection();
|
||||
public MarkupElement.MarkupElementCollection Elements
|
||||
public MarkupObjectModel()
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.mvarElements;
|
||||
}
|
||||
mvarElements = new MarkupElement.MarkupElementCollection (null, this);
|
||||
}
|
||||
|
||||
private MarkupElement.MarkupElementCollection mvarElements = null;
|
||||
public MarkupElement.MarkupElementCollection Elements { get { return this.mvarElements; } }
|
||||
|
||||
public override void CopyTo(ObjectModel destination)
|
||||
{
|
||||
MarkupObjectModel dest = destination as MarkupObjectModel;
|
||||
@ -140,5 +140,35 @@ namespace UniversalEditor.ObjectModels.Markup
|
||||
if (tag == null) return defaultValue;
|
||||
return tag.Value;
|
||||
}
|
||||
|
||||
public MarkupElement FindElementUsingSchema(string schema, string name)
|
||||
{
|
||||
string tagPrefix = null;
|
||||
|
||||
for (int i = 0; i < this.Elements.Count; i++) {
|
||||
MarkupTagElement tagTopLevel = (this.Elements [i] as MarkupTagElement);
|
||||
if (tagTopLevel != null) {
|
||||
for (int j = 0; j < tagTopLevel.Attributes.Count; j++) {
|
||||
if (tagTopLevel.Attributes [j].Namespace.Equals ("xmlns")) {
|
||||
|
||||
if (tagTopLevel.Attributes [j].Value.Equals (schema)) {
|
||||
tagPrefix = tagTopLevel.Attributes [j].Name;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tagPrefix == null) {
|
||||
Console.WriteLine ("ue: MarkupObjectModel: tag prefix for schema '" + schema + "' not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
string fullName = tagPrefix + ":" + name;
|
||||
return FindElement (fullName);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user