question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Index position of nodes

See original GitHub issue

Hi guys, I was using this great library, but I found something to add to it which is the index of every childNode (and childCount in parent).

I have this particular American football XML (part of it):

<qtr number="1" text="1st">
   <play hasball="COR" down="1" togo="10" spot="COR40" context="V,1,10,V40" playid="0,1,0" tokens="CMT:Cornell wins the toss and defers"
      text="Cornell wins the toss and defers" newcontext="V,1,10,V40">
   </play>
   <play hasball="COR" down="1" togo="10" spot="COR40" context="V,1,10,V40" playid="0,2,1" tokens="SPOT:V,V40,N"
      text="COR ball on COR40." newcontext="V,1,10,V40">
   </play>
   <play hasball="COR" down="1" togo="10" spot="COR40" context="V,1,10,V40" playid="0,3,2" type="K" tokens="KO:9A,H00 TB:"
      text="Null, Nickolas kickoff 60 yards to the PENN0, touchback." newcontext="H,1,10,H20">
    <p_ko vh="V" name="Blabla" gain="60" result="T"></p_ko>
   </play>
   <drivestart poss="H,H20,15:00" vh="H" spot="H20" clock="15:00" driveindex="1,2"></drivestart>
   <play hasball="PENN" down="1" togo="10" spot="PENN20" context="H,1,10,H20" playid="1,1,3" tokens="SPOT:H,H20,Y"
      text="PENN ball on PENN20." newcontext="H,1,10,H20">
   </play>
</qtr>

So, for this sport the actual order of plays and drivestart nodes is key. While I am parsing this XML and converting into a JSON, I loose the order, so that’s why I added 2 options appendIndexInNodes (boolean, false by default) and indexInNodesName (string, ‘#index’ by default) to set up this feature.

The result appending index in every node will be:

{
    "childCount": 1,
    "qtr": {
        "@_number": "1",
        "@_text": "1st",
        "#index": 0,
        "childCount": 5,
        "play": [
            {
                "@_hasball": "COR",
                "@_down": "1",
                "@_togo": "10",
                "@_spot": "COR40",
                "@_context": "V,1,10,V40",
                "@_playid": "0,1,0",
                "@_tokens": "CMT:Cornell wins the toss and defers",
                "@_text": "Cornell wins the toss and defers",
                "@_newcontext": "V,1,10,V40",
                "#index": 0
            },
            {
                "@_hasball": "COR",
                "@_down": "1",
                "@_togo": "10",
                "@_spot": "COR40",
                "@_context": "V,1,10,V40",
                "@_playid": "0,2,1",
                "@_tokens": "SPOT:V,V40,N",
                "@_text": "COR ball on COR40.",
                "@_newcontext": "V,1,10,V40",
                "#index": 1
            },
            {
                "@_hasball": "COR",
                "@_down": "1",
                "@_togo": "10",
                "@_spot": "COR40",
                "@_context": "V,1,10,V40",
                "@_playid": "0,3,2",
                "@_type": "K",
                "@_tokens": "KO:9A,H00 TB:",
                "@_text": "Null, Nickolas kickoff 60 yards to the PENN0, touchback.",
                "@_newcontext": "H,1,10,H20",
                "#index": 2,
                "childCount": 1,
                "p_ko": {
                    "@_vh": "V",
                    "@_name": "Blabla",
                    "@_gain": "60",
                    "@_result": "T",
                    "#index": 0
                }
            },
            {
                "@_hasball": "PENN",
                "@_down": "1",
                "@_togo": "10",
                "@_spot": "PENN20",
                "@_context": "H,1,10,H20",
                "@_playid": "1,1,3",
                "@_tokens": "SPOT:H,H20,Y",
                "@_text": "PENN ball on PENN20.",
                "@_newcontext": "H,1,10,H20",
                "#index": 4
            }
        ],
        "drivestart": {
            "@_poss": "H,H20,15:00",
            "@_vh": "H",
            "@_spot": "H20",
            "@_clock": "15:00",
            "@_driveindex": "1,2",
            "#index": 3
        }
    }
}

I made all code changes and tests under PR #172, I will wait for your comments!

Feel free to ask me anything. Thanks!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
domboryscommented, Jul 31, 2019

Hi, I have encountered the same issue while parsing some GML files. This is the problematic part:

<gml:Curve>
	<gml:segments>
		<gml:LineStringSegment>
			<gml:pos>8.72475070598000E+0005 2.27947125583450E+0005</gml:pos>
			<gml:pos>8.72474827387390E+0005 2.27920615627330E+0005</gml:pos>
		</gml:LineStringSegment>
		<gml:ArcString>
			<gml:pos>8.72474827387390E+0005 2.27920615627330E+0005</gml:pos>
			<gml:pos>8.72468488023918E+0005 2.27916040807065E+0005</gml:pos>
			<gml:pos>8.72462626321960E+0005 2.27921213520070E+0005</gml:pos>
		</gml:ArcString>
		<gml:LineStringSegment>
			<gml:pos>8.72462626321960E+0005 2.27921213520070E+0005</gml:pos>
			<gml:pos>8.72463133010730E+0005 2.27946547958260E+0005</gml:pos>
		</gml:LineStringSegment>
		<gml:ArcString>
			<gml:pos>8.72463133010730E+0005 2.27946547958260E+0005</gml:pos>
			<gml:pos>8.72468883023631E+0005 2.27951358239362E+0005</gml:pos>
			<gml:pos>8.72475070598000E+0005 2.27947125583450E+0005</gml:pos>
		</gml:ArcString>
	</gml:segments>
</gml:Curve>

This code represents a curve in a shape of a running track. The gml:LineStringSegment elements represent parts of the curve which are line segments. The gml:ArcString elements represent parts which are arcs. The coordinates of the endpoints are inside the gml:pos elements.

The order of the gml:LineStringSegment and gml:ArcString elements is meaningful - first there is a straight line, followed by an arc, followed by another straight line, followed by another arc.

I want to draw this shape, so I need to know the order of these elements as they appear in the XML document. However, when I use Fast XML Parser this information is lost:

{
    "gml:Curve": {
        "gml:segments": {
            "gml:LineStringSegment": [
                {
                    "gml:pos": [
                        "8.72475070598000E+0005 2.27947125583450E+0005",
                        "8.72474827387390E+0005 2.27920615627330E+0005"
                    ]
                },
                {
                    "gml:pos": [
                        "8.72462626321960E+0005 2.27921213520070E+0005",
                        "8.72463133010730E+0005 2.27946547958260E+0005"
                    ]
                }
            ],
            "gml:ArcString": [
                {
                    "gml:pos": [
                        "8.72474827387390E+0005 2.27920615627330E+0005",
                        "8.72468488023918E+0005 2.27916040807065E+0005",
                        "8.72462626321960E+0005 2.27921213520070E+0005"
                    ]
                },
                {
                    "gml:pos": [
                        "8.72463133010730E+0005 2.27946547958260E+0005",
                        "8.72468883023631E+0005 2.27951358239362E+0005",
                        "8.72475070598000E+0005 2.27947125583450E+0005"
                    ]
                }
            ]
        }
    }
}

In this JSON all the LineStringSegments end up in one array and the ArcStrings in another one.

It would be wonderful if a feature such as proposed by gvillo was added.

0reactions
amitguptagwlcommented, Nov 17, 2021

check v4 with preserveOrder option. Please create a new issue if that doesn’t fulfill the purpose,

Read more comments on GitHub >

github_iconTop Results From Across the Web

Index Node — Blender Manual
The Index node gives an integer value indicating the position of each element in the list, starting at zero. This depends on the...
Read more >
Node index to node depth-position - MATLAB ind2depo
Node index to node depth-position ... computes the depths D and the positions P (at these depths D ) for the nodes with...
Read more >
Write a function to get Nth node in a Linked List - GeeksforGeeks
Write a GetNth() function that takes a linked list and an integer index and returns the data value stored in the node at...
Read more >
Positioning Tree Nodes - L3HarrisGeospatial.com
The position of tree widget nodes within a tree can be controlled in several ways. When a tree node is created without the...
Read more >
How to Get a Position from an Index - Discuss - ProseMirror
I don't think you can. You will need a ResolvedPos which you can not get from an index. Nodes don't have a positions....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found